📄 energyw.h
字号:
#define WGAIN 0x1D
#define VARGAIN 0x1E
#define VAGAIN 0x1F
#define WATTOS 0x20
#define VAROS 0x21
#define IRMSOS 0x22
#define VRMSOS 0x23
#define WDIV 0x24
#define VARDIV 0x25
#define VADIV 0x26
#define CF1NUM 0x27
#define CF1DEN 0x28
#define CF2NUM 0x29
#define CF2DEN 0x2A
/*******************************************************************************
Definition of Energy Registers--MODE1
*******************************************************************************/
#define MODE1 0x0b
#define SWRST 0x80 //Reset all of the energy measurement registers to default
#define DISZXLPF 0x40 //Disable the zero-crossing LPF
#define INTE 0x20 //Enable the digital integrator
#define SWAPBITS 0x10 //Swap CH1&CH2 ADCs
#define PWRDN 0x08 //Power down ADCs.
#define DISCF2 0x04 //Disable Frequency output CF2
#define DISCF1 0x02 //Disable Frequency output CF1
#define DISHPF 0x01 //Disable the HPFs in voltage and current channels.
/*******************************************************************************
Definition of Energy Registers--MODE2
*******************************************************************************/
#define MODE2 0x0c
//Configuration bits for CF2 output
#define CF2_WATT 0x00 //CF2 frequency is proportional to active power
#define CF2_VAR 0x40 //CF2 frequency is proportional to reactive power
#define CF2_VA_IRMS 0x80 //CF2 frequency is proportional to apparent power or IRMS
//Configuration bits for CF1 output
#define CF1_WATT 0x00 //CF1 frequency is proportional to active power
#define CF1_VAR 0x10 //CF1 frequency is proportional to reactive power
#define CF1_VA_IRMS 0x20 //CF1 frequency is proportional to apparent power or IRMS
//Configuration bits for apparent power or IRMS for CF1&CF2 outputs
#define CF_IRMS 0x08
#define CF_VA 0x00
#define ZXRMS 0x04 //Enable update of RMS values synchronously to voltage ZX
#define FREQSEL 0x02 //PER_FREQ register holds a frequency measurement
/*******************************************************************************
Definition of Energy Registers--WAVMODE
*******************************************************************************/
#define WAVMODE 0x0d
//Waveform 2 selection for samples mode
#define WAV2_CURRENT 0x00 //Current output
#define WAV2_VOLTAGE 0x20 //Voltage output
#define WAV2_AP_MUL 0x40 //Active Power multiplier output
#define WAV2_VAR_MUL 0x60 //Reactive Power multiplier output
#define WAV2_VA_MUL 0x80 //VA multiplier output
#define WAV2_IRMS_LPF 0xa0 //IRMS LPF output
//Waveform 1 selection for samples mode
#define WAV1_CURRENT 0x00 //Current output
#define WAV1_VOLTAGE 0x04 //Voltage output
#define WAV1_AP_MUL 0x08 //Active Power multiplier output
#define WAV1_VAR_MUL 0x0c //Reactive Power multiplier output
#define WAV1_VA_MUL 0x10 //VA multiplier output
#define WAV1_IRMS_LPF 0x14 //IRMS LPF output
//Waveform samples output data rate
#define DTRT_25K6 0x00 //25.6Ksps
#define DTRT_12K8 0x01 //12.8Ksps
#define DTRT_6K4 0x02 // 6.4Ksps
#define DTRT_3K2 0x03 // 3.2Ksps
/*******************************************************************************
Definition of Energy Registers--NOLDMODE
*******************************************************************************/
#define NLMODE 0x0e
#define IRMSNOLOAD 0x40 //Enable IRMS no-load threshold detection.
//The level is defined by the setting of the VANOLOAD bits.
//Apparent power No-load threshold
#define VANOLOAD_OFF 0x00 //Disabled
#define VANOLOAD_030 0x10 //Enabled with threshold = 0.030% of Full scale
#define VANOLOAD_015 0x20 //Enabled with threshold = 0.015% of Full scale
#define VANOLOAD_0075 0x30 //Enabled with threshold = 0.0075% of Full scale
//Reactive power No-l oad threshold
#define VARNOLOAD_OFF 0x00 //Disabled
#define VARNOLOAD_015 0x04 //Enabled with threshold = 0.015% of Full scale
#define VARNOLOAD_0075 0x08 //Enabled with threshold = 0.0075% of Full scale
#define VARNOLOAD_0037 0x0c //Enabled with threshold = 0.0037% of Full scale
//Reactive power No-l oad threshold
#define APNOLOAD_OFF 0x00 //Disabled
#define APNOLOAD_015 0x01 //Enabled with threshold = 0.015% of Full scale
#define APNOLOAD_0075 0x02 //Enabled with threshold = 0.0075% of Full scale
#define APNOLOAD_0037 0x03 //Enabled with threshold = 0.0037% of Full scale
/*******************************************************************************
Definition of Energy Registers--ACCMODE
*******************************************************************************/
//This bit indicate the current channel used to measure energy in anti-tampering mode
//0-Channel A
//1-Channel B
#define ACCMODE 0x0F
#define ICHANNEL 0x80
//Configuration bit to select event that will trigger a Fault interrupt
//0-Fault interrupt occurs when part enters Fault mode.
//1-Fault interrupt occurs when part enters Normal mode.
#define FAULTSIGN_EXIT 0x40
#define FAULTSIGN_ENTER 0x00
//Configuration bit to select event that will trigger an reactive power sign interrupt
//0-VARSIGN interrupt occurs when reative power changes from positive to negative
//1-VARSIGN interrupt occurs when reative power changes from negative to positive
#define VARSIGN_N_P 0x20
#define VARSIGN_P_N 0x00
//Configuration bit to select event that will trigger an active power sign interrupt
//0-VARSIGN interrupt occurs when ative power changes from positive to negative
//1-VARSIGN interrupt occurs when ative power changes from negative to positive
#define APSIGN_N_P 0x10
#define APSIGN_P_N 0x00
//1-Enables absolute value accumulation of Reactive power in energy register and pulse output
#define ABSVARM 0x08
//1-Enables reactive power accumulation depending on the sign of active power
//if Active power is positive,VAR is accumulated as it is;
//if Active power is negative,the sign of the VAR is reversed for the accumulation.
//This accumulation mode affects both the VAR registers and the VARCF output.
#define SAVARM 0x04
//1-Enables positive only accumulation of Active power in energy register and pulse output
#define POAM 0x02
//1-Enables absolute value accumulation of Active power in energy register and pulse output
#define ABSAM 0x01
/*******************************************************************************
Definition of Energy Registers--GAIN
*******************************************************************************/
#define GAIN 0x1b
//These bits define the voltage channel input gain
#define PGA2_X1 0x00 //Gain = 1
#define PGA2_X2 0x20 //Gain = 2
#define PGA2_X4 0x40 //Gain = 4
#define PGA2_X8 0x60 //Gain = 8
#define PGA2_X16 0x80 //Gain = 16
//These bits define the current channel input gain
#define PGA1_X1 0x00 //Gain = 1
#define PGA1_X2 0x01 //Gain = 2
#define PGA1_X4 0x02 //Gain = 4
#define PGA1_X8 0x03 //Gain = 8
#define PGA1_X16 0x04 //Gain = 16
/*******************************************************************************
Definition of Energy Registers--CALMODE
*******************************************************************************/
#define CALMODE 0X3D
//These bits define the current channel used for energy measurements.
#define SEL_ICH_AUTO 0x30 //Current channel automatically selected by the tampering condition
#define SEL_ICH_A 0x10 //Current channel connected to IA
#define SEL_ICH_B 0x20 //Current channel connected to IB
#define V_CH_SHORT 0x08 //short V channel to ground
#define I_CH_SHORT 0x04 //short I channel to ground
/*******************************************************************************
Macro Definition of Accessing Energy SFRs and Registers
*******************************************************************************/
//This macro is used for getting a 3-byte value from energy SFRs,
//sfrname should be one of:VRMS,IRMS,EIRQEN,EIRQST,WAV1,WAV2
//the 3-byte value will be saved in AdeReg
#define GetEnergySFR(sfrname,DataL,DataM,DataH) \
{\
DataH = sfrname##H;\
DataM = sfrname##M;\
DataL = sfrname##L;\
}
//------------------------------------------------------------------------------
//This macro is used for getting a value from energy registers,
//the return value will be saved in AdeReg
#define GetEnergyReg(regaddr,DataL,DataM,DataH)\
{\
MADDPT = regaddr;\
SomeNops();\
DataL = MDATL;\
DataM = MDATM;\
DataH = MDATH;\
}
//------------------------------------------------------------------------------
//This macro is used for setting a 2-byte energy register,
//regaddr should be a r/w register.
#define SetEnergyReg2(regaddr,DataL,DataM)\
{\
MDATL = DataL;\
MDATM = DataM;\
MADDPT= regaddr | 0x80;\
SomeNops();\
}
//------------------------------------------------------------------------------
//This macro is used for setting a 1-byte energy register,
//regaddr should be a r/w register.
#define SetEnergyReg1(regaddr,DataL)\
{\
MDATL = DataL;\
MADDPT= regaddr | 0x80;\
SomeNops();\
}
//------------------------------------------------------------------------------
// This macro is used for delay ,for matching the speed of MCU(MCLK) and periphery (MCLK/5)
void SomeNops(void)
{
asm("Nop");
asm("Nop");
asm("Nop");
asm("Nop");
asm("Nop");
}
//
/*******************************************************************************
Definition of Globe Routines
*******************************************************************************/
extern void EnergyInit(void);
extern void MeasureAll(void);
extern void ClearWatchdog(void);
extern void EnergyReload(void);
extern void EnergySave(void);
extern void SomeNops(void);
extern void I2C_WriteBlock(unsigned char chip_block,unsigned char addr,unsigned char __idata *buf,unsigned char len);
extern unsigned char I2C_ReadByte(unsigned char chip_block,unsigned char addr);
extern void I2C_ReadBlock(unsigned char chip_block,unsigned char addr,unsigned char __idata *buf,unsigned char len);
/*******************************************************************************
Definition of Globe Variables
*******************************************************************************/
//extern ADE_REGS AdeReg;
extern __idata unsigned int Irms;
extern __idata unsigned int Vrms;
extern __idata unsigned int ActivePower;
extern __idata unsigned int ReactivePower;
extern __idata unsigned int ApparentPower;
extern __idata unsigned int PowerFactor;
extern __idata unsigned int Frequency;
extern __idata unsigned int Temperature;
extern __idata EEDATA EEData;
//#define Date (EEData.DD)
//#define Month (EEData.MM)
//#define Year (EEData.YY)
//#define CF1Counter (EEData.CF1)
//#define PCF1Counter (EEData.PCF1)
//#define NCF1Counter (EEData.NCF1)
#define ActiveEnergy (EEData.AE)
#define PActiveEnergy (EEData.PAE)
#define NActiveEnergy (EEData.NAE)
//#define CF2Counter (EEData.CF2)
//#define PCF2Counter (EEData.PCF2)
//#define NCF2Counter (EEData.NCF2)
#define ReactiveEnergy (EEData.RE)
#define PReactiveEnergy (EEData.PRE)
#define NReaCtiveEnergy (EEData.NRE)
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -