ghayne wrote: ↑
Fri Aug 23, 2019 8:24 am
...I cannot afford to miss any pulses (or over count) because they are being used to calculate the cost (4000 pulses kWh)...
Easily achieved. The interrupt handler updates a global. Before you clear down the global, disable interrupts. Read the global, clear it down, and re-enable interrupts. Ensure that the period for which interrupts are disabled is shorter than the shortest interval between pulses:
Code: Select all
state = machine.disable_irq()
running_total += gpulse_count
gpulse_count = 0
The reason for clearing down the global is to avoid it exceeding 30 bits in size, which would lead to it becoming a long integer which cannot be handled in an ISR. If your consumption won't exceed 268MWH between reboots you could just let the ISR update the running total and skip this bit of code.