TIDUF72 August 2024
per_sample_dsp()Figure 3-6 shows the
flowchart for the per_sample_dsp() function. The
per_sample_dsp() function is used to calculate intermediate dot
product results that are fed into the foreground process for the calculation of
metrology readings. Both voltage and current samples are processed and accumulated
in dedicated 64-bit registers. Per-phase active power and reactive power are also
accumulated in 64-bit registers.
per_sample_dsp
() FunctionAfter CYCLES_PER_COMPUTATION number of cycles (10 cycles if FNOM = 50Hz and 12 cycles if FNOM = 60Hz) have been accumulated, the background process triggers the foreground function to calculate the final values of RMS voltage and current; active, reactive, and apparent powers; active, reactive, and apparent energy; frequency; power factor; fundamental voltage, fundamental current, fundamental active power, fundamental reactive power, and fundamental apparent power; voltage underdeviation and voltage overdeviation; and voltage THD and current THD. In the software, there are two sets of dot products: at any given time, one is used by the foreground for calculation and the other used as the working set by the background. After the background process has sufficient samples, the process swaps the two dot products so that the foreground uses the newly acquired dot products that the background process just calculated and the background process uses a new empty set to calculate the next set of dot products.
Whenever there is a leading-edge zero-crossing (−
to + voltage transition) on a voltage channel, the per_sample_dsp()
function is also responsible for updating the frequency (in samples per cycle) of
the corresponding phase and triggering the calculation of the foreground of the
1-cycle VRMS reading. This 1-cycle VRMS reading is a different
calculation than the VRMS reading that is updated every
CYCLES_PER_COMPUTATION number of cycles. The 1-cycle VRMS
reading is specifically used for updating the sag, swell, and interruption state
variables. The 1-cycle VRMS calculation uses the same dot-product
swapping scheme as the scheme used for the CYCLES_PER_COMPUTATION dot
products.
The per_sample_dsp() function is
also responsible for outputting a voltage zero crossing pin (optional). Whenever
there is a negative to positive zero crossing on a voltage channel and the
corresponding 1-cycle VRMS reading of the voltage channel is greater than
the interruption threshold, a falling edge is asserted on this pin. If there is a
positive to negative zero crossing on a voltage channel and the 1-cycle
VRMS reading of the voltage channel is greater than the interruption
threshold, a rising edge is asserted on this pin. To reduce the impact of outputting
the zero crossing pin on the accuracy of the design, the zero crossing output needs
to not be selected to be on a GPIO pin connected to a LED.
The following sections describe the various
elements of electricity measurement in the per_sample_dsp()
function.