July
1998, Issue 96
A
PIC-Based AC Power Meter
SOFTWARE
DESIGN
The PICs
internal timer generates a 10-ms timer interrupt for
periodic software functions. This works well since I
need to service the LCD backplane in the 10100-Hz
range, and it also lets me sample power at a 100-Hz
rate.
Figure
4 shows a flowchart of the 10-ms timer ISR. Every
10 ms, the LCD backplane and arrow segment must be toggled,
the tic (0.01 s) counter incremented, and power value
accumulated into S.
Every 250
ms, the fast flash of the arrow segment is done if needed.
Every 500 ms, the slow flash of the arrow segment is
done if necessary, and the power value computed for
display.
Figure
5 illustrates the main-loop processing. Both switches
are scanned every time through the main loop, debounced
through a 50-ms delay.
Every second,
the larger 24-bit energy accumulator, E, is updated
from the local 16-bit accumulator, S. The mode
state variable directs execution to the appropriate
processing for the four operational modes.