电源控制说明:
VCC: 由电网电源,6v电池和3.6V电池汇流提供
供mcu等电网掉电后需要工作的器件电源使用(此处仅用作mcu电源)。
VSWO: 由MCU的VD(电网,6V电池,3.6V电池汇流)与mcu的VBAT(3.6V电池)汇流提供
供mcu的reset,8025t电源,按键等需要低功耗唤醒等位置使用。
1.RESET电路
2.8025T电源
3. 按键唤醒部分
4.上盖、端盖检测部分
VCC_OP: 电网电源 (电池不供电)
供停电后不需供电的外围电路:
1 通讯部分: 485 、 载波、无线等
2 指示灯:
3 液晶背光:
4 光耦:
5 继电器部分:
6.esam可控电源。
7.红外发射在电网电源在线时使用vcc_op。
VD:由电网电源和6V电池汇流而成。供给DVCC,可控的红外电源VCC_IR使用。
DVCC: 由VD生成(选配VCC一般不采用),ctrl_dvcc=1时,dvcc=3.3V;ctrl_dvcc=0时,dvcc关断.
1. 计量电源
2. flash电源
需要进行计量/保存flash时打开。上电后必须使能ctrl_dvcc;掉电后在全失压检测时打开ctrl_dvcc一次
VCC_IR: 红外收发管的电源,由ctrl_WAKE控制打开关闭.
打开条件: 红外唤醒
AD_3.6V: 3.6V电池提供给mcu的Vbat。
VDD:电网电源通过稳压得到通常=5.3V
6V_5V:6V电池通过LDO后的电源,通常=5.0V。
电路原理图如下:
单片机源程序如下:
- #include "RN7302_Demo.h"
- __no_init sDl645StruDataComm_TypeDef Dl645RN7302DataComm;
- __no_init sDl645FrontTmp_TypeDef Dl645FrontTmp;
- __no_init sDl645Front_TypeDef Dl645Front;
- __no_init sDl645Eg_TypeDef Dl645Eg;
- __no_init sDl645FirmParaFile_TypeDef Dl645FirmPara;
-
- //底层函数
- u8 fnSpi2_ReadByte(void)
- {
- u8 i,temp=0;
- for(i=0;i<8;i++)
- {
- temp<<=1;
- PinWrite_ADSCLK(1);
- PinWrite_ADSCLK(1);
- fnDelay2us();
- fnDelay2us();
- fnDelay2us();
- fnDelay2us();
- PinWrite_ADSCLK(0);
- PinWrite_ADSCLK(0);
- fnDelay2us();
- fnDelay2us();
- fnDelay2us();
- fnDelay2us();
- if (PinRead_ADSDI()){temp=temp+0x1;}
- fnDelay2us();
- fnDelay2us();
- fnDelay2us();
- }
- return temp;
- }
- //////////////////////////////////////////////////////////////////////////
- void fnSpi2_WriteByte(u8 Dat)
- {
- u8 i;
- for(i=0;i<8;i++)
- {
- PinWrite_ADSCLK(1);
- PinWrite_ADSCLK(1);
- fnDelay2us();
- fnDelay2us();
- if(Dat & 0x80)
- {
- PinWrite_ADSDO(1);
- PinWrite_ADSDO(1);
- fnDelay2us();
- fnDelay2us();
- fnDelay2us();
- }
- else
- {
- PinWrite_ADSDO(0);
- PinWrite_ADSDO(0);
- fnDelay2us();
- fnDelay2us();
- fnDelay2us();
- }
- PinWrite_ADSCLK(0);
- PinWrite_ADSCLK(0);
- fnDelay2us();
- fnDelay2us();
- fnDelay2us();
- Dat <<= 1;
- }
- PinWrite_ADSDO(1);
- PinWrite_ADSDO(1);
- fnDelay2us();
- fnDelay2us();
- fnDelay2us();
- }
- //存储器写入函数
- ErrorStatus fnMemory_Write(u32 Dst , u8 *Src , u32 DatLen)
- {
- ErrorStatus err;
- if( (FM24C_START_ADDR <= Dst) &&
- ( (Dst + DatLen) < (FM24C_START_ADDR + FM24C_SIZE) ) )
- {
- #if !DL645SOFT_DEBUG
- err = fnFM24CXX_Write(Dst- FM24C_START_ADDR , Src , DatLen , 3);
- if(err==ERROR) Dl645Bkgrd.PubData.EventErr[5]=BKGRD_EVENTERR_INTERMEMORY;
- else Dl645Bkgrd.PubData.EventErr[5]=BKGRD_EVENTERR_OK;
- #endif
- }
- else if( (AT45DB_START_ADDR <= Dst) &&
- ( (Dst + DatLen) < (AT45DB_START_ADDR + AT45DB_SIZE) ) )
- {
- #if !DL645SOFT_DEBUG
- err = fnAT45DBXX_Write( Dst - AT45DB_START_ADDR , Src , DatLen , 3);
- if(err==ERROR) Dl645Bkgrd.PubData.EventErr[5]=BKGRD_EVENTERR_INTERMEMORY;
- else Dl645Bkgrd.PubData.EventErr[5]=BKGRD_EVENTERR_OK;
- #endif
- }
- else
- {
- err = ERROR;
- Dl645Bkgrd.PubData.EventErr[5]=BKGRD_EVENTERR_INTERMEMORY;
- }
- return(err);
- }
- //存储器读取函数
- ErrorStatus fnMemory_Read(u8 *Dst , u32 Src , u32 DatLen)
- {
- ErrorStatus err;
- if( (FM24C_START_ADDR <= Src) &&
- ( (Src + DatLen) < (FM24C_START_ADDR + FM24C_SIZE) ) )
- {
- #if !DL645SOFT_DEBUG
- err = fnFM24CXX_Read(Dst , Src - FM24C_START_ADDR , DatLen , 3);
- if(err==ERROR) Dl645Bkgrd.PubData.EventErr[5]=BKGRD_EVENTERR_INTERMEMORY;
- else Dl645Bkgrd.PubData.EventErr[5]=BKGRD_EVENTERR_OK;
- #endif
- }
- else if( (AT45DB_START_ADDR <= Src) &&
- ( (Src + DatLen) < (AT45DB_START_ADDR + AT45DB_SIZE) ) )
- {
- #if !DL645SOFT_DEBUG
- err = fnAT45DBXX_Read(Dst , Src - AT45DB_START_ADDR , DatLen , 3);
- if(err==ERROR) Dl645Bkgrd.PubData.EventErr[5]=BKGRD_EVENTERR_INTERMEMORY;
- else Dl645Bkgrd.PubData.EventErr[5]=BKGRD_EVENTERR_OK;
- #endif
- }
- else
- {
- err = ERROR;
- }
- return(err);
- }
-
- // 文件操作函数
- ErrorStatus fnDl645File_Read(u8 FileId , u32 OffAddr , void *Dst , u32 Len)
- {
- if(FileId >= Dl645FileId_Max) return(ERROR);
- if( (OffAddr + Len) > Dl645FileInfo[FileId].Len) return(ERROR);
- return(fnMemory_Read(Dst , Dl645FileInfo[FileId].StartAddr + OffAddr , Len) );
- }
- ErrorStatus fnDl645File_Write(u8 FileId , u32 OffAddr , void *Src , u32 Len)
- {
- if(FileId >= Dl645FileId_Max) return(ERROR);
- if( (OffAddr + Len) > Dl645FileInfo[FileId].Len) return(ERROR);
- return(fnMemory_Write(Dl645FileInfo[FileId].StartAddr + OffAddr , Src , Len) );
- }
- ErrorStatus fnRN7302_Write(u16 wReg,u8 *pBuf,u8 DatLen)
- {
- u8 i,temp,chksum,Repeat;
- ErrorStatus err = SUCCESS;
- if( (DatLen == 0) || (DatLen > 4) ) return(ERROR);
- for( Repeat =3; Repeat != 0 ; Repeat--)
- {
- PinWrite_ADCS(0);
- NOP();
- temp = (u8)(wReg & 0x00ff);
- chksum = temp;
- fnSpi2_WriteByte( temp); //first write hight Addr
- temp = (((u8)(wReg >> 4)) & 0xf0) + 0x80;
- chksum += temp;
- fnSpi2_WriteByte( temp);
-
- for(i = DatLen; i > 0;i-- )
- {
- fnSpi2_WriteByte(pBuf[i-1]); // first write high data
- chksum +=pBuf[i-1];
- }
- chksum = ~chksum;
- fnSpi2_WriteByte(chksum);
- // PinWrite_ADCS(1);
- // NOP();
- //读WData寄存器检查-----------------------
- // PinWrite_ADCS(0);
- // NOP();
-
- fnSpi2_WriteByte( 0x8D);
- chksum = 0x8D;
- temp = ( (u8)(0x018D >> 4) & 0xf0);
- fnSpi2_WriteByte( temp );
- chksum += temp;
- for(i = 3 ; i > 0 ; i--)
- {
- temp = fnSpi2_ReadByte();
- if(DatLen >= i)
- {
- if(temp != pBuf[i - 1])
- {
- err = ERROR;
- break;
- }
- }
- chksum += temp;
- }
- if(err == SUCCESS)
- {
- chksum = ~chksum;
- temp = fnSpi2_ReadByte();
- if(temp != chksum) err = ERROR;
- }
-
- PinWrite_ADCS(1);
- if(err == SUCCESS) break;
- fnDelay2us();
- fnDelay2us();
- }
- PinWrite_ADSDO(1);
- PinWrite_ADSCLK(1);
- return(err);
- }
- ErrorStatus fnRN7302_Read(u16 wReg,u8 *pBuf,u8 DatLen)
- {
- u8 i,temp,chksum,Repeat;
- ErrorStatus err = SUCCESS;
- if(DatLen == 0) return(ERROR);
- for( Repeat=3; Repeat != 0 ; Repeat--)
- {
- PinWrite_ADCS(0);
- fnDelay2us();
- temp = (u8)(wReg & 0x00ff);
- chksum = temp;
- fnSpi2_WriteByte( temp); //first write hight Addr
- temp = ((u8)(wReg >> 4))& 0xf0;
- chksum += temp;
- fnSpi2_WriteByte( temp);
-
- for(i = DatLen; i > 0;i--)
- {
- pBuf[i-1] = fnSpi2_ReadByte();
- chksum += pBuf[i-1];
- }
- chksum = ~chksum;
- if(fnSpi2_ReadByte()!=chksum) err = ERROR;
- // PinWrite_ADCS(1);
- //---读RData寄存器检查------------------------------------
- if(err != SUCCESS) continue;
-
- fnSpi2_WriteByte( 0x8c);//读上一次SPI 读出的数据
- chksum = 0x8c;
- temp = ( (u8)(0x018C >> 4) & 0xf0);
- fnSpi2_WriteByte( temp );
- chksum += temp;
- for(i = 4 ; i > 0 ; i--)
- {
- temp = fnSpi2_ReadByte();
- if(DatLen >= i)
- {
- if(temp != pBuf[i - 1])
- {
- err = ERROR;
- break;
- }
- }
- chksum += temp;
- }
- if(err == SUCCESS)
- {
- chksum = ~chksum;
- temp = fnSpi2_ReadByte();
- if(temp != chksum) err = ERROR;
- }
-
- PinWrite_ADCS(1);
- if(err == SUCCESS) break;
- fnDelay2us();
- fnDelay2us();
- }
- PinWrite_ADCS(1);
- PinWrite_ADSDO(1);
- PinWrite_ADSCLK(1);
- return(err);
- }
- void fnRN7302_Init(void)
- {
- Dl645RN7302DataComm.ucTemp8 = 0xe5; // 写使能位
- fnRN7302_Write(0x0180,Dl645RN7302DataComm.ucTempBuf,1);
-
- Dl645RN7302DataComm.ucTemp8 = 0xA2; // 切换到EMM模式
- fnRN7302_Write(WMSW,Dl645RN7302DataComm.ucTempBuf,1);
-
- Dl645RN7302DataComm.ucTemp8 = 0xfa; // 写使能位
- fnRN7302_Write(0x0182,Dl645RN7302DataComm.ucTempBuf,1);
- SystemDelay(10);
- Dl645RN7302DataComm.ucTemp8 = 0xe5; // 写使能位
- fnRN7302_Write(0x0180,Dl645RN7302DataComm.ucTempBuf,1);
-
- Dl645RN7302DataComm.ucTemp8 = 0xA2; // 切换到EMM模式
- fnRN7302_Write(WMSW,Dl645RN7302DataComm.ucTempBuf,1);
-
- Dl645RN7302DataComm.ucTempBuf[0] = 0x77; // 计量控制位
- Dl645RN7302DataComm.ucTempBuf[1] = 0x77;
- Dl645RN7302DataComm.ucTempBuf[2] = 0x77;
- fnRN7302_Write(0x0162,Dl645RN7302DataComm.ucTempBuf,3);
-
- Dl645RN7302DataComm.wTemp16 = Dl645FirmPara.HFConst1;
- fnRN7302_Write(HFCONST1,Dl645RN7302DataComm.ucTempBuf,2);
-
- // 电压增益初始化
- fnRN7302_Write(GSUA,(u8 *)&Dl645FirmPara.VGain[0],2);
- fnRN7302_Write(GSUB,(u8 *)&Dl645FirmPara.VGain[1],2);
- fnRN7302_Write(GSUC,(u8 *)&Dl645FirmPara.VGain[2],2);
-
- // 电流增益初始化
- fnRN7302_Write(GSIA,(u8 *)&Dl645FirmPara.IGain[0],2);
- fnRN7302_Write(GSIB,(u8 *)&Dl645FirmPara.IGain[1],2);
- fnRN7302_Write(GSIC,(u8 *)&Dl645FirmPara.IGain[2],2);
- fnRN7302_Write(GSIN,(u8 *)&Dl645FirmPara.IGain[3],2);
-
- // 通道相位校正
- fnRN7302_Write(PRTH1L,(u8 *)&Dl645FirmPara.PRth[0],2);
- fnRN7302_Write(PRTH1H,(u8 *)&Dl645FirmPara.PRth[1],2);
- fnRN7302_Write(PRTH2L,(u8 *)&Dl645FirmPara.PRth[2],2);
- fnRN7302_Write(PRTH2H,(u8 *)&Dl645FirmPara.PRth[3],2); // 通道相位分段参数
-
-
- // 通道相位校正
- fnRN7302_Write(PHSIA,(u8 *)&Dl645FirmPara.PHSI[0],3);
- fnRN7302_Write(PHSIB,(u8 *)&Dl645FirmPara.PHSI[1],3);
- fnRN7302_Write(PHSIC,(u8 *)&Dl645FirmPara.PHSI[2],3);
-
- fnRN7302_Write(PA_PHS,(u8 *)&Dl645FirmPara.P_PHS[0],2);
- fnRN7302_Write(PB_PHS,(u8 *)&Dl645FirmPara.P_PHS[1],2);
- fnRN7302_Write(PC_PHS,(u8 *)&Dl645FirmPara.P_PHS[2],2);
-
- fnRN7302_Write(GPA,(u8 *)&Dl645FirmPara.PGain[0],2);
- fnRN7302_Write(GPB,(u8 *)&Dl645FirmPara.PGain[1],2);
- fnRN7302_Write(GPC,(u8 *)&Dl645FirmPara.PGain[2],2);
-
- fnRN7302_Write(GQA,(u8 *)&Dl645FirmPara.PGain[0],2);
- fnRN7302_Write(GQB,(u8 *)&Dl645FirmPara.PGain[1],2);
- fnRN7302_Write(GQC,(u8 *)&Dl645FirmPara.PGain[2],2);
-
- fnRN7302_Write(GSA,(u8 *)&Dl645FirmPara.PGain[0],2);
- fnRN7302_Write(GSB,(u8 *)&Dl645FirmPara.PGain[1],2);
- fnRN7302_Write(GSC,(u8 *)&Dl645FirmPara.PGain[2],2);
-
- // 通道功率OFFSET校正
- fnRN7302_Write(PA_OS,(u8 *)&Dl645FirmPara.UI_Offset[0],2);
- fnRN7302_Write(PB_OS,(u8 *)&Dl645FirmPara.UI_Offset[1],2);
- fnRN7302_Write(PC_OS,(u8 *)&Dl645FirmPara.UI_Offset[2],2);
-
- fnRN7302_Write(IStart_PS,(u8 *)&Dl645FirmPara.NOLOAD,2);
- fnRN7302_Write(ZXOT,(u8 *)&Dl645FirmPara.ZEROSTAR,2);
-
- Dl645RN7302DataComm.ucTemp8 = 0x42;
- fnRN7302_Write(0x0184,Dl645RN7302DataComm.ucTempBuf,1);
- Dl645RN7302DataComm.ucTemp8 = 0;
- fnRN7302_Write(0x0185,Dl645RN7302DataComm.ucTempBuf,1);
- Dl645RN7302DataComm.ucTemp8 = 0;
- fnRN7302_Write(0x0184,Dl645RN7302DataComm.ucTempBuf,1);
-
- Dl645RN7302DataComm.ucTempBuf[0] = 0x10;
- Dl645RN7302DataComm.ucTempBuf[1] = 0x32;
- Dl645RN7302DataComm.ucTempBuf[2] = 0x07;
- fnRN7302_Write(CFCFG,Dl645RN7302DataComm.ucTempBuf,3);
- Dl645RN7302DataComm.ucTempBuf[0] = 0x40; // 计量控制位 默认值 400000
- Dl645RN7302DataComm.ucTempBuf[1] = 0x00;
- Dl645RN7302DataComm.ucTempBuf[2] = 0x00;
- fnRN7302_Write(0x0161,Dl645RN7302DataComm.ucTempBuf,3);
-
-
- Dl645RN7302DataComm.ucTemp8 = 0x10; // 清空采样数据缓存区
- fnRN7302_Write(0x0163,Dl645RN7302DataComm.ucTempBuf,1);
-
- Dl645RN7302DataComm.ucTemp8 = 0xDC; // 写保护
- fnRN7302_Write(0x0180,Dl645RN7302DataComm.ucTempBuf,1);
- Dl645FirmPara.FractionP=0x04;
- Dl645FirmPara.FractionI=0x04;
- Dl645FirmPara.FractionU=0x02;
- }
- void fnDl645Front_Exec(void)
- {
- //读电压电流
- for(i=0;i<4;i++)
- {
- Dl645FrontTmp.UI[i] = 0 ;
- fnRN7302_Read( 0x000b+i , (u8 *)&Dl645FrontTmp.UI[i] , 4 ) ;
-
- }
- for(i=0;i<3;i++)
- {
- Dl645FrontTmp.UI[i+4] = 0 ;
- fnRN7302_Read( 0x0007+i , (u8 *)&Dl645FrontTmp.UI[i+4] , 4 ) ;
-
- }
-
- //读功率
- for(i=0;i<12;i++)
- {
- Dl645FrontTmp.Pw[i] = 0 ;
- fnRN7302_Read(0x0014+i,(u8 *)&Dl645FrontTmp.Pw[i],4);
- if((Dl645FrontTmp.Pw[i]<30)&&(Dl645FrontTmp.Pw[i]>-30))
- Dl645FrontTmp.Pw[i]=0;
- }
-
- //读功率方向
- fnRN7302_Read(PQSign,(u8 *)&Dl645FrontTmp.PDirect,2);
-
- //读电压电流角度值
- for(i=0;i<5;i++)
- {
- Dl645FrontTmp.Angle[i] = 0 ;
- fnRN7302_Read(YUB+i,(u8 *)&Dl645FrontTmp.Angle[i],3);
- Dl645Front.PubData.Angle[i] = fnHexToBcd_u16((u16)(((float)Dl645FrontTmp.Angle[i]/16777216)*3600));
- }
-
- //功率计算
- for(j=0;j<3;j++)
- {
-
- for(i=0;i<3;i++)
- {
- Dl645Front.PubData.Pw[j*4+i+1]=fnDFConver_Hex32ToDF09((s32)((Dl645FrontTmp.Pw[j*4+i])/((Dl645FirmPara.PRmsConst))));//计算{Pa Pb Pc}、{Qa Qb Qc}、{Sa Sb Sc}
- }
- }
- Tempw = (s32)((Dl645FrontTmp.Pw[3])/((Dl645FirmPara.PRmsConst))) ;
- Dl645Front.PubData.Pw[0]=fnDFConver_Hex32ToDF09(Tempw);
- Tempq = (s32)((Dl645FrontTmp.Pw[7])/((Dl645FirmPara.PRmsConst))) ;
- Dl645Front.PubData.Pw[4]=fnDFConver_Hex32ToDF09(Tempq);
- // 计算总视在功率
- Tempws = (s32)sqrt((float)Tempw*(float)Tempw+(float)Tempq*(float)Tempq);
- Dl645Front.PubData.Pw[8] = fnDFConver_Hex32ToDF09(Tempws);//计算P、Q
-
- //功率因数计算
- //总功率因数
- Dl645Front.PubData.Pf[0]=fnDFConver_Bcd16To16((s16)((1000*(double)(Tempw))/(Tempws)));
-
- //电压电流计算
- for(i=0;i<3;i++)
- {
- Dl645Front.PubData.U[i]=0x7fff&(fnDFConver_Bcd16To16((s16)(Dl645FrontTmp.UI[i+4]/(10*(Dl645FirmPara.VRmsConst))))); //电压
- }
-
-
- TempIa = (s32)(Dl645FrontTmp.UI[0]/(Dl645FirmPara.IRmsConst));
- TempIb = (s32)(Dl645FrontTmp.UI[1]/(Dl645FirmPara.IRmsConst));
- TempIc = (s32)(Dl645FrontTmp.UI[2]/(Dl645FirmPara.IRmsConst));
- Dl645Front.PubData.I[0] = fnDFConver_Bcd32To32(TempIa);
- Dl645Front.PubData.I[1] = fnDFConver_Bcd32To32(TempIb);
- Dl645Front.PubData.I[2] = fnDFConver_Bcd32To32(TempIc);
- Dl645Front.PubData.I[3] = fnDFConver_Bcd32To32((s32)(Dl645FrontTmp.UI[3]/(Dl645FirmPara.IRmsConst)));
- if(Dl645FrontTmp.PDirect&0x0001) Dl645Front.PubData.I[0] |= 0x80000000;
- if(Dl645FrontTmp.PDirect&0x0002) Dl645Front.PubData.I[1] |= 0x80000000;
- if(Dl645FrontTmp.PDirect&0x0004) Dl645Front.PubData.I[2] |= 0x80000000;
-
- //频率计算
- if((Dl645FrontTmp.Frequency>1638400)||(Dl645FrontTmp.Frequency<1092266)) //when 50HZ is 5120 ;+- 20% frequence is 6144 and 4096
- Dl645FrontTmp.Frequency=1310720;
- Dl645Front.PubData.Frequency=fnHexToBcd_u16((u16)(65536000/(Dl645FrontTmp.Frequency/100)));
-
- //转换功率方向
- Dl645Front.PubData.PDirect = ( (Dl645FrontTmp.PDirect << 1) & 0xee) | ( (Dl645FrontTmp.PDirect >> 3) & 0x11);
-
- if(Dl645Bkgrd.PriPara.WireMode==0x01) //三相三线
- {
- Dl645Front.PubData.Angle[3]=0;
- Dl645Front.PubData.Angle[6]=0;
- }
-
-
- //从RN8302读出的即为脉冲数//{P,Q,Ps},{Pa,Qa,Psa},{Pb,Qb,Psb},{Pc,Qc,Psc}{Fp,Fq}{Fpa,Fqa}{Fpb,Fqb}{Fpc,Fqc}
- /*读电能寄存器*/
- for(i=0;i<3;i++)
- {
- Dl645FrontTmp.Pulse[(i+1)*3] = 0;
- fnRN7302_Read(EPA+i,(u8 *)&Dl645FrontTmp.Pulse[(i+1)*3],3); //有功
- Dl645FrontTmp.Pulse[(i+1)*3+1] = 0;
- fnRN7302_Read(EQA+i,(u8 *)&Dl645FrontTmp.Pulse[(i+1)*3+1],3); //无功
- Dl645FrontTmp.Pulse[(i+1)*3+2] = 0;
- fnRN7302_Read(ESA+i,(u8 *)&Dl645FrontTmp.Pulse[(i+1)*3+2],3); //视在有功
- Dl645FrontTmp.Pulse[14+i*2] =0;
- fnRN7302_Read(FEPA+i,(u8 *)&Dl645FrontTmp.Pulse[14+i*2],3); //基波有功
- Dl645FrontTmp.Pulse[15+i*2] = 0;
- fnRN7302_Read(FEQA+i,(u8 *)&Dl645FrontTmp.Pulse[15+i*2],3); //基波无功
- }
- Dl645FrontTmp.Pulse[0] = 0;
- fnRN7302_Read(EPT,(u8 *)&Dl645FrontTmp.Pulse[0],3); //总有功
- Dl645FrontTmp.Pulse[1] = 0;
- fnRN7302_Read(EQT,(u8 *)&Dl645FrontTmp.Pulse[1],3); //总无功
- Dl645FrontTmp.Pulse[2] = 0;
- fnRN7302_Read(EST,(u8 *)&Dl645FrontTmp.Pulse[2],3); //总视在
- Dl645FrontTmp.Pulse[12] =0;
- fnRN7302_Read(FEPT,(u8 *)&Dl645FrontTmp.Pulse[12],3); //总基波有功
- Dl645FrontTmp.Pulse[13] =0;
- fnRN7302_Read(FEQT,(u8 *)&Dl645FrontTmp.Pulse[13],3); //总基波无功
-
- for(i=0;i<20;i++)//电能高频脉冲转换成低频脉冲
- {
- Dl645FrontTmp.Pulse_Eg[i]+=Dl645FrontTmp.Pulse[i];
- }
- }
- void fnDl645Energy_Exec(void)
- {
- u8 Ep[20];
- if( !(Dl645FrontTmp.Pulse_Eg[0] | Dl645FrontTmp.Pulse_Eg[1] | Dl645FrontTmp.Pulse_Eg[2] | Dl645FrontTmp.Pulse_Eg[3] |
- Dl645FrontTmp.Pulse_Eg[4] | Dl645FrontTmp.Pulse_Eg[5] | Dl645FrontTmp.Pulse_Eg[6] | Dl645FrontTmp.Pulse_Eg[7] |
- Dl645FrontTmp.Pulse_Eg[8] | Dl645FrontTmp.Pulse_Eg[9] | Dl645FrontTmp.Pulse_Eg[10] | Dl645FrontTmp.Pulse_Eg[11] |
- Dl645Eg.PubPara.fMinute) )
- {
- return;
- }
- //Dl645Eg.PubPara.PPlsDeltaE为脉冲数,如脉冲数为800,因电能小数为2位,故此值为8
- for(i = 0 ; i < 12 ; i++)
- {
- Ep[i] = 0;
-
- if(Dl645FrontTmp.Pulse_Eg[i])
- {
- Dl645Eg.PriData.PieceEg[i] += Dl645FrontTmp.Pulse_Eg[i];
- Dl645FrontTmp.Pulse_Eg[i] = 0;
-
- switch(i % 3)
- {
- case 0:
- if(Dl645Eg.PubPara.PPlsDeltaE == 0) break;
- while (Dl645Eg.PriData.PieceEg[i] >= Dl645Eg.PubPara.PPlsDeltaE)//需按电能小数位数进行计算
- {
- Ep[i]++;
- Dl645Eg.PriData.PieceEg[i] -= Dl645Eg.PubPara.PPlsDeltaE;
- }
- break;
- case 1:
- if(Dl645Eg.PubPara.QPlsDeltaE == 0) break;
- while (Dl645Eg.PriData.PieceEg[i] >= Dl645Eg.PubPara.QPlsDeltaE)//需按电能小数位数进行计算
- {
- Ep[i]++;
- Dl645Eg.PriData.PieceEg[i] -= Dl645Eg.PubPara.QPlsDeltaE;
- }
- break;
- default:
- if(Dl645Eg.PubPara.PsPlsDeltaE == 0) break;
- while (Dl645Eg.PriData.PieceEg[i] >= Dl645Eg.PubPara.PsPlsDeltaE)//需按电能小数位数进行计算
- {
- Ep[i]++;
- Dl645Eg.PriData.PieceEg[i] -= Dl645Eg.PubPara.PsPlsDeltaE;
- }
- break;
- }
- }
- }
- for(i = 0 ; i < 8 ; i++)
- {
- Ep[i+12] = 0;
-
- if(Dl645FrontTmp.Pulse_Eg[i+12])
- {
- Dl645Eg.PriData.PieceEg[i+12] += Dl645FrontTmp.Pulse_Eg[i+12];
- Dl645FrontTmp.Pulse_Eg[i+12] = 0;
-
- switch((i+12) % 2)
- {
- case 0:
- if(Dl645Eg.PubPara.PPlsDeltaE == 0) break;
- while (Dl645Eg.PriData.PieceEg[i+12] >= Dl645Eg.PubPara.PPlsDeltaE)//需按电能小数位数进行计算
- {
- Ep[i+12]++;
- Dl645Eg.PriData.PieceEg[i+12] -= Dl645Eg.PubPara.PPlsDeltaE;
- }
- break;
- default :
- if(Dl645Eg.PubPara.QPlsDeltaE == 0) break;
- while (Dl645Eg.PriData.PieceEg[i+12] >= Dl645Eg.PubPara.QPlsDeltaE)//需按电能小数位数进行计算
- {
- Ep[i+12]++;
- Dl645Eg.PriData.PieceEg[i+12] -= Dl645Eg.PubPara.QPlsDeltaE;
- }
- break;
- }
- }
- }
- }
- // RxFrm为通讯数据指针,指到07协议的第1个68数据,为sFrmDl645B_TypeDef类型指针
- //校表进行增益校准和相位校准,可选择进行相位分段校准
- // 校表部分程序
- eDL645B_ErrInfo_TypeDef fnDl645_PutParaVar(sFrmDl645B_TypeDef *RxFrm)
- {
- u8 i,j,k;
- u32 DITemp=0x0;
- u8 UnConst[6],InConst[6],ImaxConst[6];
- u16 nItem,tempconst,tempub,tempib;
- u16 temphfconst;
- u32 tempus,tempis;
- sDF10 ConstE;
- ErrorStatus err;
- u16 tempuc=0,tempud=0;
- u32 tempic=0,tempid=0;
- float ADErr;
- u32 temppw[2];
- i=RxFrm->UDat.DI3;
- RxFrm->UDat.DI3=0;
- memcpy(&DITemp , &RxFrm->UDat.DI0 , 4);
- RxFrm->UDat.DI3=i;
-
- if((DITemp==0xFE0001)||(DITemp==0xFE0002)||(DITemp==0xFE0003))
- {
- if(RxFrm->Len != (12 + 5*sizeof(u16) ) ) return(DL645B_ERRINFO_DATA);
- fnDl645File_Write(Dl645FileId_GeneralPara , Dl645FileItemInfoOffAddr_GeneralPara_OutputPara + 16 + (5*sizeof(u16)) * (RxFrm->UDat.DI0 - 1) , &RxFrm->UDat.Dat[8] , 5*sizeof(u16) );
- memset(&Dl645Output.PriPara,0,sizeof(Dl645Output.PriPara) - 2);
- return(DL645B_ERRINFO_OK);
- }
- if(DITemp==0x00f91201)
- {
- if((RxFrm->UDat.Dat[0] == 0x03)&&(RxFrm->UDat.Dat[1] == 0x43)&&(RxFrm->UDat.Dat[2] == 0x56)&&(RxFrm->UDat.Dat[3] == 0x98)) ;
- else return(DL645B_ERRINFO_PSW);
- }
- else if(DITemp==0x001503) ;
- else
- {
- if(!(Dl645Bkgrd.PubData.MtSta.MtSta3.StaBit.PrgEnable) ) return(DL645B_ERRINFO_PSW);
- err = fnDl645Secret_Verify(0x04 , RxFrm->UDat.Dat[0] , &RxFrm->UDat.Dat[1]);
- if(err != SUCCESS) return(DL645B_ERRINFO_PSW);
- }
- switch(DITemp)
- {
- case 0x00f81000: //电流电压功率初校,HFCONST等参数设置
- if(RxFrm->Len != (12+48)) return(DL645B_ERRINFO_DATA);
-
- memcpy(&tempconst , &(RxFrm->UDat.Dat[8]) , 2);
- memcpy(&temphfconst , &(RxFrm->UDat.Dat[10]) , 2);
- memcpy(&tempub , &(RxFrm->UDat.Dat[12]) , 2);
- memcpy(&tempus , &(RxFrm->UDat.Dat[14]) , 4);
- memcpy(&tempib , &(RxFrm->UDat.Dat[18]) , 2);
- memcpy(&tempis , &(RxFrm->UDat.Dat[20]) , 4);
-
-
- Dl645FirmPara.ConstE=tempconst*10L;
- Dl645RN7302DataComm.ucTemp8 = 0xe5; // 写使能位
- fnRN7302_Write(0x0180,Dl645RN7302DataComm.ucTempBuf,1);
- Dl645FirmPara.HFConst1 = temphfconst;
- fnRN7302_Write(HFCONST1,(u8 *)&Dl645FirmPara.HFConst1,2);
- fnDl645File_Write(Dl645FileId_FirmPara,26,(u8 *)&Dl645FirmPara.HFConst1,2);
-
- for(i=0;i<3;i++) //
- {
- memcpy(&temppw[0] , &(RxFrm->UDat.Dat[32+4*i]) , 4);
- temppw[1] = tempus/tempub;
- temppw[1] = (temppw[1] *temppw[0])/10;
- fnRN7302_Read( 0x0007+ i , (u8 *)&temppw[0] , 4 ) ;
- ADErr=((float)temppw[0]-(float)temppw[1])/temppw[1];
- ADErr=(-ADErr/(1+ADErr));
- if(ADErr>0) Dl645FirmPara.VGain[i]=(u16)(ADErr*32768);
- else Dl645FirmPara.VGain[i] = (u16)(65535 + ADErr*32768);
- fnRN7302_Write(GSUA+i,(u8 *)&Dl645FirmPara.VGain[i],2);
- fnRN7302_Read( GSUA+i , Dl645RN7302DataComm.ucTempBuf , 2 ) ;
- }
- fnDl645File_Write(Dl645FileId_FirmPara,42,(u8 *)&Dl645FirmPara.VGain[0],6);
-
- for(i=0;i<3;i++) //电流增益校正
- {
- memcpy(&temppw[0] , &(RxFrm->UDat.Dat[44+4*i]) , 4);
- temppw[1] = tempis/tempib;
- temppw[1] = (temppw[1] *temppw[0])/10;
- fnRN7302_Read( 0x000B+ i , (u8 *)&temppw[0] , 4 ) ;
- ADErr=((float)temppw[0]-(float)temppw[1])/temppw[1];
- ADErr=((-ADErr)/(1+ADErr));
- if(ADErr>0) Dl645FirmPara.IGain[i]=(u16)(ADErr*32768);
- else Dl645FirmPara.IGain[i] = (u16)(65535 + ADErr*32768);
- fnRN7302_Write(GSIA+i,(u8 *)&Dl645FirmPara.IGain[i],2);
- }
- fnDl645File_Write(Dl645FileId_FirmPara,48,(u8 *)&Dl645FirmPara.IGain[0],8);
-
-
- tempconst = fnHexToBcd_u16(tempconst) ;
- ConstE.Dat0 = (((u8)(tempconst & 0x000f))<<4)&0xf0;
- ConstE.Dat1 = (tempconst & 0x0ff0)>>4;
- ConstE.Dat2 = (u8)((tempconst & 0xf000)>>12);
-
-
- fnDl645File_Write(Dl645FileId_HighPara , Dl645FileItemInfoOffAddr_HighPara_PConstE , (u8 *)&ConstE , 3);
- fnDl645File_Write(Dl645FileId_HighPara , Dl645FileItemInfoOffAddr_HighPara_QConstE , (u8 *)&ConstE , 3);
-
- i=Dl645FirmPara.FractionI;
- B=1;
- while(i--)
- {
- B*=10;
- }
- B = B/1000;
- Dl645FirmPara.IRmsConst=((float)tempis/((float)tempib*B));
- fnDl645File_Write(Dl645FileId_FirmPara,10,(u8 *)&Dl645FirmPara.IRmsConst,4);
-
- i=Dl645FirmPara.FractionU;
- B=1;
- while(i--)
- {
- B*=10;
- }
- B = B/100;
- Dl645FirmPara.VRmsConst=((float)tempus/(tempub*B));
- fnDl645File_Write(Dl645FileId_FirmPara,30,(u8 *)&Dl645FirmPara.VRmsConst,4);
-
- Dl645FirmPara.NOLOAD = (u16)((tempis*0.0003)/16);
- Dl645FirmPara.ZEROSTAR=(u16)((tempis*0.005)/4096);
- fnRN7302_Write(IStart_PS,(u8 *)&Dl645FirmPara.NOLOAD,2);
- fnRN7302_Write(ZXOT,(u8 *)&Dl645FirmPara.ZEROSTAR,2);
- fnDl645File_Write(Dl645FileId_FirmPara,18,(u8 *)&Dl645FirmPara.NOLOAD,4);
-
- // 功率系数计算
- Dl645FirmPara.PRmsConst=(u32)((float)tempus*(float)tempis/((float)tempub*(float)tempib*838.8608));
- fnDl645File_Write(Dl645FileId_FirmPara,36,(u8 *)&Dl645FirmPara.PRmsConst,4);
-
- memcpy(&tempub , &(RxFrm->UDat.Dat[24]) , 2);
- memcpy(&tempib , &(RxFrm->UDat.Dat[26]) , 2);
-
- Dl645FirmPara.PRth[0] = tempub;
- Dl645FirmPara.PRth[1] = tempib;
-
- fnRN7302_Write(PRTH1L,(u8 *)&Dl645FirmPara.PRth[0],2);
- fnRN7302_Write(PRTH1H,(u8 *)&Dl645FirmPara.PRth[1],2);
-
- memcpy(&tempub , &(RxFrm->UDat.Dat[28]) , 2);
- memcpy(&tempib , &(RxFrm->UDat.Dat[30]) , 2);
-
- Dl645FirmPara.PRth[2] = tempub;
- Dl645FirmPara.PRth[3] = tempib;
-
- fnRN7302_Write(PRTH2L,(u8 *)&Dl645FirmPara.PRth[2],2);
- fnRN7302_Write(PRTH2H,(u8 *)&Dl645FirmPara.PRth[3],2);
- fnDl645File_Write(Dl645FileId_FirmPara,70,(u8 *)&Dl645FirmPara.PRth[0],8);
-
- Dl645RN7302DataComm.ucTemp8 = 0xDC; // 写保护
- fnRN7302_Write(0x0180,Dl645RN7302DataComm.ucTempBuf,1);
- Dl645FirmPara.ChkSum1 = 0;
- SystemDelay(10);
- fnRN7302_Read( CheckSum1 , (u8 *)&Dl645FirmPara.ChkSum1 , 3 ) ;
- fnDl645File_Write(Dl645FileId_FirmPara,22,(u8 *)&Dl645FirmPara.ChkSum1,3);
- break;
- case 0x00f81100: //功率相位校准
- if((RxFrm->Len != (12+18))&&(RxFrm->Len != (12+20))&&(RxFrm->Len != (12+5))) return(DL645B_ERRINFO_DATA);
- if(RxFrm->Len == (12+5))
- {
- memcpy(&tempis , &(RxFrm->UDat.Dat[9]) , 4);
- Dl645RN7302DataComm.ucTemp8 = 0xe5; // 写使能位
- fnRN7302_Write(0x0180,Dl645RN7302DataComm.ucTempBuf,1);
- if(tempis > 0x7fffffff) ADErr=-(float)(0xffffffff - tempis)/100000;
- else ADErr=(float)tempis/100000;
- ADErr = (asin(-ADErr/1.732))*57.29578/0.017578; // 弧度转成角度
- if(Dl645FirmPara.PRth[0]==0 && Dl645FirmPara.PRth[1]==0 && Dl645FirmPara.PRth[2]==0 && Dl645FirmPara.PRth[3]==0)
- {
- if(ADErr == 0) Dl645FirmPara.PHSI[RxFrm->UDat.Dat[8]] = 0x808080;
- else if(ADErr>0) Dl645FirmPara.PHSI[RxFrm->UDat.Dat[8]] = 0x808080 - (u8)ADErr;
- else {ADErr = -ADErr;Dl645FirmPara.PHSI[RxFrm->UDat.Dat[8]] = 0x808080 + (u8)ADErr;}
- }
- else
- {
- if(ADErr == 0) Dl645FirmPara.PHSI[RxFrm->UDat.Dat[8]] = (Dl645FirmPara.PHSI[RxFrm->UDat.Dat[8]]&0x00ff00ff)|0x8000;
- else if(ADErr>0) Dl645FirmPara.PHSI[RxFrm->UDat.Dat[8]] = Dl645FirmPara.PHSI[RxFrm->UDat.Dat[8]] - (((u32)((u8)ADErr)<<8)&0x0000ff00);
- else {ADErr = -ADErr;Dl645FirmPara.PHSI[RxFrm->UDat.Dat[8]] = Dl645FirmPara.PHSI[RxFrm->UDat.Dat[8]] + (((u32)((u8)ADErr)<<8)&0x0000ff00);}
- }
- fnRN7302_Write(PHSIA+RxFrm->UDat.Dat[8],(u8 *)&Dl645FirmPara.PHSI[RxFrm->UDat.Dat[8]],3);
- }
- else
- {
- memcpy(&tempis , &(RxFrm->UDat.Dat[8]) , 4);
- memcpy(&tempus , &(RxFrm->UDat.Dat[12]) , 4);
-
- Dl645FirmPara.PRmsConst=((float)tempus*100/(tempis/10));
-
- fnDl645File_Write(Dl645FileId_FirmPara,36,(u8 *)&Dl645FirmPara.PRmsConst,4);
-
- Dl645RN7302DataComm.ucTemp8 = 0xe5; // 写使能位
- fnRN7302_Write(0x0180,Dl645RN7302DataComm.ucTempBuf,1);
- if((RxFrm->Len == (12+18)))
- {
- tempangle[0] =0;
-
- for(i=0;i<2;i++)
- {
- fnRN7302_Read( YUB+i , Dl645RN7302DataComm.ucTempBuf , 3 ) ;
- temppw[0] =Dl645RN7302DataComm.lTemp32 & 0x00ffffff;
- tempangle[i+1] = (u16)(((float)temppw[0]/16777216)*36000);
- }
-
- for(i=0;i<3;i++)
- {
- memcpy(&tempangle[i+3] , &(RxFrm->UDat.Dat[20+2*i]) , 2);
- fnRN7302_Read( YIA+i , Dl645RN7302DataComm.ucTempBuf , 3 ) ;
- temppw[0] =Dl645RN7302DataComm.lTemp32 & 0x00ffffff;
- ADErr = ((((float)temppw[0]/16777216)*36000-(float)(tempangle[i+3]+tempangle[i]))/1.7578);
- if(Dl645FirmPara.PRth[0]==0 && Dl645FirmPara.PRth[1]==0 && Dl645FirmPara.PRth[2]==0 && Dl645FirmPara.PRth[3]==0)
- {
- if(ADErr>0) Dl645FirmPara.PHSI[i] = 0x808080 - (u8)ADErr;
- else {ADErr = -ADErr;Dl645FirmPara.PHSI[i] = 0x808080 + (u8)ADErr;}
- }
- else
- {
- if(ADErr>0) Dl645FirmPara.PHSI[i] = Dl645FirmPara.PHSI[i] - (((u32)((u8)ADErr)<<8)&0x0000ff00);
- else {ADErr = -ADErr;Dl645FirmPara.PHSI[i] = Dl645FirmPara.PHSI[i] + (((u32)((u8)ADErr)<<8)&0x0000ff00);}
- }
- fnRN7302_Write(PHSIA+i,(u8 *)&Dl645FirmPara.PHSI[i],3);
- }
- }
- else
- {
- for(i=0;i<3;i++)
- {
- fnRN7302_Read( 0x0014+i , Dl645RN7302DataComm.ucTempBuf , 4 ) ;
- temppw[0] =Dl645RN7302DataComm.lTemp32;
-
- memcpy(&temppw[1] , &(RxFrm->UDat.Dat[16 + 4*i]) , 4);
- temppw[1] = (u32)(((float)tempus/(float)tempis)*(float)temppw[1]);
- ADErr=((float)temppw[0]-(float)temppw[1])/(float)temppw[1];
- ADErr = (asin(-ADErr/1.732))*57.29578/0.017578; // 弧度转成角度
- if(Dl645FirmPara.PRth[0]==0 && Dl645FirmPara.PRth[1]==0 && Dl645FirmPara.PRth[2]==0 && Dl645FirmPara.PRth[3]==0)
- {
- if(ADErr>0) Dl645FirmPara.PHSI[i] = 0x808080 - (u8)ADErr;
- else {ADErr = -ADErr;Dl645FirmPara.PHSI[i] = 0x808080 + (u8)ADErr;}
- }
- else
- {
- if(ADErr>0) Dl645FirmPara.PHSI[i] = Dl645FirmPara.PHSI[i] - (((u32)((u8)ADErr)<<8)&0x0000ff00);
- else {ADErr = -ADErr;Dl645FirmPara.PHSI[i] = Dl645FirmPara.PHSI[i] + (((u32)((u8)ADErr)<<8)&0x0000ff00);}
- }
- fnRN7302_Write(PHSIA+i,(u8 *)&Dl645FirmPara.PHSI[i],3);
- }
- }
- }
- fnDl645File_Write(Dl645FileId_FirmPara,56,(u8 *)&Dl645FirmPara.PHSU[0],14);
-
- Dl645RN7302DataComm.ucTemp8 = 0xDC; // 写保护
- fnRN7302_Write(0x0180,Dl645RN7302DataComm.ucTempBuf,1);
- Dl645FirmPara.ChkSum1 = 0;
- SystemDelay(10);
- fnRN7302_Read( CheckSum1 , (u8 *)&Dl645FirmPara.ChkSum1 , 3 ) ;
- fnDl645File_Write(Dl645FileId_FirmPara,22,(u8 *)&Dl645FirmPara.ChkSum1,3);
- break;
- case 0x00f81102: //功率相位校准分段1
- if((RxFrm->Len != (12+10))&&(RxFrm->Len != (12+20))&&(RxFrm->Len != (12+5))) return(DL645B_ERRINFO_DATA);
- if(Dl645FirmPara.PRth[0]==0 && Dl645FirmPara.PRth[1]==0 && Dl645FirmPara.PRth[2]==0 && Dl645FirmPara.PRth[3]==0) return(DL645B_ERRINFO_DATA);
- Dl645RN7302DataComm.ucTemp8 = 0xe5; // 写使能位
- fnRN7302_Write(0x0180,Dl645RN7302DataComm.ucTempBuf,1);
- if(RxFrm->Len == (12+10))
- {
- tempangle[0] =0;
- for(i=0;i<2;i++)
- {
- fnRN7302_Read( YUB+i , Dl645RN7302DataComm.ucTempBuf , 3 ) ;
- temppw[0] =Dl645RN7302DataComm.lTemp32 & 0x00ffffff;
- tempangle[i+1] = (u16)(((float)temppw[0]/16777216)*36000);
- }
-
- for(i=0;i<3;i++)
- {
- memcpy(&tempangle[i+3] , &(RxFrm->UDat.Dat[12+2*i]) , 2);
- fnRN7302_Read( YIA+i , Dl645RN7302DataComm.ucTempBuf , 3 ) ;
- //fnRN7302_Read( YIA+i , (u8 *)&temppw[0] , 3 ) ;
- temppw[0] =Dl645RN7302DataComm.lTemp32 & 0x00ffffff;
- ADErr = ((((float)temppw[0]/16777216)*36000-(tempangle[i+3]+tempangle[i]))/1.7578);
- if(ADErr>0) Dl645FirmPara.PHSI[i] = ((Dl645FirmPara.PHSI[i]&0xffff00)|0x000080) - (u8)ADErr;
- else {ADErr = -ADErr;Dl645FirmPara.PHSI[i] = ((Dl645FirmPara.PHSI[i]&0xffff00)|0x000080) + (u8)ADErr;}
- fnRN7302_Write(PHSIA+i,(u8 *)&Dl645FirmPara.PHSI[i],3);
- }
- }
- else if(RxFrm->Len == (12+20))
- {
- memcpy(&tempis , &(RxFrm->UDat.Dat[8]) , 4);
- memcpy(&tempus , &(RxFrm->UDat.Dat[12]) , 4);
-
- for(i=0;i<3;i++)
- {
- fnRN7302_Read( 0x0014+i , Dl645RN7302DataComm.ucTempBuf , 4 ) ;
- temppw[0] =Dl645RN7302DataComm.lTemp32;
-
- memcpy(&temppw[1] , &(RxFrm->UDat.Dat[16 + 4*i]) , 4);
- temppw[1] = (u32)(((float)tempus/(float)tempis)*(float)temppw[1]);
- ADErr=((float)temppw[0]-(float)temppw[1])/(float)temppw[1];
- ADErr = (asin(-ADErr/1.732))*57.29578/0.017578; // 弧度转成角度
- if(ADErr>0) Dl645FirmPara.PHSI[i] = ((Dl645FirmPara.PHSI[i]&0xffff00)|0x000080) - (u8)ADErr;
- else {ADErr = -ADErr;Dl645FirmPara.PHSI[i] = ((Dl645FirmPara.PHSI[i]&0xffff00)|0x000080) + (u8)ADErr;}
- fnRN7302_Write(PHSIA+i,(u8 *)&Dl645FirmPara.PHSI[i],3);
- }
- }
- else
- {
- memcpy(&tempis , &(RxFrm->UDat.Dat[9]) , 4);
- Dl645RN7302DataComm.ucTemp8 = 0xe5; // 写使能位
- fnRN7302_Write(0x0180,Dl645RN7302DataComm.ucTempBuf,1);
- if(tempis > 0x7fffffff) ADErr=-(float)(0xffffffff - tempis)/100000;
- else ADErr=(float)tempis/100000;
- ADErr = (asin(-ADErr/1.732))*57.29578/0.017578; // 弧度转成角度
- if(ADErr>0) Dl645FirmPara.PHSI[RxFrm->UDat.Dat[8]] = ((Dl645FirmPara.PHSI[RxFrm->UDat.Dat[8]]&0xffff00)|0x000080) - (u8)ADErr;
- else {ADErr = -ADErr;Dl645FirmPara.PHSI[RxFrm->UDat.Dat[8]] = ((Dl645FirmPara.PHSI[RxFrm->UDat.Dat[8]]&0xffff00)|0x000080) + (u8)ADErr;}
- fnRN7302_Write(PHSIA+RxFrm->UDat.Dat[8],(u8 *)&Dl645FirmPara.PHSI[RxFrm->UDat.Dat[8]],3);
- }
- fnDl645File_Write(Dl645FileId_FirmPara,56,(u8 *)&Dl645FirmPara.PHSU[0],14);
- Dl645RN7302DataComm.ucTemp8 = 0xDC; // 写保护
- fnRN7302_Write(0x0180,Dl645RN7302DataComm.ucTempBuf,1);
- Dl645FirmPara.ChkSum1 = 0;
- SystemDelay(10);
- fnRN7302_Read( CheckSum1 , (u8 *)&Dl645FirmPara.ChkSum1 , 3 ) ;
- fnDl645File_Write(Dl645FileId_FirmPara,22,(u8 *)&Dl645FirmPara.ChkSum1,3);
- break;
- case 0x00f81103:
- if((RxFrm->Len != (12+10))&&(RxFrm->Len != (12+20))&&(RxFrm->Len != (12+5))) return(DL645B_ERRINFO_DATA);
- if(Dl645FirmPara.PRth[0]==0 && Dl645FirmPara.PRth[1]==0 && Dl645FirmPara.PRth[2]==0 && Dl645FirmPara.PRth[3]==0) return(DL645B_ERRINFO_DATA);
- Dl645RN7302DataComm.ucTemp8 = 0xe5; // 写使能位
- fnRN7302_Write(0x0180,Dl645RN7302DataComm.ucTempBuf,1);
- if(RxFrm->Len == (12+10))
- {
- tempangle[0] =0;
- for(i=0;i<2;i++)
- {
- fnRN7302_Read( YUB+i , Dl645RN7302DataComm.ucTempBuf , 3 ) ;
- temppw[0] =Dl645RN7302DataComm.lTemp32 & 0x00ffffff;
- tempangle[i+1] = (u16)(((float)temppw[0]/16777216)*36000);
- }
- for(i=0;i<3;i++)
- {
- memcpy(&tempangle[i+3] , &(RxFrm->UDat.Dat[12+2*i]) , 2);
- fnRN7302_Read( YIA+i , Dl645RN7302DataComm.ucTempBuf , 3 ) ;
- temppw[0] =Dl645RN7302DataComm.lTemp32 & 0x00ffffff;
- ADErr = ((((float)temppw[0]/16777216)*36000-(tempangle[i+3]+tempangle[i]))/1.7578);
- if(ADErr>0) Dl645FirmPara.PHSI[i] = ((Dl645FirmPara.PHSI[i]&0x00ffff)|0x800000) - (((u32)((u8)ADErr)*65536)&0x00ff0000);
- else {ADErr = -ADErr;Dl645FirmPara.PHSI[i] = ((Dl645FirmPara.PHSI[i]&0x00ffff)|0x800000) + (((u32)((u8)ADErr)*65536)&0x00ff0000);}
- fnRN7302_Write(PHSIA+i,(u8 *)&Dl645FirmPara.PHSI[i],3);
- }
- }
- else if((RxFrm->Len == (12+20)))
- {
- memcpy(&tempis , &(RxFrm->UDat.Dat[8]) , 4);
- memcpy(&tempus , &(RxFrm->UDat.Dat[12]) , 4);
-
- for(i=0;i<3;i++)
- {
- fnRN7302_Read( 0x0014+i , Dl645RN7302DataComm.ucTempBuf , 4 ) ;
- temppw[0] =Dl645RN7302DataComm.lTemp32;
-
- memcpy(&temppw[1] , &(RxFrm->UDat.Dat[16 + 4*i]) , 4);
- temppw[1] = (u32)(((float)tempus/(float)tempis)*(float)temppw[1]);
- ADErr=((float)temppw[0]-(float)temppw[1])/(float)temppw[1];
- ADErr = (asin(-ADErr/1.732))*57.29578/0.017578; // 弧度转成角度
- if(ADErr>0) Dl645FirmPara.PHSI[i] = ((Dl645FirmPara.PHSI[i]&0x00ffff)|0x800000) - (((u32)((u8)ADErr)*65536)&0x00ff0000);
- else {ADErr = -ADErr;Dl645FirmPara.PHSI[i] = ((Dl645FirmPara.PHSI[i]&0x00ffff)|0x800000) + (((u32)((u8)ADErr)*65536)&0x00ff0000);}
- fnRN7302_Write(PHSIA+i,(u8 *)&Dl645FirmPara.PHSI[i],3);
- }
- }
- else
- {
- memcpy(&tempis , &(RxFrm->UDat.Dat[9]) , 4);
- Dl645RN7302DataComm.ucTemp8 = 0xe5; // 写使能位
- fnRN7302_Write(0x0180,Dl645RN7302DataComm.ucTempBuf,1);
- if(tempis > 0x7fffffff) ADErr=-(float)(0xffffffff - tempis)/100000;
- else ADErr=(float)tempis/100000;
- ADErr = (asin(-ADErr/1.732))*57.29578/0.017578; // 弧度转成角度
- if(ADErr>0) Dl645FirmPara.PHSI[RxFrm->UDat.Dat[8]] = ((Dl645FirmPara.PHSI[RxFrm->UDat.Dat[8]]&0x00ffff)|0x800000) - (((u32)((u8)ADErr)*65536)&0x00ff0000);
- else {ADErr = -ADErr;Dl645FirmPara.PHSI[RxFrm->UDat.Dat[8]] = ((Dl645FirmPara.PHSI[RxFrm->UDat.Dat[8]]&0x00ffff)|0x800000) + (((u32)((u8)ADErr)*65536)&0x00ff0000);}
- fnRN7302_Write(PHSIA+RxFrm->UDat.Dat[8],(u8 *)&Dl645FirmPara.PHSI[RxFrm->UDat.Dat[8]],3);
- }
- fnDl645File_Write(Dl645FileId_FirmPara,56,(u8 *)&Dl645FirmPara.PHSU[0],14);
-
- Dl645RN7302DataComm.ucTemp8 = 0xDC; // 写保护
- fnRN7302_Write(0x0180,Dl645RN7302DataComm.ucTempBuf,1);
- Dl645FirmPara.ChkSum1 = 0;
- SystemDelay(10);
- fnRN7302_Read( CheckSum1 , (u8 *)&Dl645FirmPara.ChkSum1 , 3 ) ;
- fnDl645File_Write(Dl645FileId_FirmPara,22,(u8 *)&Dl645FirmPara.ChkSum1,3);
- break;
- case 0x00f81501: // 误差校正功率增益
- if(RxFrm->Len != (12+5)) return(DL645B_ERRINFO_DATA);
- if(RxFrm->UDat.Dat[8]>0x03) return(DL645B_ERRINFO_DATA);
- memcpy(&tempis , &(RxFrm->UDat.Dat[9]) , 4);
- Dl645RN7302DataComm.ucTemp8 = 0xe5; // 写使能位
- fnRN7302_Write(0x0180,Dl645RN7302DataComm.ucTempBuf,1);
- if(tempis > 0x7fffffff) ADErr=-(float)(0xffffffff - tempis)/100000;
- else ADErr=(float)tempis/100000;
- ADErr=((-ADErr)/(1+ADErr));
- if(ADErr>=0) Dl645FirmPara.PGain[RxFrm->UDat.Dat[8]]=(u16)(ADErr*32768);
- else Dl645FirmPara.PGain[RxFrm->UDat.Dat[8]] = (u16)(65535 + ADErr*32768);
- fnRN7302_Write(GPA+RxFrm->UDat.Dat[8],(u8 *)&Dl645FirmPara.PGain[RxFrm->UDat.Dat[8]],2);
- fnRN7302_Write(GQA+RxFrm->UDat.Dat[8],(u8 *)&Dl645FirmPara.PGain[RxFrm->UDat.Dat[8]],2);
- fnRN7302_Write(GSA+RxFrm->UDat.Dat[8],(u8 *)&Dl645FirmPara.PGain[RxFrm->UDat.Dat[8]],2);
- Dl645RN7302DataComm.ucTemp8 = 0xDC; // 写保护
- fnRN7302_Write(0x0180,Dl645RN7302DataComm.ucTempBuf,1);
- fnDl645File_Write(Dl645FileId_FirmPara,98,(u8 *)&Dl645FirmPara.PGain[0],6);
- Dl645FirmPara.ChkSum1 = 0;
- SystemDelay(10);
- fnRN7302_Read( CheckSum1 , (u8 *)&Dl645FirmPara.ChkSum1 , 3 ) ;
- fnDl645File_Write(Dl645FileId_FirmPara,22,(u8 *)&Dl645FirmPara.ChkSum1,3);
- break;
- case 0x00f81600:
- if((RxFrm->Len != (12 + 1)) && (RxFrm->UDat.Dat[8] != 0x5A)) return(DL645B_ERRINFO_DATA);
- Dl645RN7302DataComm.ucTemp8 = 0xe5; // 写使能位
- fnRN7302_Write(0x0180,Dl645RN7302DataComm.ucTempBuf,1);
- for(i=0;i<3;i++)
- {
- Dl645FirmPara.VGain[i]=0;
- fnRN7302_Write(GSUA+i,(u8 *)&Dl645FirmPara.VGain[i],2);
- Dl645FirmPara.IGain[i]=0;
- fnRN7302_Write(GSIA+i,(u8 *)&Dl645FirmPara.IGain[i],2);
- }
- for(i=0;i<2;i++)
- {
- Dl645FirmPara.PHSU[i]=0x80;
- fnRN7302_Write(PHSUB+i,(u8 *)&Dl645FirmPara.PHSU[i],1);
- }
- for(i=0;i<3;i++)
- {
- Dl645FirmPara.PHSI[i]=0x808080;
- fnRN7302_Write(PHSUB+i,(u8 *)&Dl645FirmPara.PHSI[i],3);
- }
- for(i=0;i<3;i++)
- {
- Dl645FirmPara.P_PHS[i]=0;
- fnRN7302_Write(PA_PHS+i,(u8 *)&Dl645FirmPara.P_PHS[i],2);
- }
- for(i=0;i<3;i++)
- {
- Dl645FirmPara.P_PHS[i]=0;
- fnRN7302_Write(PA_PHS+i,(u8 *)&Dl645FirmPara.P_PHS[i],2);
- }
- for(i=0;i<3;i++)
- {
- Dl645FirmPara.PGain[i]=0;
- fnRN7302_Write(GPA+i,(u8 *)&Dl645FirmPara.PGain[i],2);
- fnRN7302_Write(GQA+i,(u8 *)&Dl645FirmPara.PGain[i],2);
- fnRN7302_Write(GSA+i,(u8 *)&Dl645FirmPara.PGain[i],2);
- }
- Dl645FirmPara.PRth[0] = 0x0;
- Dl645FirmPara.PRth[1] = 0x0;
- Dl645FirmPara.PRth[2] = 0x0;
- Dl645FirmPara.PRth[3] = 0x0;
- fnRN7302_Write(PRTH1L,(u8 *)&Dl645FirmPara.PRth[0],2);
- fnRN7302_Write(PRTH1H,(u8 *)&Dl645FirmPara.PRth[1],2);
- fnRN7302_Write(PRTH2L,(u8 *)&Dl645FirmPara.PRth[2],2);
- fnRN7302_Write(PRTH2H,(u8 *)&Dl645FirmPara.PRth[3],2);
-
- Dl645RN7302DataComm.ucTemp8 = 0xDC; // 写保护
- fnRN7302_Write(0x0180,Dl645RN7302DataComm.ucTempBuf,1);
- fnDl645File_Write(Dl645FileId_FirmPara,42,(u8 *)&Dl645FirmPara.VGain[0],6);
- fnDl645File_Write(Dl645FileId_FirmPara,48,(u8 *)&Dl645FirmPara.IGain[0],8);
- fnDl645File_Write(Dl645FileId_FirmPara,56,(u8 *)&Dl645FirmPara.PHSU[0],14);
- fnDl645File_Write(Dl645FileId_FirmPara,70,(u8 *)&Dl645FirmPara.PRth[0],8);
- fnDl645File_Write(Dl645FileId_FirmPara,92,(u8 *)&Dl645FirmPara.P_PHS[0],12);
- fnDl645File_Write(Dl645FileId_FirmPara,98,(u8 *)&Dl645FirmPara.PGain[0],6);
- Dl645FirmPara.ChkSum1 = 0;
- SystemDelay(10);
- fnRN7302_Read( CheckSum1 , (u8 *)&Dl645FirmPara.ChkSum1 , 3 ) ;
- fnDl645File_Write(Dl645FileId_FirmPara,22,(u8 *)&Dl645FirmPara.ChkSum1,3);
- break;
- }
- }
复制代码
只有一个c文件,不完整,求大家补全:
RN7302_Demo_V1.1.rar
(6.25 KB, 下载次数: 371)
|