4.3.4 LED Pulse Generation
In electricity meters, the energy consumed is normally measured in fraction of kilowatt-hour (kWh) pulses. This information can be used to accurately calibrate any meter or to report measurement during normal operation. To serve both of these tasks efficiently, the microcontroller must accurately generate and record the number of these pulses. It is a general requirement to generate these pulses with relatively little jitter. Although time jitters are not an indication of bad accuracy, as long as the jitter is averaged out, it can give a negative impression of the overall accuracy of the meter.
The sample code uses the average power to generate the energy pulses. The average power (calculated by the foreground process) is accumulated every SD24 interrupt. This is equivalent to converting it to energy. After the accumulated energy crosses a threshold, a pulse is generated. The amount of energy above this threshold is stored, and new energy amount is added to it in the next interrupt cycle. Because the average power tends to be a stable value, this way of generating energy pulses are very steady and free of jitter.
The threshold determines the energy tick specified by the power company and is a constant, for example, it can be in kWh. In most meters, the pulses per kWh decide this energy tick. For example, in this application, the number of pulses generated per kWh is set to 1600 for active and reactive energies. The energy tick in this case is 1 kWh/1600. Energy pulses are generated and also indicated via LEDs on the board. Port pins are toggled for the pulses with control over the pulse width for each pulse.