LMA
Lightweight Metrology for AC
Loading...
Searching...
No Matches
LMA_Types.h
Go to the documentation of this file.
1
12
13#ifndef _LMA_TYPES_H
14#define _LMA_TYPES_H
15
16#include <stdbool.h>
17#include <stddef.h>
18#include <stdint.h>
19
23
27typedef int32_t spl_t;
28
33typedef int64_t acc_t;
34
36
40
48
62
67typedef struct LMA_PhaseInputs_str
68{
73
78typedef struct LMA_NeutralInputs_str
79{
82
87typedef struct LMA_Accs_str
88{
93 uint32_t sample_count;
94} LMA_Accs;
95
100typedef struct LMA_PhaseAccs_str
101{
105
110typedef struct LMA_NeutralAccs_str
111{
115
120typedef struct LMA_ZeroCross_str
121{
122 uint32_t count;
124 bool debounce;
128
133typedef struct LMA_Measurements_str
134{
135 float vrms;
136 float irms;
138 float fline;
139 float p;
140 float q;
141 float s;
143
159
164typedef struct LMA_EnergyUnit_str
165{
166 float act;
167 float app;
168 float react;
170
177
184
189typedef struct LMA_GlobalCalibration_str
190{
191 float fs;
194
199typedef struct LMA_PhaseCalibration_str
200{
204 float p_coeff;
206
211typedef struct LMA_NeutralCalibration_str
212{
215
217
219
224typedef struct LMA_PhaseAngleError_str
225{
226 uint32_t sample_counter;
230
235typedef struct LMA_Signals_str
236{
241
252
273
277
284
286typedef struct LMA_Energy_str
287{
289 struct unit
290 {
291 float act;
292 float app;
293 float react;
294 } unit;
295
308
310 struct counter
311 {
312 uint64_t act_imp;
314 uint64_t
316 uint64_t app_imp;
318 uint64_t app_exp;
320 uint64_t c_react_imp;
322 uint64_t c_react_exp;
324 uint64_t l_react_imp;
326 uint64_t l_react_exp;
328 } counter;
329} LMA_Energy;
330
332typedef struct LMA_Impulse_str
333{
334 uint32_t led_on_count;
335 uint32_t active_counter;
341} LMA_Impulse;
342
347typedef struct LMA_SystemEnergy_str
348{
349 LMA_Energy energy;
350 LMA_Impulse impulse;
352
354
356
361typedef struct LMA_PhaseCalibArgs_str
362{
364 float vrms_tgt;
365 float irms_tgt;
366 uint32_t line_cycles;
369
374typedef struct LMA_GlobalCalibArgs_str
375{
378 uint32_t rtc_cycles;
380
385typedef struct LMA_Config_str
386{
392 float no_load_i;
393 float no_load_p;
394 float v_sag;
395 float v_swell;
396} LMA_Config;
397
399
401
402#endif /* _LMA_TYPES_H */
int64_t acc_t
Accumulator type.
Definition LMA_Types.h:33
int32_t spl_t
Raw ADC sample type.
Definition LMA_Types.h:27
LMA_Status
Phase status.
Definition LMA_Types.h:54
@ LMA_OK
No Problems.
Definition LMA_Types.h:55
@ LMA_VOLTAGE_SWELL
Vrms Swelled (Vrms > LMA_Config.v_swell)
Definition LMA_Types.h:60
@ LMA_NO_APPARENT_LOAD
No Apparent Power (S < LMA_Config.no_load_p)
Definition LMA_Types.h:58
@ LMA_NO_REACTIVE_LOAD
No Reactive Power (Q < LMA_Config.no_load_p)
Definition LMA_Types.h:57
@ LMA_VOLTAGE_SAG
Vrms Sagged (Vrms < LMA_Config.v_sag)
Definition LMA_Types.h:59
@ LMA_NO_ACTIVE_LOAD
No Active Power (P < LMA_Config.no_load_p)
Definition LMA_Types.h:56
General Accumulator structure.
Definition LMA_Types.h:88
uint32_t sample_count
Sample counter, used to track number of samples during accumulation period.
Definition LMA_Types.h:93
acc_t i_acc
Current accumulator.
Definition LMA_Types.h:90
acc_t p_acc
Active power accumulator.
Definition LMA_Types.h:91
acc_t v_acc
Voltage accumulator.
Definition LMA_Types.h:89
acc_t q_acc
Reactive power accumulator.
Definition LMA_Types.h:92
Runtime LMA Configuration.
Definition LMA_Types.h:386
float fline_tol_low
Lower tolerance of system frequency.
Definition LMA_Types.h:389
float v_sag
Voltage sag value.
Definition LMA_Types.h:394
float no_load_i
No load current value.
Definition LMA_Types.h:392
float v_swell
Voltage swell value.
Definition LMA_Types.h:395
float fline_tol_high
Upper tolerance of system frequency.
Definition LMA_Types.h:390
LMA_GlobalCalibration gcalib
Global calibration data block.
Definition LMA_Types.h:387
float meter_constant
Ws/imp ... translated Ws/imp = 3,600,000 / [imp/kwh].
Definition LMA_Types.h:391
float no_load_p
No active/reactive power load value.
Definition LMA_Types.h:393
uint32_t update_interval
Number of V line cycles to between computation updates.
Definition LMA_Types.h:388
Energy computation data.
Definition LMA_Types.h:149
float act_exp_energy_wh
active energy exported in Wh
Definition LMA_Types.h:151
float l_exp_energy_wh
reactive (inductive) energy exported in Wh
Definition LMA_Types.h:157
float c_exp_energy_wh
reactive (capacitive) energy exported in Wh
Definition LMA_Types.h:155
float app_exp_energy_wh
apparent energy exported in Wh
Definition LMA_Types.h:153
float act_imp_energy_wh
active energy imported in Wh
Definition LMA_Types.h:150
float c_imp_energy_wh
reactive (capacitive) energy imported in Wh
Definition LMA_Types.h:154
float app_imp_energy_wh
apparent energy imported in Wh
Definition LMA_Types.h:152
float l_imp_energy_wh
reactive (inductive) energy imported in Wh
Definition LMA_Types.h:156
Running energy accumulators for counting energy between pulses - Ws (Watt second)
Definition LMA_Types.h:298
float app_exp_ws
Variable used to accumulate the apparent export (to grid) energy.
Definition LMA_Types.h:302
float c_react_imp_ws
Variable used to accumulate the C reactive import (from grid) energy.
Definition LMA_Types.h:303
float app_imp_ws
Variable used to accumulate the apparent import (from grid) energy.
Definition LMA_Types.h:301
float l_react_imp_ws
Variable used to accumulate the L reactive import (from grid) energy.
Definition LMA_Types.h:305
float act_imp_ws
Variable used to accumulate the active import (from grid) energy.
Definition LMA_Types.h:299
float act_exp_ws
Variable used to accumulate the active export (to grid) energy.
Definition LMA_Types.h:300
float l_react_exp_ws
Variable used to accumulate the L reactive export (to grid) energy.
Definition LMA_Types.h:306
float c_react_exp_ws
Variable used to accumulate the C reactive export (to grid) energy.
Definition LMA_Types.h:304
Total energy measured by meter in units of energy (pulses or kwh/imp)
Definition LMA_Types.h:311
uint64_t app_imp
Variable used to accumulate units of energy (pulses) over meter lifetime (apparent import ....
Definition LMA_Types.h:316
uint64_t app_exp
Variable used to accumulate units of energy (pulses) over meter lifetime (apparent export ....
Definition LMA_Types.h:318
uint64_t c_react_imp
Variable used to accumulate units of energy (pulses) over meter lifetime (C reactive import ....
Definition LMA_Types.h:320
uint64_t l_react_exp
Variable used to accumulate units of energy (pulses) over meter lifetime (L reactive export ....
Definition LMA_Types.h:326
uint64_t act_imp
Variable used to accumulate units of energy (pulses) over meter lifetime (active import ....
Definition LMA_Types.h:312
uint64_t c_react_exp
Variable used to accumulate units of energy (pulses) over meter lifetime (C reactive export ....
Definition LMA_Types.h:322
uint64_t act_exp
Variable used to accumulate units of energy (pulses) over meter lifetime (active export ....
Definition LMA_Types.h:315
uint64_t l_react_imp
Variable used to accumulate units of energy (pulses) over meter lifetime (L reactive import ....
Definition LMA_Types.h:324
Currently computed units of energy per ADC interval of whole system.
Definition LMA_Types.h:290
float react
Currently computed unit of reactive energy per ADC interval.
Definition LMA_Types.h:293
float app
Currently computed unit of apparent energy per ADC interval.
Definition LMA_Types.h:292
float act
Currently computed unit of active energy per ADC interval.
Definition LMA_Types.h:291
Energy related data.
Definition LMA_Types.h:287
Energy unit data.
Definition LMA_Types.h:165
float react
Currently computed unit of reactive energy per ADC interval.
Definition LMA_Types.h:168
float app
Currently computed unit of apparent energy per ADC interval.
Definition LMA_Types.h:167
float act
Currently computed unit of active energy per ADC interval.
Definition LMA_Types.h:166
Calibration arguments (global)
Definition LMA_Types.h:375
float rtc_period
period of the RTC for fs calibration
Definition LMA_Types.h:376
float fline_target
Target line frequency.
Definition LMA_Types.h:377
uint32_t rtc_cycles
number of RTC periods to accumulate for frequency calibration
Definition LMA_Types.h:378
Global/System calibration data.
Definition LMA_Types.h:190
float deg_per_sample
degrees per sample
Definition LMA_Types.h:192
float fs
Sampling frequency.
Definition LMA_Types.h:191
Data related to impulse controls.
Definition LMA_Types.h:333
uint32_t led_on_count
Number of ADC intervals for the LED on count.
Definition LMA_Types.h:334
bool reactive_on
Flag indicating the reactive led is on.
Definition LMA_Types.h:340
uint32_t reactive_counter
Counter used to track on time of the reactive LED.
Definition LMA_Types.h:337
uint32_t apparent_counter
Counter used to track on time of the apparent LED.
Definition LMA_Types.h:336
bool apparent_on
Flag indicating the apparent led is on.
Definition LMA_Types.h:339
bool active_on
Flag indicating the active led is on.
Definition LMA_Types.h:338
uint32_t active_counter
Counter used to track on time of the active LED.
Definition LMA_Types.h:335
Measurement output.
Definition LMA_Types.h:134
float irms_neutral
RMS Current (Neutral Sensing)
Definition LMA_Types.h:137
float q
Reactive Power.
Definition LMA_Types.h:140
float vrms
RMS Voltage.
Definition LMA_Types.h:135
float p
Active Power.
Definition LMA_Types.h:139
float fline
Line Frequency.
Definition LMA_Types.h:138
float s
Apparent Power.
Definition LMA_Types.h:141
float irms
RMS Current.
Definition LMA_Types.h:136
Neutral accumulators.
Definition LMA_Types.h:111
acc_t i_acc_snapshot
Snapshot of current accumulator after computation window finished.
Definition LMA_Types.h:113
acc_t i_acc_temp
Running current accumulator.
Definition LMA_Types.h:112
Neutral calibration data.
Definition LMA_Types.h:212
float irms_coeff
Irms coefficient (Neutral channel)
Definition LMA_Types.h:213
Neutral data.
Definition LMA_Types.h:247
LMA_NeutralCalibration calib
Instance of the neautrals calibration data block.
Definition LMA_Types.h:250
LMA_NeutralInputs inputs
Area to load inputs (ADC Samples) for processing.
Definition LMA_Types.h:248
LMA_NeutralAccs accs
Object holding accumulator data.
Definition LMA_Types.h:249
Structure for defining the inputs to a neutral object in terms of samples.
Definition LMA_Types.h:79
spl_t i_sample
Raw ADC Current Sample.
Definition LMA_Types.h:80
Phase accumulators.
Definition LMA_Types.h:101
LMA_Accs snapshot
Object holding snapshot of accumulators after computation window finished.
Definition LMA_Types.h:103
LMA_Accs temp
Object holding running accumulators.
Definition LMA_Types.h:102
Phase-angle error calibration data.
Definition LMA_Types.h:225
float v_fraction
the fractional component of the zero cross on the voltage
Definition LMA_Types.h:227
uint32_t sample_counter
counter to track the number of phase angle computations taken for averaging
Definition LMA_Types.h:226
float i_fraction
the fractional component of the zero cross on the current
Definition LMA_Types.h:228
Calibration arguments (per phase)
Definition LMA_Types.h:362
uint32_t line_cycles_stability
Line cycles to delay for allowing signal stability - typically about 5-10.
Definition LMA_Types.h:367
float vrms_tgt
Vrms target calibration voltage.
Definition LMA_Types.h:364
float irms_tgt
Irms target calibration current.
Definition LMA_Types.h:365
uint32_t line_cycles
Line cycles to stabilise readings over.
Definition LMA_Types.h:366
LMA_Phase * p_phase
Pointer to a phases targetting calibration.
Definition LMA_Types.h:363
Phase calibration data.
Definition LMA_Types.h:200
float vi_phase_correction
V-I Phase Correction (I relative to V i.e., I lags V = negative, I leads V = positive)
Definition LMA_Types.h:203
float vrms_coeff
Vrms coefficient.
Definition LMA_Types.h:201
float irms_coeff
Irms coefficient.
Definition LMA_Types.h:202
float p_coeff
Power coefficient.
Definition LMA_Types.h:204
Phase data.
Definition LMA_Types.h:258
LMA_Status status
Phase status.
Definition LMA_Types.h:266
LMA_PhaseCalibration calib
Instance of the phases calibration data block.
Definition LMA_Types.h:263
LMA_PhaseAccs accs
Object holding accumulator data.
Definition LMA_Types.h:261
LMA_Signals sigs
Phase signals.
Definition LMA_Types.h:267
LMA_PhaseInputs inputs
Area to load inputs (ADC Samples) for processing.
Definition LMA_Types.h:260
LMA_Neutral * p_neutral
Pointer to neutral channel (if present)
Definition LMA_Types.h:268
uint32_t phase_number
zero indexed phase number for identification
Definition LMA_Types.h:271
LMA_Measurements measurements
Object holding measurements from last computation window update.
Definition LMA_Types.h:264
LMA_ZeroCross zero_cross_v
Zero cross tracking variables for voltage.
Definition LMA_Types.h:262
float(* p_computation_hook)(float *i, float *v, float *f)
Hook to enable applying a compensation factor to power based on i, v and f args.
Definition LMA_Types.h:269
struct LMA_Phase_str * p_next
Forms singly linked list of phases (null terminated)
Definition LMA_Types.h:259
LMA_EnergyUnit energy_units
Energy processing block.
Definition LMA_Types.h:265
Structure for defining the inputs to a phase object in terms of samples.
Definition LMA_Types.h:68
spl_t v_sample
Raw ADC Voltage Sample.
Definition LMA_Types.h:69
spl_t i_sample
Raw ADC Current Sample.
Definition LMA_Types.h:71
spl_t v90_sample
90 degreephase shifted ADC Voltage Sample
Definition LMA_Types.h:70
Signal/flag data.
Definition LMA_Types.h:236
bool accumulators_ready
Flag to indicate our accumulators are ready for update.
Definition LMA_Types.h:237
bool calibrating
Flag to indicate system is calibrating.
Definition LMA_Types.h:239
bool measurements_ready
Flag to indicate a new measurement set is ready.
Definition LMA_Types.h:238
Energy data.
Definition LMA_Types.h:348
Zero cross detection data.
Definition LMA_Types.h:121
bool debounce
zerocross debounce flag
Definition LMA_Types.h:124
bool first_event
flag indicating we have already detected a zero cross (synch'd)
Definition LMA_Types.h:125
bool already_run
flag indicating we need to prime the filter
Definition LMA_Types.h:126
uint32_t count
running counter to count the number of zero cross
Definition LMA_Types.h:122
spl_t last_sample
Tracked/filtered voltage.
Definition LMA_Types.h:123