Pulse counters (revision 3.05) – Maxim Integrated 71M6513H Power Meter IC Family Software User Manual
Page 64

71M651x Software User’s Guide
Pulse Counters (Revision 3.05)
For the Demo Code Revision 3.05 only, a versatile pulse counter utility is available that is based on the interrupts ge-
nerated by a high-to-low transition of the W and/or R pulse output pins (DIO pins DIO6 and DIO7).
The CLI command CPD defines a time interval (window) during which pulses are counted that are then displayed with
the M14.2, M15.2 or M13.2 commands. We call these pulse counters “accumulated”.
The CLI commands M14.1, M15.1, and M13.1 display the “absolute” pulse counts, i.e. the number of pulses detected
regardless of the time window. These absolute pulse counts can be reset using the CLI command CPC.
Because pulses can appear at fairly high frequencies, the pulse counter routines had to be designed to be fast and
efficient. At the core of the pulse counting mechanism are the two incremental pulse counters iPulseW_Cnt and
iPulseR_Cnt, located in internal (indirect access) RAM for fastest access. As shown in the code sample below
(taken from misc.c), these counters are incremented with in the interrupt service routines with each occurrence of the
associated pulse.
void io_high_priority_isr (void) small reentrant
{
iPulseW_Cnt++;
}
void io_low_priority_isr (void) small reentrant
{
iPulseR_Cnt++;
}
iPulseW_Cnt and iPulseR_Cnt hold the pulse counts encountered in one second intervals only, and then are
copied to XRAM-based counters.
Each second, when the RTC_ACTION macro is called in events.c, the incremental pulse counters iPulseW_Cnt and
iPulseR_Cnt are copied to the XRAM-based pulse counters xPulseW_Cnt and xPulseR_Cnt. As shown below,
the RTC_ACTION macro resets the incremental pulse counters to zero, in order to initialize them for the next one-
second interval. The RTC interrupt is used to synchronize this 1-second event, since it is more accurate than the
accumulation interval of the CE.
#define RTC_ACTION()
IRQ_DISABLE();
xPulseW_Cnt = iPulseW_Cnt;
xPulseR_Cnt = iPulseR_Cnt;
iPulseW_Cnt = iPulseR_Cnt = 0;
pulse_count_available = 1;
IRQ_ENABLE();
Again, each second, as controlled by the variable pulse_count_available (handled by the RTC interrupt in
events.c), the routine ce_update() calls count_pulses(), where the XRAM-based pulse counters
xPulseW_Cnt and xPulseR_Cnt are added to the final pulse counters
PulseW_Cnt
and
PulseR_Cnt.
The count_pulses() routine is shown below.
The absolute pulse counters are updated unconditionally, while the accumulated pulse counters are only updated
when the time window, as defined by the CPD command, is still open. This is reflected in the value of the variable
pulse_tmr
. The variable
capture_pulse_cnts
signals the start of pulse counting, i.e. it is only true
immediately after the CPA command is issued via the CLI.
The accumulated pulse counters are determined by subtracting the start count from the final count:
sub8_8 (pulseW_cnt1.a, pulseW_cnt0.a);
The pulse counts to be displayed are stored in the variables dPulseW_Cnt and
dPulseR_Cnt
.
Revision 2.4
TERIDIAN Proprietary
64 of 137
© Copyright 2005-2006 TERIDIAN Semiconductor Corporation