----用于FLASH的变频器实时数据定义及其实现----现在需要定义一个可靠的FLASH内部数据管理方式,方便DSP进行读写数据。代码如下:(代码看不懂)----flash.h----- [/align][align=left]/****************函数声明*******************/[/align]Uint16 SectorErase(Uint16);
- Uint16 BlockErase(Uint16);
- Uint16 ChipErase(void);
- void FlashRead(int *Ptr, Uint32, Uint16);
- Uint16 FlashWrite(int *Ptr, Uint32, Uint16);
- void InitExRam(void);
复制代码
----flash.c----
- /*****************头文件********************/
- #include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
- #include "DSP2833x_Examples.h" // DSP2833x Examples Include File
- #include "flash.h"
- /****************宏定义*****************/
- //#define SST_ID 0x00BF /* SST Manufacturer's ID code */
- //#define SST_39VF800A 0x2780 /* SST39VF800/SST39VF800A device code */
- #define TimeOutErr 1
- #define VerifyErr 2
- #define WriteOK 0
- #define EraseErr 3
- #define EraseOK 0
- #define SectorSize 0x800
- #define BlockSize 0x8000
- #pragma DATA_SECTION(EX_RAM_DATA,".exramps") //定义外部存储数据用的数组;
- int EX_RAM_DATA[8192];
- /***************全局变量定义****************/
- unsigned int *FlashStart = (unsigned int *)0x100000;//flash的首地址
- /*---------------------------------------------------------------------
- 函数原型:Uint16 SectorErase(Uint16 SectorNum)
- 函数名称:Flash段擦除
- 函数功能:以段为单位擦除Flash
- 入口参数:SectorNum---段号
- 出口参数:0---正确 1---超时 3---错误
- 作 者:
- 日 期:
- ----------------------------------------------------------------------*/
- Uint16 SectorErase(Uint16 SectorNum)
- {
- Uint16 i,Data;
- Uint32 TimeOut;
- *(FlashStart + 0x5555) = 0xAAAA;
- *(FlashStart + 0x2AAA) = 0x5555;
- *(FlashStart + 0x5555) = 0x8080;
- *(FlashStart + 0x5555) = 0xAAAA;
- *(FlashStart + 0x2AAA) = 0x5555;
- *(FlashStart + SectorSize * SectorNum) = 0x3030;
- i = 0;
- TimeOut = 0;
- while(i<5)
- {
- Data = *(FlashStart + SectorSize * (SectorNum + 1) -1);
- if (Data == 0xFFFF) i++;
- else i=0;
- if ( ++TimeOut>0x1000000)
- return (TimeOutErr);
- }
- for (i=0;i<SectorSize;i++)
- {
- Data = *(FlashStart + SectorSize * SectorNum +i);
- if (Data !=0xFFFF) return (EraseErr);
- }
- return (EraseOK);
- }
- /*---------------------------------------------------------------------
- 函数原型:Uint16 BlockErase(Uint16 BlockrNum)
- 函数名称:Flash块擦除
- 函数功能:以块为单位擦除Flash
- 入口参数:BlockNum---段号
- 出口参数:0---正确 1---超时 3---错误
- 作 者:
- 日 期:
- ----------------------------------------------------------------------*/
- Uint16 BlockErase(Uint16 BlockNum)
- {
- Uint16 i,Data;
- Uint32 TimeOut;
-
- *(FlashStart + 0x5555) = 0xAAAA;
- *(FlashStart + 0x2AAA) = 0x5555;
- *(FlashStart + 0x5555) = 0x8080;
- *(FlashStart + 0x5555) = 0xAAAA;
- *(FlashStart + 0x2AAA) = 0x5555;
- *(FlashStart + BlockSize * BlockNum + 1) = 0x5050;
- i = 0;
- TimeOut = 0;
- while(i<5)
- {
- Data = *(FlashStart + BlockSize * (BlockNum +1));
- if (Data == 0xFFFF) i++;
- else i=0;
- if ( ++TimeOut>0x1000000)
- return (TimeOutErr);
- }
- for (i=0;i<SectorSize;i++)
- {
- Data = *(FlashStart + BlockSize * BlockNum +i);
- if (Data !=0xFFFF) return (EraseErr);
- }
- return (EraseOK);
- }
- /*---------------------------------------------------------------------
- 函数原型:Uint16 ChipErase(void)
- 函数名称:Flash全部擦除
- 函数功能:擦除Flash
- 入口参数:无
- 出口参数:0---正确 1---超时 3---错误
- 作 者:
- 日 期:
- ----------------------------------------------------------------------*/
- Uint16 ChipErase(void)
- {
- Uint16 Data;
- Uint32 TimeOut,i;
-
- *(FlashStart + 0x5555) = 0xAAAA;
- *(FlashStart + 0x2AAA) = 0x5555;
- *(FlashStart + 0x5555) = 0x8080;
- *(FlashStart + 0x5555) = 0xAAAA;
- *(FlashStart + 0x2AAA) = 0x5555;
- *(FlashStart + 0x5555) = 0x1010;
-
- i = 0;
- TimeOut = 0;
- while(i<5)
- {
- Data = *(FlashStart + 0x3FFFF);
- if (Data == 0xFFFF) i++;
- else i=0;
- if ( ++TimeOut>0x1000000)
- return (TimeOutErr);
- }
- for (i=0;i<0x40000;i++)
- {
- Data = *(FlashStart + i);
- if (Data !=0xFFFF) return (EraseErr);
- }
- return (EraseOK);
- }
-
- /*---------------------------------------------------------------------
- 函数原型:Uint16 FlashWrite(int *Ptr, Uint32 RomStart, Uint16 Length)
- 函数名称:写Flash
- 函数功能:将Ptr所指的Length个数据写入RomStart开始处
- 入口参数:Ptr---写入数据指针 RomStart---Flash起始位置 Length---数据长度
- 出口参数:0---正确 1---超时
- 作 者:
- 日 期:
- ----------------------------------------------------------------------*/
- Uint16 FlashWrite(int *Ptr,Uint32 RomStart,Uint16 Length)
- {
- Uint32 i,TimeOut;
- Uint16 Data1,Data2,j;
- for (i=0;i<Length;i++)
- {
- *(FlashStart + 0x5555) = 0x00AA;
- *(FlashStart + 0x2AAA) = 0x0055;
- *(FlashStart + 0x5555) = 0x00A0;
- *(FlashStart + RomStart + i) = *(Ptr+i);
- TimeOut = 0;
- j=0;
- while(j<5)
- {
- Data1 = *(FlashStart + RomStart + i);
- Data2 = *(FlashStart + RomStart + i);
- if (Data1 == Data2) j++;
- else j=0;
- if ( ++TimeOut>0x1000000)
- return (TimeOutErr);
- }
- }
- return (WriteOK);
- }
- /*---------------------------------------------------------------------
- 函数原型:Uint16 FlashRead(int *Ptr, Uint32 RomStart, Uint16 Length)
- 函数名称:Flash读
- 函数功能:将RomStart开始Length个数据写入Ptr
- 入口参数:Ptr---写入数据指针 RomStart---Flash起始位置 Length---数据长度
- 出口参数:无
- 作 者:
- 日 期:
- ----------------------------------------------------------------------*/
- void FlashRead(int *Ptr, Uint32 RomStart, Uint16 Length)
- {
- Uint32 i;
- for (i=0;i<Length;i++)
- {
- *(Ptr+i) = *(FlashStart + RomStart +i);
- }
- }
- /*---------------------------------------------------------------------
- 函数原型:void InitExRam(void)
- 函数名称:初始化外部Ram
- 函数功能:将ExRam初始化为0
- 入口参数:
- 出口参数:
- 作 者:
- 日 期:
- ----------------------------------------------------------------------*/
- void InitExRam(void)
- {
- Uint16 i;
- for (i=0;i<0xFFFF;i++)
- EX_RAM_DATA[i] = 0;
- }
-
- //=========================================NO MORE==============================
复制代码
----para.c----- /*****************头文件********************/
- #include "DSP2833x_Device.h"
- #include "DSP2833x_Examples.h"
- #include "parameter.h"
- #include "flash.h"
- #pragma DATA_SECTION(ParaTable,".ParaTab")
- struct PARAMETER_REGS ParaTable;
- //read the parameter from the flash;
- //if the flash is not empty, then read the parameter from the flash and then run;
- //
- void ReadParaFromFlash()
- {
- int *ParPoint;
- ParPoint = &ParaTable.PowerParReg.uPowerType;
- FlashRead(ParPoint,0x0,256);
- }
- /*---------------------------------------------------------------------
- 函数原型:WR_Default()
- 函数名称:初始化电机参数
- 函数功能:第一次向flash写入,以后从flash读取上次参数:
- ----------------------------------------------------------------------*/
- void WtiteDefaultToFlash()
- {
- int *ParPoint,i;
- ChipErase();
- ParPoint = &ParaTable.PowerParReg.uPowerType;
- for(i=0;i<256;i++)
- *(ParPoint+i) = 0x00;
- ParaTable.PowerParReg.uPowerType = 0; //电机类型:0:感应电机;
- ParaTable.PowerParReg.uPowerNomFre = 50; //电源额定频率 : 实际值,缺省50 HZ(单位);
- ParaTable.PowerParReg.uPowerNomVol = 380; //电源额定电压 : 线电压 实际值,缺省380 V (单位)
- ParaTable.PowerParReg.uPowerNomSpeed = 1500; //电源额定转速 : 实际值,缺省1485 RPM (单位)
- ParaTable.PowerParReg.uPOLES = 2; //电机极对 : 实际值,缺省2 POLERS(对极)
- ParaTable.PowerParReg.uPowerNomCur = 30; //电源额定电流 实际值, 262 A (单位)
- ParaTable.PowerParReg.uPulse = 80; //电机编码器的每转脉冲数 实际值,缺省 80 (编码器的每转脉冲数);
- ParaTable.PowerParReg.uRs = 20; //20度时电机定子绕组电阻 实际值 20 毫欧;
- ParaTable.PowerParReg.uLs = 10; //20度时电机定子绕组漏抗 实际值 10 毫亨;
- ParaTable.PowerParReg.uRr = 20; //20度时电机转子绕组电阻 实际值 20 毫欧
- ParaTable.PowerParReg.uLr = 20; //20度时电机转子绕组漏抗 实际值 20 毫欧
- ParaTable.PowerParReg.PT1000 = 1000; //电机温度测试用的PT 缺省使用PT1000; 1000表示PT1000;
- ParaTable.PowerParReg.uPPower = 50; //电机额定功率 实际值 50 KW
- ParaTable.PowerParReg.uCosPhi = 85; //电机额定功率因数 85 % ; 实际百分数
- ParaTable.PowerParReg.uIsd = 620; //电机额定励磁电流 标幺值 Q12; 4096表示100%
- ParaTable.PowerParReg.uIsq = 3900; //电机额定转矩电流 标幺值 Q12:4096表示100%;
- ParaTable.PowerParReg.uTorque = 300; //电机额定转矩:NM
- ParaTable.PowerParReg.uGD2 = 100; //电机飞轮负载一阶转矩
- ParaTable.PowerParReg.uRxs1 = 100; //电机带的减速齿轮箱传动比 实际数目*100:用于机车;例如200表示2倍增速度;10表示0.1倍增速;
- ParaTable.PowerParReg.uRadius = 90; //电机带的飞轮直径 实际值: 90毫米;
- ParaTable.PowerParReg.uForMaxSpeed = 4096;;//正向最大速度值:Q12; 4096=100%;
- ParaTable.PowerParReg.uBackMaxSpeed = -4096;//负向最大速度值:Q12:4096=100%
- ParaTable.PowerParReg.uMaxTorque = 7372; //加速最大转矩限制 Q12:100%=4096;
- ParaTable.PowerParReg.uMinTorque = -7372;//减速最大转矩限制 Q12:100%=4096
- //VVVF参数设置
- ParaTable.VVVFReg.uAcelTime1 = 4000; //总加速时间: 1=10ms: (0到100%速度用的时间)
- ParaTable.VVVFReg.uAcelTime2 = 4000; //总加速时间: 1=10ms: (100%到150%速度用的时间)
- ParaTable.VVVFReg.uDecTime1 = 4000; //总减速时间: 1=10ms; (0到100%速度用的时间)
- ParaTable.VVVFReg.uDecTime2 = 4000; //总减速时间: 1=10ms; (150到100%速度用的时间)
- ParaTable.VVVFReg.uTimeMux = 1; //时间系数 =1;时间放大倍数;(对10ms进行放大)
- ParaTable.VVVFReg.uVBoost = 40; //启动电压:标幺值Q12; 5%
- ParaTable.VVVFReg.uVol125 = 3687; //电压设定V1:标幺值Q12; 90%
- ParaTable.VVVFReg.uVol150 = 3072; //电压设定V2:标幺值Q12; 75%
- ParaTable.VVVFReg.uVol200 = 1024; //电压设定V3:标幺值Q12; 25%
- ParaTable.VVVFReg.uFreq1 = 500; //1号频率
- ParaTable.VVVFReg.uFreq2 = 1000; //2号频率
- ParaTable.VVVFReg.uFreq3 = 2000; //3号频率
- ParaTable.VVVFReg.uFreq4 = 2800; //4号频率
- ParaTable.VVVFReg.uFreq5 = 3200; //5号频率
- ParaTable.VVVFReg.uFreq6 = 4096; //6号频率
- ParaTable.VVVFReg.uVol1 = 800; //1号电压
- ParaTable.VVVFReg.uVol2 = 1300; //2号电压
- ParaTable.VVVFReg.uVol3 = 2000; //3号电压
- ParaTable.VVVFReg.uVol4 = 2800; //4号电压
- ParaTable.VVVFReg.uVol5 = 3200; //5号电压
- ParaTable.VVVFReg.uVol6 = 4096; //6号电压
- //设置通信参数
- ParaTable.CommReg.uSpeed = 11520; //串行通信速率:11520*10;
- ParaTable.CommReg.uDataNum = 8; //8个数据位;
- ParaTable.CommReg.uCheckBit = 0; //无校验位;
- ParaTable.CommReg.uStopBit = 1; //一个停止位;
- ParaTable.CommReg.uSetNum = 2; //设备号;
- ParaTable.CommReg.RecvMode = 3; //CAN+SCI;
- ParaTable.CommReg.uCanBaud = 100; //can speed: 100KBPS;
- ParaTable.CommReg.uCanRecvAddr = 0; //CAN接收地址;
- ParaTable.CommReg.uCanSendAddr = 31; //can发送地址;
- //设置PI控制器参数
- ParaTable.PIset.KpId = 2800; //Q12:id控制比例系数; 4505
- ParaTable.PIset.KiId = 24; //q12:id控制积分系数 24
- ParaTable.PIset.KdId = 10; //Q12:id控制比例系数
- ParaTable.PIset.Isd_PI_Max = 4096; //q12:id_PI输出最大值;
- ParaTable.PIset.Isd_PI_Min = -4096; //q12:id_PI输出最小值
- ParaTable.PIset.KpIq = 2800; //q12:iq控制积分系数 4505
- ParaTable.PIset.KiIq = 24; //Q12:iq控制比例系数 24
- ParaTable.PIset.KdIq = 10; //q12:iq控制比例系数
- ParaTable.PIset.Isq_PI_Max = 4096; //q12:iq_PI输出最大值;
- ParaTable.PIset.Isq_PI_Min = -4096; //q12:iq_PI输出最小值
- ParaTable.PIset.KpVd = 1600; //Q12:Vd控制比例系数; //7372;
- ParaTable.PIset.KiVd = 10; //q12:Vd控制积分系数 //153;
- ParaTable.PIset.KdVd = 10; //Q12:Vd控制比例系数
- ParaTable.PIset.Vd_PI_Max = 4096; //q12:Vd_PI输出最大值;
- ParaTable.PIset.Vd_PI_Min = -4096; //q12:Vd_PI输出最小值
- ParaTable.PIset.KpVq = 3500; //Q12:Vq控制比例系数; //7372;
- ParaTable.PIset.KiVq = 30; //q12:Vq控制积分系数 //153;
- ParaTable.PIset.KdVq = 10; //Q12:Vq控制比例系数
- ParaTable.PIset.Vq_PI_Max = 8192; //q12:Vq输出最大值;
- ParaTable.PIset.Vq_PI_Min = -8192; //q12:Vq输出最小值
- //变频器电气参数设置
- ParaTable.InvCtlReg.uACInputVol = 380; // 变频器交流输入电压380V;
- ParaTable.InvCtlReg.uDCInput = 540; // 变频器直流输入电压540V;
- ParaTable.InvCtlReg.uDCInputLim = 540; // 变频器直流最低输入电压540V;
- ParaTable.InvCtlReg.uInputDCCurrent = 227; // 变频器直流输入电流227A;
- // ParaTable.InvCtlReg.uDcVolUpper = 5529; // 直流电压最高值:135%;Q12;
- ParaTable.InvCtlReg.uDcVolUpper = 4915; // 直流电压最高值:120%;Q12;
- ParaTable.InvCtlReg.uDcVolBom = 3277; // 直流输入低压值:80%; Q12;
- // ParaTable.InvCtlReg.uDcVolBom = 3072; // 直流输入最低值:75%; Q12;
- ParaTable.InvCtlReg.uAcOutputVol = 380; // 变频器额定输出交流电压: 实际值380*1.4142;
- ParaTable.InvCtlReg.uACOutputCurrent = 18; // 变频器额定输出交流电流: 实际值;
- ParaTable.InvCtlReg.uACOutputVolMax = 4505; // 输出交流电压最高保护值:110% -Q12
- // ParaTable.InvCtlReg.uACOutputVolMax = 3686; // 测试用,输出90%过压报警
- ParaTable.InvCtlReg.uACOutputVolMax1 = 4710; // 输出交流电压最高保护值1:115% -Q12
- ParaTable.InvCtlReg.uACOutputCurMax = 4915; //交流输出铙电流 标幺值;4096=100% Q12
- ParaTable.InvCtlReg.uACOutputCurMax1 = 4915; //变频器输出电流报警值 标幺值;4096=100% Q12
- ParaTable.InvCtlReg.uChgStopVol = 2621; //变频器d充电结束电压值 标幺值;80%的额定电压合上继电器
- ParaTable.InvCtlReg.uChgWait = 30; //充电结束后等待时间 实际数: 单位10ms;
- ParaTable.InvCtlReg.uErrorTemp = 383; //变频器保护温度值 实际值; 95℃保护值(550ohm)
- ParaTable.InvCtlReg.uWarringTemp = 85; //变频器报警温度值 实际值;
- ParaTable.InvCtlReg.uFanOnTemp = 45; //开风机温度: 实际值;
- ParaTable.InvCtlReg.uFanOffTemp = 40; //关风机温度: 实际值;
- ParaTable.InvCtlReg.uPwmFreq = 6400; //变频器PWM开关周期 实际值: 6400Hz;
- ParaTable.InvCtlReg.uT3Period = 5; //变频器外部逻辑控制周期; 1ms;
- ParaTable.InvCtlReg.uACCurrXS = 50; //变频器电流传感器系数: 满量程*2; 实际值;//20ohm
- ParaTable.InvCtlReg.uDCVolXS = 1066; //变频器直流电压传感器系数:满量程; 实际值;
- ParaTable.InvCtlReg.uACVolabXS = 635; //变频器交流AB电压采样对应相传感器系数
- ParaTable.InvCtlReg.uACVolbcXS = 637; //变频器交流BC电压采样对应传感器系数
- ParaTable.InvCtlReg.uFreqXS = 55; //变频器频率旋钮调节器;对50Hz标幺
- ParaTable.InvCtlReg.LosePhaseCurr = 200; //5%;
- //变频器运行控制设置
- ParaTable.InvRunCtlReg.uCtlMode = 1; //运行模式 :枚举类型0:开环 或者1 闭环
- ParaTable.InvRunCtlReg.uFocMode = 0; //运行控制ㄏ抻贔OC模式):枚举类型:0 转速闭环;1 转矩闭环;
- ParaTable.InvRunCtlReg.uFuncEnable = 0; //外部程序控制是否允许 :=0:外部程序控制不允许;=1 外部程序控制允许;
- ParaTable.InvRunCtlReg.uSpeedRefSource = 1; //速度参考值来源:bit0: AI1; BIT1:AI2; BIT3:命令给定
- ParaTable.InvRunCtlReg.uTorqRefSource = 1; //转矩参考量来源:bit0: AI1; BIT1:AI2; BIT3:命令给定
- ParaTable.InvRunCtlReg.uFuncRefSource = 1; //外部程控参考值来源 :bit0: AI1;BIT1:AI2;BIT3:命令给定(195);
- ParaTable.InvRunCtlReg.uFuncRealSource = 1; //外部程控反馈值来源 :bit0: AI1;BIT1:AI2;BIT3:命令给定(196):
- ParaTable.InvRunCtlReg.StartMode = 0; //启动/停止方式位 :0: 外部开关启动; 1: 命令给定;控制字中给定
- ParaTable.InvRunCtlReg.DiectionSetMode = 0; //方向设置方式位 :0: 外部开关设置; 1: 命令设定;
- ParaTable.InvRunCtlReg.uStopMode = 0; //停机方式:0:停止PWM,自由停车,1:靠岸停车,按照减速曲线停车;
- ParaTable.InvRunCtlReg.SkipRiskEnable = 0; //危险带宽跳过允许位 1:跳过危险频率点;;
- ParaTable.InvRunCtlReg.CMD_FunRef = 4096; //命令设定的程控参考值;
- ParaTable.InvRunCtlReg.CMD_VdRef = 4096; //命令设定的速度参考值;
- ParaTable.InvRunCtlReg.CMD_TorqueRef = 4096; //命令设定的转矩参考值;
- FlashWrite(ParPoint,0x0,256);
- }
- void UpdataPara(int Addr,int Data)
- {
- int *ParPoint;
- ParPoint = &ParaTable.PowerParReg.uPowerType;
- *(ParPoint+Addr) = Data;
- }
复制代码
Q&A:哪位朋友可以给我讲解一下
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>