⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 globe.h

📁 FE42X单相防窃电电表DEMO(编译器 AQ430 AQ430 V2.0.6.5)
💻 H
字号:
/********************************************************************************
*					           杭州利尔达                                       *
*                 MSP430FE42X单相防窃电多功能电表平台                           *
*                          -----  ESP SD16实现                                  *
*                                                                               *
*                                                                               *
* 说明:本软件为杭州利尔达单相防窃电多功能电表DEMO软件                          *
*                                                                               *
*********************************************************************************/

#ifndef _GLOBE_H_
#define _GLOBE_H_


typedef unsigned char uint8;
typedef signed char int8;
typedef unsigned int  uint16;
typedef signed int  int16;
typedef unsigned long  uint32;
typedef signed long  int32;

typedef unsigned char uint8_t;
typedef signed char int8_t;
typedef unsigned int  uint16_t;
typedef signed int  int16_t;
typedef unsigned long  uint32_t;
typedef signed long  int32_t;

// LCD显示字符表
extern const unsigned char lcd_digit_table[];

struct emeter_var
{
	// 系统状态标志位
	uint16 ui_meter_status;
	// 防窃电模式状态
	uint16 ui_anti_tamperring_status;
	// 保存ESP软件版本号
	uint16 ui_firmware_version;
	// 指示显示页面
	uint8 uc_display_stage;
	// 秒计数
	uint16 ui_sec_count;
	/* 电网频率 */
	uint16 ui_main_frequency;
	/* 功率因子 */
    uint16 ui_power_factor;
	// 上次温度测量值,摄氏度
    int16 i_last_temperature;
    // 上次温度测量值,采样值
    int16 i_temperature;
	// 温度采样偏置
	int16 i_temperature_offset;
	// 电流有效值
	uint16 ui_current_IRMS;
	/* 电压有效值 */
	uint16 ui_voltage_V1RMS;
	// 累计有用功电能
	float f_total_energy;
	// 上次测量得到的各项电能
	uint32 ul_total_power;
	
	uint32 ul_act_power_counter;
	uint32 ul_act_power1;
	uint32 ul_act_power2;
	uint32 ul_react_power;
	uint32 ul_app_power;
	float f_re_total_power;
	
	/* 校表参数缓存 */
	uint8 ucFlashOperated[2];
	float f_Cz1;  // 电路常数
	float f_Cz2;  // 电路常数
	uint16 ui_GainCorr1;
	uint16 ui_GainCorr2;
	int32 l_PowerOffset1;
	int32 l_PowerOffset2;
	float f_PhaseCorr1;
	float f_PhaseCorr2;
	uint16 ui_SD16_CurrentCorr1;
	uint16 ui_SD16_CurrentCorr2;
	uint16 ui_SD16_VoltageCorr1;
	uint16 ul_TempSampleOffset;
	
	uint8 ucCalibrationMode;
	uint8 ucCalibrationOption;
	
	uint8 uc_pout_hc595;
	
	uint8 uc_restart_esp_delay;
	
	uint8 uc_lcd_remaining_times;
	uint8 uc_switch_delay_counter;
	
	uint8 display_stage;
	
};
extern struct emeter_var emeter;

union signed_long_word
{
      int32 l;
      uint16 w[2];
};
extern union signed_long_word ds;

extern uint32 ul_total_power_infact;

extern uint16 ui_step_counter;

struct current_sensor_parms_s
{
	
	uint16 V_rms;
    uint16 I_rms;
	/* Channel's DC estimates, accumulated powers, and the logged
	   accumulated power from the last measurement cycle. */
    int32_t I_dc_estimate;
    int16_t P_accum[3];
    int16_t P_accum_logged[3];
    /*! \brief The accumulating dot product of I.I */
    int16_t I_sq_accum[3];
    /*! \brief The latest logged dot product of I.I */
    int16_t I_sq_accum_logged[3];
    /*! \brief The current number of accumulated samples. */
    int16_t sample_count;
    /*! \brief The latest logged number of accumulated samples. */
    int16_t sample_count_logged;
    /*! \brief The beta of the FIR/interpolator used for phase correction. */
    int16_t fir_beta;
    /*! \brief The step into the history data used for phase correction. */
    int16_t fir_step;
    int16_t fir_gain;
    /*! \brief History of the current samples, for use when making large phase corrections */
    int16_t I_history[2];
    
    int8_t I_endstops;
};

struct phase_parms_s
{

    uint16_t V_rms;
    uint16_t I_rms;
	/* Voltage channel DC estimates. We need separate estimates for normal
       and limp mode, as in limp mode we use a different ADC reference. */
    int32_t V_dc_estimate[2];
	int16_t V_history[4];
	/* 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 V_sq_accum_logged[3];

	struct current_sensor_parms_s current;
	struct current_sensor_parms_s neutral;
	/* The number of samples of mains waveform cycles accumulated so far during the
       current measurement cycle. The logged value from the last measurement cycle. */
    int16_t sample_count;
    int16_t sample_count_logged;

    uint16_t status;

	/* Values used in determining ADC overload, for each of the ADCs.
	   The ones for detecting overload of the high gain current ADCs
	   are always needed. The others are optional. */
	int8_t V_endstops;
	int8_t V_history_index;

};
extern struct phase_parms_s *phase;

/****************************************************************
* 定义显示页面,显示顺序为:                                    *                  
* P1 	电流通道I1平均有功功率                                  *
* P2 	电流通道I2平均有功功率                                  *
* C		电流有效值IRMS                                          *
* U		电压有效值VRMS                                          *
* F     电网频率                                                *
* PF	功率因素                                                *
* rP	平均无功功率                                            *
* AP	平均视在功率                                            *
*****************************************************************/
enum
{
    DISPLAY_STAGE_ACT_ENERGY_1 = 1, // P1
    DISPLAY_STAGE_ACT_ENERGY_2,     // P2
    DISPLAY_STAGE_CURRENT,          // C
	DISPLAY_STAGE_VOLTAGE,          // U
	DISPLAY_STAGE_FREQUENCY,        // F
	DISPLAY_STAGE_POWERFACTOR,      // PF
	DISPLAY_STAGE_REACT_ENERGY,     // rP
	DISPLAY_STAGE_APP_ENERGY,       // AP
	DISPLAY_STAGE_TEMPERATURE,      // t
	DISPLAY_STAGE_TIME,				// 时间
	DISPLAY_STAGE_DATE,				// 日期
	
	DISPLAY_STAGE_TEST1,
	DISPLAY_STAGE_TEST2,
	DISPLAY_STAGE_TEST3,
	DISPLAY_STAGE_TEST4,
	DISPLAY_STAGE_TEST5,
	DISPLAY_STAGE_TEST6,
	DISPLAY_STAGE_TEST7,
	DISPLAY_STAGE_TEST8,
	DISPLAY_STAGE_TEST9,				
	
    DISPLAY_STAGE_LAST
};

// meter_status;
#define SKIP_A_SECOND       		BIT0		// 时钟跳过一秒标志
#define MAIN_VOLTAGE_DOWN   		BIT1		// 电网电压无标志,电表将关闭ESP		
#define NEW_ENERGY_READY    		BIT2		// 标志新的能量已经准备好
#define KEY_PRESS_DELAY     		BIT3		// 标志按键延时状态
#define REQUIRE_MODIFY_ESP_PARAM    BIT4        // 标志需要修改ESP参数寄存器,需要先让ESP进入IDLE状态
#define IN_TEMPERATURE_MEASURE	    BIT5        // 标志正在一次温度测量状态  
#define V1_CZ_TRAILING				BIT6
#define ENRDY_INT_OCCUR				BIT7        /* ESP新的能量准备好中断发生标志 */
#define REQUIRE_RTC_CORRENT 		BIT8        /* 要求温度补偿 */
#define REQUIRE_FLASH_OP    		BIT9
#define REQUIRE_LCD_UPDATE  		BITA
#define ENSPER_INT_OCCUR			BITB
#define BT_1SEC_INT_OCCUR			BITC

// ui_anti_tamperring_status
#define IN_SD16_MEASURE_MODE		BIT0
#define IN_ESP_MEASURE_MODE			BIT1
#define IN_ONLY_RTC_MODE			BIT2
#define EXTERN_VOLTAGE_SENSOR		BIT3
#define SD16_MEASURE_NEW_LOG		BIT4


// 实时时钟结构
struct  rtc_s
{
	uint8 second;
	uint8 minute;
	uint8 hour;
	uint8 day;
	uint8 week;
	uint8 month;
	uint8 year;
	uint8 sumcheck;
};
extern struct rtc_s rtc;	

extern uint32 ul_actensper1;
extern uint32 ul_actensper2;

#endif



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -