#include "DSP281x_Device.h"
#include "DSP281x_Examples.h"
#define LCD_DELAY_nUS(A) Delay(((((long double) A * 1000.0L) / (long double)6.666667) - 18.0L) / 14.0L)
void Delay(unsigned long loopCnt);
//'''''''''''''''''''''''''液晶显示值/'''''''''''''''''''''''''''''''''''''
extern unsigned char number[10];
extern unsigned char a,b,c,d,e, biao_zhi;
unsigned char f;
int NowSpd=0;
long Place_now_display=0;
//'''''''''''''''''''''''''''end'''''''''''''''''''''''''''''''//
//::::::::::::::::::::::::电机初始化变量定义:::::::::::::::::::::::::::::::::
char motor_OK=1, shan_qu=0;
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*::::::::::::::::::::::::::速度变量值定义:::::::::::::::::::::::::::::::::::::::::::*/
int temp=0, temp1=0, temp2=0;
long SatErr_speed=0,
OutPreSat_speed=0; //速度变量值定义
long speed_now=0, Up_speed=0, speed_error=0, Ui_speed=0;
long speed_set=0;
//:::::::::::::::::::::::::::位置环变量定义:::::::::::::::::::::::::::
long PlaceSet=0, PlaceError=0,
Place_now=0, Now_P=0,//圈数
OutPreSat_Place=0; //位置变量值定义
unsigned char PlaceSetBit=0; //位置设定标志位
//--------------------------------------------------------------------
//:::::::::::::::::::::::::空间矢量变量定义:::::::::::::::::::::::::::::::::::::::::
int extent_temp=0, extent_temp1=0, extent_temp2=0;//位置变量值定义
unsigned int extent[14]={0x3999, 0x2999, 0x6999, 0x4999, 0x5999, 0x1999, 0x3999, 0x2999, 0x6999, 0x4999, 0x5999, 0x1999, 0x3999, 0x2999 }; //区域数组定义
int extent_i=0, extent_D=0, extent_Q=0, extent_D_1=0; //扇区变量,extent_i, extent_D, extent_Q(extent_Q比extent_D超前90度
//-----------------------------------
extern const int sin_theta[1000];//外部SIN表
extern const int cos_theta[1000];//外部cos表
//cos_theta[theta]为Q15格式, ID, IQ为Q7格式1-128, Id,Iq为LONG型
int t1=0, t2=0, CMPR_temp=1250, theta=0, pwm_temp=0;// turn=0;
long Id=0, Iq=0, ID=0, IQ=0, Ualfa=0, Ubeta=0, x=0, y=0, z=0, temp_volue=0;
//===========================电流环变量定义=========================
int AD2_temp=0,Ki_Q_temp=0, Ki_D_temp=0, pwm_x=0,theta_add_60=0;
long Iu=0,Iv=0, I_d=0, I_q=0, I_ref_D=0, I_ref_Q=0, I_er_Q=0,
I_er_D=0, I_order_Q=0,
OutPreSat_IQ=0, SatErr_IQ=0, Ui_IQ=0, Up_IQ=0,
OutPreSat_ID=0, SatErr_ID=0, Ui_ID=0, Up_ID=0;
//------------------------------------------------------------------
// long adc_x0=0, adc_x1=0, adc_restul1=0, adc_restul0=0,adc_i=0;
//===========================测试变量==============================
// unsigned int TimeClash=0, timer2_x=0,timer2_x1=0, timer1_test[1000]={0},
// timer2_test[1000]={0}, timer3_test[500]={0}, //timer4_test[500]={0},
// test_i=0, ICTs=0;
unsigned int TimeClash=0;
extern unsigned int IsrTest;
//-------------------------------------------------------------------
//==========================串口程式变量定义==========================
int ReceiveTemp = 0, SciCommand_i=0, SciCommand_j=0, SetBit=0;
int SpeedSetTemp = 0, PlaceEnable=1, SpeedSetAD=0;
long PlaceSetTemp=0, SciCommand[14]={0};
//--------------------------------------------------------------------
////////////////外部中断初始化///////////////////////
void init_Xint1(void)
{
EALLOW;
PieCtrlRegs.PIEIER1.bit.INTx4=1; //中断允许
PieCtrlRegs.PIEIFR1.bit.INTx4=0; //清除中断标志
PieCtrlRegs.PIEACK.bit.ACK1=1;
XIntruptRegs.XINT1CR.bit.POLARITY=1; // 上升沿触发
XIntruptRegs.XINT1CR.bit.ENABLE=1;
EDIS;
EINT;
}
////////////////ADC初始化/////////////////////
void init_ADC(void)
{
//AdcRegs.ADCTRL1.bit.RESET = 1;
//AdcRegs.ADCTRL1.bit.RESET = 0;
AdcRegs.ADCTRL3.bit.ADCPWDN = 1;
LCD_DELAY_nUS(2000);
AdcRegs.ADCTRL3.bit.ADCBGRFDN = 3;
LCD_DELAY_nUS(2000);
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; //连续运行;
AdcRegs.ADCTRL1.bit.CPS = 0;
AdcRegs.ADCTRL2.bit.EVA_SOC_SEQ1 = 1;
AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 1;
AdcRegs.ADCTRL3.bit.ADCCLKPS = 3; //25MHZ
AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 2;
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0;
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 1;
AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 2;
}
///////////////初始化事件管理器EVA////////////////////
void Init_Evx(void)
{
//=======定时器3定时中断初始化======================
EALLOW;
EvbRegs.T3PR=9375; //一毫秒
EvbRegs.T3CON.all=0x1340; //8分频
PieCtrlRegs.PIEIER4.bit.INTx4=1;//定时器3周期中断允许
PieCtrlRegs.PIEIFR4.bit.INTx4=0;//清除中断标志位
PieCtrlRegs.PIEACK.bit.ACK4=1;
EvbRegs.EVBIMRA.bit.T3PINT=1;
EvbRegs.EVBIFRA.bit.T3PINT=1;
EDIS;
//-------------------------------------------
//========定时器1下溢中断&(svpwm)初始化====================
EALLOW;
EvaRegs.T1CON.all = 0x0842; //定时器1,连续增减,一分频, 使能,比较使能,立即重载
EvaRegs.T1PR = 1250; //30MHZ PWM
EvaRegs.CMPR1 = 0; //测试用
EvaRegs.CMPR2 = 0; //测试用
EvaRegs.COMCONA.all |= 0X9200; //使能比较操作, 使能SVPWM模式, T0下溢重载, PWM比较输出使能
EvaRegs.ACTRA.all = 0X0999; //SV正转, PWM 1,3,5低有效 & pWM 2,4,6高有效;
// EvaRegs.EXTCONA.bit.INDCOE = 1; //独立输出比较使能
// EvaRegs.GPTCONA.all |= 0x0052;
EvaRegs.T1CNT = 0;
EvaRegs.EVAIMRA.bit.T1UFINT = 1; //下溢中断允许
EvaRegs.EVAIFRA.bit.T1UFINT = 1; //清除下溢中断标志位
PieCtrlRegs.PIEIER2.bit.INTx6 = 1;//下溢中断向量允许
PieCtrlRegs.PIEIFR2.bit.INTx6 = 0;//清除下溢中断标志
PieCtrlRegs.PIEACK.bit.ACK2 = 1;
/////////////////QEP初始化////////////////
EvaRegs.T2CON.all = 0x1870;
EvaRegs.T2CNT = 0x0000;
EvaRegs.T2PR = 0xffff;
//------------------------------------------
/*////////////// EVB捕获功能初始化 /////////
EvbRegs.CAPCONB.bit.CAP45EN = 1; //使能捕捉单元4和5
EvbRegs.CAPCONB.bit.CAP45TSEL = 3; //44和5选择定时器3
EvbRegs.CAPCONB.bit.CAP4EDGE = 3; // 单元4上升和下降沿触发
EvbRegs.CAPCONB.bit.CAP5EDGE = 3; // 单元5上升和下降沿触发
EvbRegs.EVBIFRC.bit.CAP4INT = 1; //复位捕捉4标志位
EvbRegs.EVBIFRC.bit.CAP5INT = 1; //复位捕捉5标志位
EvbRegs.EVBIMRC.bit.CAP4INT = 1; //允许捕捉中断4
EvbRegs.EVBIMRC.bit.CAP5INT = 1; //允许捕捉中断5
PieCtrlRegs.PIEIER5.bit.INTx5 = 1; //允许捕捉中断4向量
PieCtrlRegs.PIEIER5.bit.INTx6 = 1; //允许捕捉中断5向量
PieCtrlRegs.PIEIFR5.bit.INTx5 = 0; //清除捕捉中断4标志位
PieCtrlRegs.PIEIFR5.bit.INTx6 = 0; //清除捕捉中断5标志位
PieCtrlRegs.PIEACK.bit.ACK5 = 1; */
//------------------------------------------
EDIS;
}
///////////////////SCI初始化//////////////////////////////////
void InitSci(void)
{
EALLOW;
//Send
SciaRegs.SCICTL1.bit.SWRESET = 1;
SciaRegs.SCICCR.bit.SCICHAR = 7; //取八位数据
SciaRegs.SCICTL1.bit.TXENA = 1; //open send
//Receive
SciaRegs.SCICTL1.bit.RXENA = 1; //open receive
SciaRegs.SCICTL2.bit.RXBKINTENA = 1; //允许接收中断
SciaRegs.SCIHBAUD = 0x01;
SciaRegs.SCILBAUD = 0xE7; //9600
PieCtrlRegs.PIEIER9.bit.INTx1 = 1; //允许接收中断
PieCtrlRegs.PIEIFR9.bit.INTx1 = 0;
PieCtrlRegs.PIEACK.bit.ACK9 = 1;
///////////////功率保护中断初始化////////////////
EvaRegs.EVAIMRA.bit.PDPINTA = 1; //PDPINTA中断允许
EvaRegs.EVAIFRA.bit.PDPINTA = 1; //PDPINTA中断标志清零
PieCtrlRegs.PIEIER1.bit.INTx1 = 1; //PDPINTA中断允许
PieCtrlRegs.PIEIFR1.bit.INTx1 = 0;
PieCtrlRegs.PIEACK.bit.ACK1 = 1; //
EDIS;
}
//-----------------------------------------------------------
///////////////////电机初始化函数(位置确定)////////////////////////////
void motor_init(void)
{
switch(GpioDataRegs.GPADAT.all & 0xE000)
{
case 0xA000: shan_qu=0; break;
case 0x2000: shan_qu=1; break;
case 0x6000: shan_qu=2; break;
邓凌佳
- 粉丝: 80
- 资源: 1万+
最新资源
- 10-【附件】-10-续签劳动合同补充协议书.docx
- 10-【附件】-14-劳动合同到期人员续签审批表.xlsx
- 10-【附件】-11-续订劳动合同意向通知书及回执.docx
- 10-【附件】-07-终止劳动合同通知书.docx
- 10-【附件】-12-劳动合同终止办理情况登记表.docx
- 10-【附件】-08-终止劳动合同证明书.docx
- 10-【附件】-13-劳动合同签收备案表.xlsx
- 11-【员工手册】-06-公司员工手册.docx
- 四旋翼无人机PID控制的MATLAB仿真.zip
- 四足机器人线性MPC控制平台Webots MATLAB.zip
- 睡眠波分析是一个开源的matlab工具箱,用于对睡眠脑电图数据中的各种波形进行评分和分析.zip
- 随机森林的MATLAB实现支持任意弱学习者,你可以定义.zip
- 它包含与我的机器学习笔记相关的所有MATLAB演示代码.zip
- 孙宏福QSM重构管道的MATLAB代码.zip
- 它是用MATLAB开发的用于建筑或暖通空调系统能源系统建模的小型软件.zip
- 提供的函数将您从实时脚本生成的latex转换为markdown,以便它可以轻松地生成带有MATLAB代码方程和图形的R.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈