资源简介
该程序用于控制高精度直流无刷陀螺电机运行,精度可达万分之一
代码片段和文件信息
#include “DSP28x_Project.h“
#include “DSP2833x_EPwm_defines.h“
#include “IQmathlib.h“
#include “C28x_FPU_FastRTS.h“
void HRPWM1_Config(int);
void HRPWM2_Config(int);
void HRPWM3_Config(int);
void HRPWM4_Config(void);//参考信号
void HRPWM5_Config(int);//驱动信号
//void HRPWM6_Config(int);
void EPwmGpio(void);
void PIDintial(void);
void start(void);
void CapGpio(void);
void SetCAPMode(void);
void Gpio(void);
void AB(void);
void AC(void);
void BC(void);
void BA(void);
void CA(void);
void CB(void);
void zero(void);
interrupt void cpu_timer0_isr(void);//速度计算
interrupt void cap_Velocity0(void); //转速的估算
interrupt void cap_Velocity1(void);//鉴相器正向加
interrupt void cap_Velocity2(void);//鉴相器反向减
#define Start1 GpioDataRegs.GPASET.bit.GPIO10
#define Start0 GpioDataRegs.GPACLEAR.bit.GPIO10
#define Start2_1 GpioDataRegs.GPASET.bit.GPIO12
#define Start2_0 GpioDataRegs.GPACLEAR.bit.GPIO12
#define reset1 GpioDataRegs.GPASET.bit.GPIO7
#define reset0 GpioDataRegs.GPACLEAR.bit.GPIO7
#define Reset1 GpioDataRegs.GPASET.bit.GPIO11
#define Reset0 GpioDataRegs.GPACLEAR.bit.GPIO11
Uint32 ij DutyFine nupdate;
Uint32 duty_2duty_1duty_3;
Uint32 period=20000;
Uint32 cankao_T=50000;//参考频率为2.5khz对应转速等于T*8
Uint32 qudong_T=3000;//驱动频率为50Khz
Uint32 temp;
Uint32 v1=0v2=0v3=0;
Uint32 counter=0;
int flag=0;
_iq KPKIKDKP1KI1KD1KP2KI2KD2;
_iq kpkikd;
_iq Error=0vError=0Error1=0Error2=0hvError=0hError1=0hError2=0;
_iq vError1=0Error1_1=0Error2_1=0hvError_1=0hError1_1=0hError2_1=0;
_iq vError2=0Error1_2=0Error2_2=0hvError_2=0hError1_2=0hError2_2=0;
_iq aError=0rError=0;
_iq aError1=0rError1=0;
_iq aError2=0rError2=0;
_iq velocity=0velocity1=0velocity2=0velocity3=0velocity4=0cankao;
_iq result=0result_hv=0;
_iq result1=0result2=0;
_iq duty_v_iq=2900duty_hv_iq=100;
Uint32 duty_v=2900duty_hv=100;
Uint16 jia1jia2jia3;
void main(void)
{
InitSysCtrl();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
//初始化Gpio
EPwmGpio();
CapGpio();
Gpio();
HRPWM1_Config(period); // ePWM1 target 15 MHz PWM (SYSCLK=150MHz) or 10 MHz PWM (SYSCLK=100MHz)
HRPWM2_Config(period); // ePWM2 target 7.5 MHz PWM (SYSCLK=150MHz) or 5 MHz PWM (SYSCLK=100MHz)
HRPWM3_Config(period);
HRPWM5_Config(qudong_T); // 驱动信号
HRPWM4_Config();
// HRPWM4_Config(cankao_T); // 参考信号
start();
PIDintial();
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;//PWM模块时基时钟同步使能禁止
SysCtrlRegs.PCLKCR1.bit.ECAP3ENCLK=1;//使能系统时钟为CAP3提供基准
SysCtrlRegs.PCLKCR1.bit.ECAP5ENCLK=1;//使能系统时钟为CAP5提供基准
SysCtrlRegs.PCLKCR1.bit.ECAP6ENCLK=1;//使能系统时钟为CAP6提供基准
EDIS;
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TINT0 = &cpu_timer0_isr;
PieVectTable.ECAP5_INT = &cap_Velocity0;
PieVectTable.ECAP6_INT = &cap_Velocity1;
- 上一篇:Solomon标准数据全部的
- 下一篇:可编程机器人,一个FLASH小游戏
评论
共有 条评论