📄 emeter-structs.h
字号:
#if defined(PRECALCULATED_PARAMETER_SUPPORT)
/*! \brief The RMS current, in 1mA steps */
#if defined(IRMS_SUPPORT)
uint16_t I_rms;
#endif
int32_t power;
#endif
int8_t I_endstops;
#if defined(POWER_FACTOR_SUPPORT)
int8_t leading;
#endif
#if defined(HARMONICS_SUPPORT)
goertzel_state_t harm_1;
goertzel_state_t harm_3;
goertzel_state_t harm_5;
int32_t pow_1;
int32_t pow_3;
int32_t pow_5;
int16_t harmonic_step;
int16_t harmonic_samples;
#endif
int stage_in_use;
int stage_hits;
};
/*! This structure contains the non-volatile parameters associated with a
single current sensor (e.g a shunt resistor or a current transformer). */
struct current_sensor_nv_parms_s
{
#if defined(IRMS_SUPPORT)
/*! The scaling factor between the raw RMS current value, and milliamps, when in
normal operation. */
int16_t I_rms_scale_factor[GAIN_STAGES];
#if defined(LIMP_MODE_SUPPORT)
/*! The scaling factor between the raw RMS current value, and milliamps when in
limp mode. */
int16_t I_rms_limp_scale_factor[GAIN_STAGES];
#endif
/*! An offset to remove an approximation of the front end noise from the measured RMS
current. */
int32_t ac_offset;
#endif
/*! The scaling factor between the raw active power value, and 0.1W increments, when in
normal operation. */
int16_t P_scale_factor[GAIN_STAGES];
/*! An initial value for the DC estimate, to ensure rapid settling after reset. */
int32_t initial_dc_estimate;
#if defined(PHASE_CORRECTION_SUPPORT)
int16_t phase_correction[GAIN_STAGES];
#endif
};
/*! This structure holds all the working data for one phase. */
struct phase_parms_s
{
#if defined(PRECALCULATED_PARAMETER_SUPPORT)
int32_t power;
#if defined(VRMS_SUPPORT)
/*! \brief The RMS voltage, in 10mV steps */
uint16_t V_rms;
#endif
#if defined(IRMS_SUPPORT)
/*! \brief The RMS current, in 1mA steps */
uint16_t I_rms;
#endif
#if defined(MAINS_FREQUENCY_SUPPORT)
/*! \brief The mains frequency, in steps of 1/100Hz */
uint16_t frequency;
#endif
#if defined(POWER_FACTOR_SUPPORT)
/*! \brief The power factor, in steps of 0.001 */
int16_t power_factor;
#endif
#if defined(REACTIVE_POWER_SUPPORT)
int32_t reactive_power;
#endif
#if defined(VA_POWER_SUPPORT)
int32_t VA_power;
#endif
#endif
/* Voltage channel DC estimates. We need separate estimates for normal
and limp mode, as in limp mode we use a different ADC reference. */
#if defined(LIMP_MODE_SUPPORT)
int32_t V_dc_estimate[2];
#else
int32_t V_dc_estimate;
#endif
#if defined(REACTIVE_POWER_BY_QUADRATURE_SUPPORT)
int16_t V_history[32];
#elif defined(PHASE_CORRECTION_SUPPORT)
int16_t V_history[4];
#endif
#if defined(VRMS_SUPPORT) || defined(POWER_FACTOR_SUPPORT)
/* Accumulated squares of the phase corrected voltage (V.V). These are used to
calculate the RMS voltage, and the power factor. We need separate accumulation
for each current sensor, as we accumulate the phase corrected voltage which matches
the current sensor's phase shift. The actual phase correction is not important for this.
However, if we use just one accumulated voltage we would need to use a scaling factor before
it can be applied. This might reduce precision, so we do things this way. */
int16_t V_sq_accum[3];
int16_t /*volatile*/ V_sq_accum_logged[3];
#endif
/*! This is the data for the live lead current sensor. */
struct current_sensor_parms_s current;
#if defined(SINGLE_PHASE) && defined(NEUTRAL_MONITOR_SUPPORT)
/*! This is the data for the neutral lead current sensor, for a single phase meter
with anti-tampering features. */
struct current_sensor_parms_s neutral;
#endif
/*! This is the number of samples accumulated to date in the block of processed
signals being gathered. */
int16_t sample_count;
/*! This records the number of samples accumulated in a currently saved block of
processed signals. */
int16_t /*volatile*/ sample_count_logged;
#if defined(PER_PHASE_ENERGY_SUPPORT)
int32_t power_counter;
int32_t energy_counter;
uint32_t consumed_energy;
#endif
#if defined(MAINS_FREQUENCY_SUPPORT)
/*! This is a count of the number of samples to date in the current mains cycle. */
int16_t cycle_sample_count;
/*! This is the current estimate of the length of a mains cycle, in units of 1/256th
of a sample time. */
int32_t mains_period;
#endif
int since_last;
int16_t last_V_sample;
uint16_t /*volatile*/ status;
/*! This value counts down each time an ADC sample from the voltage
channel hits the end of the ADC range. It is used to detect an
overrange signal in a robust way, ignoring a small number of samples
hits the ends of the ADC range, which might just be a few noise spikes. */
int8_t V_endstops;
#if defined(REACTIVE_POWER_BY_QUADRATURE_SUPPORT) || defined(PHASE_CORRECTION_SUPPORT)
/*! This is a pointer to the current latest value in the voltage sample history
buffer. */
int8_t V_history_index;
#endif
#if defined(PER_PHASE_ENERGY_SUPPORT)
/*! This times the duration of an energy pulse */
uint8_t energy_pulse_remaining_time;
#endif
};
#if !defined(SINGLE_PHASE) && defined(NEUTRAL_MONITOR_SUPPORT)
/*! This structure holds all the working data for a multi-phase meter's
neutral monitoring. */
struct neutral_parms_s
{
#if PRECALCULATED_PARAMETER_SUPPORT
#if defined(IRMS_SUPPORT)
uint16_t I_rms;
#endif
#if MAINS_FREQUENCY_SUPPORT
uint16_t frequency;
#endif
#endif
/* Channel's DC estimates, accumulated powers, and the logged
accumulated power from the last measurement cycle. */
int32_t I_dc_estimate;
#if IRMS_SUPPORT || POWER_FACTOR_SUPPORT
int16_t I_sq_accum[3];
int16_t /*volatile*/ I_sq_accum_logged[3];
#endif
int16_t sample_count;
int16_t /*volatile*/ sample_count_logged;
#if MAINS_FREQUENCY_SUPPORT
int16_t cycle_sample_count;
int32_t mains_period;
#endif
/*! This value counts down each time an ADC sample from the current
channel hits the end of the ADC range. It is used to detect an
overrange signal in a robust way, ignoring a small number of samples
hits the ends of the ADC range, which might just be a few noise spikes. */
int8_t I_endstops;
uint16_t /*volatile*/ status;
};
#endif
#if defined(REACTIVE_POWER_BY_QUADRATURE_SUPPORT)
#define V_HISTORY_MASK 0x1F
#elif defined(PHASE_CORRECTION_SUPPORT)
#define V_HISTORY_MASK 0x3
#endif
/*! This structure contains the non-volatile parameters associated with a phase. */
struct phase_nv_parms_s
{
struct current_sensor_nv_parms_s current;
#if defined(VRMS_SUPPORT)
int16_t V_rms_scale_factor;
#if defined(LIMP_MODE_SUPPORT)
int16_t V_rms_limp_scale_factor;
#endif
#endif
int32_t initial_v_dc_estimate;
#if defined(LIMP_MODE_SUPPORT)
int32_t initial_v_limp_dc_estimate;
#endif
};
/*! This structure is an image of the non-volatile calibration parameters
stored in the info memory. */
struct nv_parms_s
{
int16_t meter_uncalibrated;
#if SELF_TEST_SUPPORT
/*! brief A place to permanently record failures detected in the meter. */
int16_t meter_failures;
/*! brief A place to permanently record recoverable failures detected in the meter. */
int16_t meter_warnings;
#endif
#if defined(SINGLE_PHASE)
struct phase_nv_parms_s chan1;
#else
struct phase_nv_parms_s chan[NUM_PHASES];
#endif
#if NEUTRAL_MONITOR_SUPPORT
struct current_sensor_nv_parms_s neutral;
#endif
#if defined(TEMPERATURE_SUPPORT)
uint16_t temperature_at_calibration;
uint16_t temperature_offset;
uint16_t temperature_scaling;
#endif
#if defined(CORRECTED_RTC_SUPPORT)
int32_t crystal_base_correction;
#endif
rtc_t rtc_at_calibration;
/* Pad to word alignment */
uint8_t xxx;
/* Keep these administrative strings an even number of bytes each */
uint8_t serial_number[16 + 2];
uint8_t property_number[16 + 2];
uint8_t factory_number[10 + 2];
};
/*! This union overlays a segment of the info, ensuring correct
alignment. */
struct info_mem_s
{
union
{
struct nv_parms_s s;
int8_t x[128];
} seg_a;
union
{
int8_t x[128];
} seg_b;
};
/* These are the flags defined for the channel's status variable. */
/*! This flag in a channel's status variable indicates the voltage signal is currently in
the positive half of its cycle. */
#define V_POS 0x0001
/*! This flag in a channel's status variable indicates the current signal is currently in
the positive half of its cycle. */
#define I_POS 0x0002
#define ENERGY_LOGABLE 0x0004
#define NEW_LOG 0x0008
/*! This flag in a channel's status variable indicates the voltage signal was in overload
during the last logged interval. Overload is determined by an excessive number of
samples hitting the end-stops of the ADC's range. */
#define V_OVERRANGE 0x0010
/*! This flag in a channel's status variable indicates the phase current signal was in overload
during the last logged interval. Overload is determined by an excessive number of
samples hitting the end-stops of the ADC's range. */
#define I_OVERRANGE 0x0020
/*! This flag in a channel's status variable indicates the phae current signal was reversed
during the last logged interval. */
#define I_REVERSED 0x0040
/*! This flag in a channel's status variable indicates the phase current signal was in overload
during the last logged interval. Overload is determined by an excessive number of
samples hitting the end-stops of the ADC's range. This is only used if the meter supports
monitoring of both the live and neutral leads for anti-tamper management. */
#define I_NEUTRAL_OVERRANGE 0x0080
/*! This flag in a channel's status variable indicates the neutral current signal was
reversed during the last logged interval. This is only used if the meter supports
monitoring of both the live and neutral leads for anti-tamper management. */
#define I_NEUTRAL_REVERSED 0x0100
/*! This flag in a channel's status variable indicates the neutral current is the one
currently being used. This means it has been judged by the anti-tamper logic to be
the measurement which can best be trusted. This is only used if the meter supports
monitoring of both the live and neutral leads for anti-tamper management. */
#define CURRENT_FROM_NEUTRAL 0x0200
/*! This flag in a channel's status variable indicates the neutral current signal is
currently in the positive half of its cycle. This is only used if the meter supports
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -