?? meter.h
字號:
/***************************************************************************
* This code and information is provided "as is" without warranty of any *
* kind, either expressed or implied, including but not limited to the *
* implied warranties of merchantability and/or fitness for a particular *
* purpose. *
* *
* Copyright (C) 2005 Teridian Semiconductor Corp. All Rights Reserved. *
***************************************************************************/
//**************************************************************************
// DESCRIPTION: 71M65xx POWER METER -
// Meter structures, enumerates, and defines.
//
// AUTHOR: MTF
//
// HISTORY: See end of file.
//**************************************************************************
// File: METER.H
//
#ifndef METER_H
#define METER_H
#include "rtc.h"
/////////////////////////////////////////////////////////////////////////////
//***************************************************************************
//* METER DEFINITIONS AND DECLARATIONS
//***************************************************************************
/////////////////////////////////////////////////////////////////////////////
#define FS (32768. / 13.) // Frame sample rate (about 2520.6 s/s).
struct Parameters_t
{ // MPU address.
uint32_t T_IThrshld; // Starting current. (Current threshold)
uint8_t T_Config; // Configuration Control.
uint32_t T_VPThrshld; // Peak voltage threshold. LSB as v0sqsum
uint32_t T_IPThrshld; // Peak current threshold. LSB as i0sqsum
int16_t T_Y_Cal_Deg0; // Crystal calibration constants, RTC only.
int16_t T_Y_Cal_Deg1; //
int16_t T_Y_Cal_Deg2; //
uint8_t T_PulseWSource; // Select one of 21 sources for APULSEW.
uint8_t T_PulseRSource; // Select one of 21 sources for APULSER.
uint16_t T_Vmax; // VMax in 100 mVolts.
uint16_t T_Imax; // IMax in 100 mAmps.
int16_t T_ppmc1; //-6680 -6.680 * (ppm/c) * 1000; PPM/C * 26.84.
int16_t T_ppmc2; //-341 -0.341 * (ppm/c^2) * 1000; PPM/C^2 * 1374.
uint8_t T_Pulse3Source; // software pulse sources
uint8_t T_Pulse4Source; //
uint16_t T_Scal; // seconds of calibration.
uint16_t T_Vcal; // calibration voltage, LSB = 0.1V (like VMAX).
uint16_t T_Ical; // calibration current, LSB = 0.1A (like IMAX).
uint32_t T_VThrshld; // Minimum voltage threshold.
int16_t T_PulseWidth; // 50 The maximum wpulse and vpulse width is 2*PULSEWIDTH+1 samples.
int32_t T_temp_nom; // Temperature reading at calibration;
uint16_t T_Imax2; // IMaxw in 100 mAmps.
uint32_t T_IThrshld2; // Starting current, sensor 2.
int32_t T_VBatMin; // Battery minimum, ADC units
uint8_t T_Reserved; // unused space
uint8_t T_lrc; // checksum
};
#define SUM_SIZE 8
typedef struct { uint8_t a[ SUM_SIZE ]; } SUM_t;
// The offsets into this structure are documented, so they shouldn't change.
// This structure is cleared on reset, and recalculated on each accumulation
// interval. The values need not be saved on sag.
// To make some of this data into a nonvolatile revenue register, just
// move the register group into Acc_T, below, and change the equates, also below.
struct Sums_t // LSB = 9.4045E-13 Watt/VAR/VA hours.
{
int8_16_32_t T_Status; // Status. [Maintained by MPU].
int32_t T_cai; // count of accumulation intervals
SUM_t T_Whi; // Total Watt hours imported (All Phases).
SUM_t T_Whi_A; // Total Watt hours imported (Phase A).
SUM_t T_Whi_B; // Total Watt hours imported (Phase B).
SUM_t T_Whi_C; // Total Watt hours imported (Phase C).
SUM_t T_VARhi; // Total VAR hours imported (All Phases).
SUM_t T_VARhi_A; // Total VAR hours imported (Phase A).
SUM_t T_VARhi_B; // Total VAR hours imported (Phase B).
SUM_t T_VARhi_C; // Total VAR hours imported (Phase C).
SUM_t T_VAh; // Total VA hours combined (All Phases).
SUM_t T_VAh_A; // Total VA hours (Phase A).
SUM_t T_VAh_B; // Total VA hours (Phase B).
SUM_t T_VAh_C; // Total VA hours (Phase C).
SUM_t T_Whe; // Total Watt hours exported (All Phases).
SUM_t T_Whe_A; // Total Watt hours exported (Phase A).
SUM_t T_Whe_B; // Total Watt hours exported (Phase B).
SUM_t T_Whe_C; // Total Watt hours exported (Phase C).
SUM_t T_VARhe; // Total VAR hours exported (All Phases).
SUM_t T_VARhe_A; // Total VAR hours exported (Phase A).
SUM_t T_VARhe_B; // Total VAR hours exported (Phase B).
SUM_t T_VARhe_C; // Total VAR hours exported (Phase C).
//----------------------------------------------------------------------//
// These are used for phased calibration and net metering
SUM_t T_Whn; // net-metered Whs for element A
SUM_t T_Whn_A; // net-metered Whs for element A
SUM_t T_Whn_B; // net-metered Whs for element B
SUM_t T_Whn_C; // net-metered Whs for element C
// These are used for phased calibration and net metering
SUM_t T_VARh; // net-metered VARs for element A
SUM_t T_VARh_A; // net-metered VARs for element A
SUM_t T_VARh_B; // net-metered VARs for element B
SUM_t T_VARh_C; // net-metered VARs for element C
// This ought to be cleared when )1=2
// This is also used when the RTC is locked to the line frequency
int32_t T_MainEdgeCount; // count of zero crossings.
};
// This structure is saved on sag. It should be as small as possible.
// It must contain all revenue registers.
struct Accumulators_t
{
// Demonstration revenue registers
// 1 phase meter preserves sum data
SUM_t T_Whr; // Total Watt hours (All Phases).
// 3-phase meter preserves phase data, calculates sum data
SUM_t T_Whr_A; // Total Watt hours (Phase A).
SUM_t T_Whr_B; // Total Watt hours (Phase B).
SUM_t T_Whr_C; // Total Watt hours (Phase C).
// nonvolatile error status
int32_t T_Status; // Bit-per-error
// brownout data
uint32_t T_brownout_cache;
uint8_t T_brownout_cache_mode;
uint8_t T_brownout_cache_valid;
// Nonvolatile timekeeping data
#if REAL_TIME_DATE
struct RTC_t T_Rtc_Time_Date; // most recent RTC Time and Date.
#endif
#if REAL_TIME_DATE && !RTC_LINE_LOCKED
// manage the real time clock so that it can be
// compensated for the time the device is off.
volatile int32_t T_trim_count; // signed values can cancel as
volatile int32_t T_trim_value; // the temperature varies.
// the second count has to be able to hold +/-900 1 second
// adjustments in case the meter is on the shelf for five years,
// crystal running at +/-6ppm, each year is ~30 million seconds.
volatile int16_t T_second_count; // queues multiple adjustments
#endif
#if OPERATING_TIME
uint32_t T_OperatingSeconds; // Total Seconds of Operation.
#endif
uint8_t T_CalibrationCount; // count of calibrations
uint8_t lrc; // space for the longitudinal error check
};
#if ERROR_RECORDING
// private data structures
struct Er
{
uint8_t errno; // error number, same as the bit number of Status
uint8_t cnt; // error count
uint8_t month;
uint8_t date;
uint8_t hour;
};
#define cer 5
#define ierMax (cer - 1) // maximum error index
struct Errors_t
{
struct Er aer[cer]; // array of error records
int32_t status; // private copy of status
uint8_t lrc; // space for the longitudinal error check
};
#define Aer Totals.Err.aer
#define OldStatus Totals.Err.status
#endif
// These can be updated as often as once every 200 ms.
//
struct Totals_t
{
// everything up to and including "Sums" tries to be unconditional, to preserve
// the memory structure for use by the CLI, and memory-reading serial protocols.
struct Parameters_t Parms; // Parameters
uint8_t T_main_edge_cnt_nom; // nominal edges per second of mains
// after this, it's all 4 and 8 byte values, so the CLI can index them
// Deviation from 22C, TEMP_NOM - TEMP; LSB 0.1 degrees C.
int32_t T_deltaT; // Delta temperature from cal. temp.[Computed by MPU].
uint32_t T_Frequency; // Frequency. [Computed by MPU].
int32_t T_VBat; // Last measured voltage of battery [Computed by MPU].
int32_t T_Irms_N; // Irms neutral. [Computed by MPU].
int32_t T_Vrms_A; // Vrms from element 0 (A). [Computed by MPU].
int32_t T_Irms_A; // Irms from element 0 (A). [Computed by MPU].
int32_t T_Vrms_B; // Vrms from element 1 (B). [Computed by MPU].
int32_t T_Irms_B; // Irms from element 1 (B). [Computed by MPU].
int32_t T_Vrms_C; // Vrms from element 2 (C). [Computed by MPU].
int32_t T_Irms_C; // Irms from element 2 (C). [Computed by MPU].
struct Sums_t Sums; // Accumulated Energies. [Computed by MPU].
// If the power fails during the calculation of the nonvolatile
// registers, the second copy will still be valid when both copies are saved and restored.
struct Accumulators_t Acc; // Nonvolatile registers. [Computed by MPU].
struct Accumulators_t AccB; // Nonvolatile registers. [Computed by MPU].
// error recording
#if ERROR_RECORDING
struct Errors_t Err;
#endif
#if POWER_FACTOR
// Power factors, LSB = 1/100000, so it displays in a percent, with three decimals
int16_t T_Pf_A; // from element 0 (A). [Computed by MPU].
int16_t T_Pf_B; // from element 1 (B). [Computed by MPU].
int16_t T_Pf_C; // from element 2 (C). [Computed by MPU].
#endif
#if PHASE_ANGLES
// V/I phase angle, LSB = 1/10 degree, so it displays with 1 decimal
int32_t T_IPhase_A; // I0:V0 phase from element 0 (A). [Computed by MPU].
int32_t T_IPhase_B; // I1:V1 phase from element 1 (B). [Computed by MPU].
int32_t T_IPhase_C; // I2:V2 phase from element 2 (C). [Computed by MPU].
#endif
#if VOLTAGE_PHASES
// V/V phase angle, LSB = 1/10 degree, so it displays with 1 decimal
int32_t T_VPhase_AB; // Voltage AB Phase angle. [Computed by MPU].
int32_t T_VPhase_AC; // Voltage AC Phase angle. [Computed by MPU].
#endif
};
// Definitions for 'Config'.
#define CFG_VAH_SELECT 0x01 // Select VAh equation; 1 => V*I, 0 => sqrt(W^2 + VAR^2).
#define CFG_CLEAR_ACC 0x02 // Initialize accumulators (auto clear)
#define CFG_CAL 0x04 // Run calibration
#define CFG_TAMPER 0x08 // Enable tamper detection.
#define CFG_OPTICAL 0x10 // Enable/disable optical port test.
// Definitions for 'Status'. Feel free to add to them.
#define CREEP BIT0 // Creep Alert.
#define MINVC BIT1 // Under Min VA.
#define PB_PRESS BIT2 // push button detected
#define WAKE_ALARM BIT3 // wake timer detected
#define MINVB BIT4 // Under min VB.
#define MAXVA BIT5 // Over max. voltage
#define MAXVB BIT6 // Over max. voltage
#define MAXVC BIT7 // Over max. voltage
#define MINVA BIT8 // Under min VC.
#define WD_DETECTED BIT9 // Unexpected reset.
#define RESERVED_10 BIT10 // Use as needed.
#define MAXIA BIT11 // Over max. current on A
#define MAXIB BIT12 // Over max. current on B
#define MAXIC BIT13 // Over max. current on C
#define MINT BIT14 // Min. temperature exceeded
#define MAXT BIT15 // Max. temperature exceeded
#define BATTERY_BAD BIT16 // Battery test failed
#define RESERVED_17 BIT17 // Use as needed.
#define CAL_BAD BIT18 // Calibration is invalid
#define CLOCK_UNSET BIT19 // Clock is not set
#define POWER_BAD BIT20 // Power register data was lost
#define GNDNEUTRAL BIT21 // Grounded neutral detected
#define TAMPER BIT22 // Tamper detected
#define VXEDGE BIT23
#define RESERVED_24 BIT24
#define SAGA BIT25 // Sag detected; conductor A
#define SAGB BIT26 // Sag detected; conductor B
#define SAGC BIT27 // Sag detected; conductor C
#define F0_CE BIT28
#define RESERVED_29 BIT29 // Use as needed.
#define RESERVED_30 BIT30 // Use as needed.
#define ONE_SEC BIT31
// The events that are worth recording
#define WORTH_RECORDING ( \
TAMPER \
| GNDNEUTRAL \
| CLOCK_UNSET \
| POWER_BAD \
| CAL_BAD \
| BATTERY_BAD \
| MAXT \
| MINT \
| MAXIA \
| MAXIB \
| MAXIC \
| SAGA \
| SAGB \
| SAGC \
)
#define MAX_ERR_CNT 14
//================================================================================================//
#define IThrshld Totals.Parms.T_IThrshld
#define Config Totals.Parms.T_Config
#define VPThrshld Totals.Parms.T_VPThrshld
#define IPThrshld Totals.Parms.T_IPThrshld
#define Y_Cal_Deg0 Totals.Parms.T_Y_Cal_Deg0
#define Y_Cal_Deg1 Totals.Parms.T_Y_Cal_Deg1
#define Y_Cal_Deg2 Totals.Parms.T_Y_Cal_Deg2
#define PulseWSource Totals.Parms.T_PulseWSource
#define PulseRSource Totals.Parms.T_PulseRSource
#define Vmax Totals.Parms.T_Vmax
#define Imax Totals.Parms.T_Imax
#define ppmc1 Totals.Parms.T_ppmc1
#define ppmc2 Totals.Parms.T_ppmc2
#define Pulse3Source Totals.Parms.T_Pulse3Source
#define Pulse4Source Totals.Parms.T_Pulse4Source
#define Scal Totals.Parms.T_Scal
#define Vcal Totals.Parms.T_Vcal
#define Ical Totals.Parms.T_Ical
#define VThrshld Totals.Parms.T_VThrshld
#define PulseWidth Totals.Parms.T_PulseWidth
#define temp_nom Totals.Parms.T_temp_nom
#define Imax2 Totals.Parms.T_Imax2
#define IThrshld2 Totals.Parms.T_IThrshld2
#define VBatMin Totals.Parms.T_VBatMin
//---------------------------------------------------------------------------//
// Deviation from 22C, TEMP_NOM - TEMP; LSB 0.1 degrees C.
#define deltaT Totals.T_deltaT
#define Frequency Totals.T_Frequency
#define VBat Totals.T_VBat
#define Irms_N Totals.T_Irms_N
#define Vrms_A Totals.T_Vrms_A
#define Irms_A Totals.T_Irms_A
#define Vrms_B Totals.T_Vrms_B
#define Irms_B Totals.T_Irms_B
#define Vrms_C Totals.T_Vrms_C
#define Irms_C Totals.T_Irms_C
#define Pf_A Totals.T_Pf_A
#define Pf_B Totals.T_Pf_B
#define Pf_C Totals.T_Pf_C
#define IPhase_B Totals.T_IPhase_B
#define IPhase_C Totals.T_IPhase_C
#define IPhase_A Totals.T_IPhase_A
#define IPhase_B Totals.T_IPhase_B
#define IPhase_C Totals.T_IPhase_C
#define VPhase_AB Totals.T_VPhase_AB
#define VPhase_AC Totals.T_VPhase_AC
//----------------------------------------------------------------------------//
// The watt hour registers are used in a table in meter.c.
// It has to be populated or the display fails. Therefore,
// these are all defined.
// Nonvolatile "revenue registers" are in "Acc" rather than "Sums"
// The table is also accessed by ) in the command line interface,
#define Status Totals.Sums.T_Status.l
#define cai Totals.Sums.T_cai
// Other stuff; optional
#define Whi Totals.Sums.T_Whi.a
#define Whi_A Totals.Sums.T_Whi_A.a
#define Whi_B Totals.Sums.T_Whi_B.a
#define Whi_C Totals.Sums.T_Whi_C.a
#define VARhi Totals.Sums.T_VARhi.a
#define VARhi_A Totals.Sums.T_VARhi_A.a
#define VARhi_B Totals.Sums.T_VARhi_B.a
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -