Does anyone have code for a CR1000 that will log both instaneous power and accumulated energy using the pulse outputs from a W-hr meter? I can count pulses to record W-hr with no problem, but for instaneous power I need to measure very long periods, with a wide range of periods between say 30 seconds and .25 seconds. Ideally the power would update with each full pulse cycle from the W-hr meter.
The easiest way is to have both an accumulator variable to track power usage and an instantaneous variable that updates every scan based on the number of pulses. The issue is what to do with the instantaneous variable when there are no pulses. In the program below, it is just left at the last value, but the user may want to put in logic to either reduce this over time (if more time has passed without a pulse than what the current instantaneous variable value would have resulted in, program could reduce the instantaneous variable each subsequent scan until another pulse), or simply set it to 0. This is the problem with a Watt-hour meter: you cannot know exactly what is going on between pulses. A watt-meter that outputs a proportional voltage based on current power usage eliminates this issue.
Public W_Hr_Accum, W_Hr_pulse,Watt_Instant
Const WattMult = 1
Const ScanInterval = 1
Public Counter
'Define Data Tables
DataTable (Instant,1,10000)
DataInterval (0,0,0,10)
Sample (1,W_Hr_pulse,FP2)
Sample (1,Watt_Instant,FP2)
Sample (1,W_Hr_Accum,IEEE4)
EndTable
DataTable (History,1,10000)
DataInterval (0,1,Hr,10)
Sample (1,W_Hr_Accum,IEEE4)
Maximum (1,Watt_Instant,FP2,False,False)
EndTable
'Main Program
BeginProg
Counter = 0
Scan (ScanInterval,Sec,0,0)
PulseCount (W_Hr_pulse,1,1 ,0,0,WattMult,0)
If W_Hr_Pulse > 0 Then
Watt_Instant = (W_Hr_Pulse/Counter) * 3600/ScanInterval
W_Hr_Accum = W_Hr_Accum + W_Hr_Pulse
EndIf
CallTable Instant
CallTable History
Counter = Counter + 1
NextScan
EndProg