瑞萨的R5F104LEA(RL78/G14)属于16位单片机,支持乘法、除法指令,运算能力比较强劲。本系统中选用计算偏少的均方根算法,计算主要为乘加。经实测可在1个周波(20ms)内完成8路32点均方根计算。
//下为系统数据结构定义
/***********************************************************************************************************************
* File Name : r_cg_userdefine.h
* Version : CodeGenerator for RL78/G14 V2.00.00.07 [22 Feb 2013]
* Device(s) : R5F104LE
* Tool-Chain : CA78K0R
* Description : This file includes user definition.
* Creation Date: 2013-10-18
***********************************************************************************************************************/
#ifndef _USER_DEF_H
#define _USER_DEF_H
#define N 32 //周波采样点数
#define channel 8 //采样通道数
#define Buffer_Num 3 //缓冲区深度
#define Average_number 20 //采样结果去平均值次数,即连续20次采样结果取平均值做为系统判断依据
struct dq{
uint8_t CY_Buffer; //当前周波采样点数
uint8_t CY_channel; //当前采样通道
uint8_t CY_position; //当前采样数据存储缓冲区位置
uint8_t Ready_NewData_NO; //Ready_NewData_NO[channel]
uint8_t Calc_NewData_MARK; //有新数据需处理标志
uint8_t Calc_NewData_NO; //Sampe_Ready
uint16_t Resuit[Buffer_Num][N][channel]; //AD Result Current Current Current ... Voltage Current
uint32_t Sum[Buffer_Num][channel]; //有效值累记和
float RMS[channel]; //平均后的有效值
};
struct run{
uint32_t Frequency[channel];
uint32_t Sum[channel];
uint16_t average[channel]; //I0 I1 I2 I3 ... U In-2
uint16_t I_Protect[channel-2]; //I0 I1 I2 I3 ... U In-2
uint16_t I_Pri_Hight; //支路优先级
uint16_t ITheory; //UTheory
};
struct protect{
uint8_t NewData_Mark; //0 No data;1 New data
uint32_t Protection_Data[3]; //W Umax Umin
};
struct sys{
uint8_t type; //过载保护标志
uint8_t BF_type;
uint32_t MK; //过载门槛值
uint32_t BF_MK;
uint16_t DELY;
uint16_t BF_DELY;
uint16_t GZ_SECOND; //故障秒计时
uint16_t GZ_MS; //故障毫秒计时
uint8_t GZ;
uint16_t HF_SECOND;
uint16_t HF_MS;
uint8_t HF;
};
struct branch{
uint8_t Num;
uint8_t MS; //支路开关工作模式 0 HEAD ; 1 AUTO
uint8_t BF_MS;
uint8_t STATE; //支路开关状态 0 OFF ; 1 ON
uint8_t BF_STATE;
uint8_t Pri; //支路开关优先级标志
uint8_t BF_Pri;
uint16_t Time1[6]; //Ion
uint16_t BF_Time1[6]; //Ion分计时
uint16_t Time1_MS[6]; //Ion毫秒计时
uint8_t Time2[6]; //Ioff
uint16_t BF_Time2[6]; //Ioff分计时
uint8_t Time2_MS[6]; //Ioff毫秒计时
};
/***********************************************************************************************************************
User definitions
***********************************************************************************************************************/
/* Start user code for function. Do not edit comment generated here */
/* End user code. Do not edit comment generated here */
#endif