资源描述:
《飞思卡尔智能车电磁组 程序.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include/*commondefinesandmacros*/
#include"derivative.h"/*derivative-specificdefinitions*/
#include
#include
#pragmaLINK_INFODERIVATIVE"MC9S12XS128"
#defineborder15//电感采集信号的边界值
#defineborder_back160//背后两个电感的边界值
floatcaiji_ad[9];//存储七路
2、AD采集量,caiji_ad[0]caiji_ad[8]恒等于零
inta,b,c;
unsignedchartable[16]={0x3F,0x06,0x5B,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x58,0x5e,0x79,0x71};
intangle_data,angle_pre;//舵机角度
unsignedintcaiji_flag;//采集标志
charout;
charflag_pulse;
charoutjudge_flag;
intcheck_stop;
3、intupp;
unsignedcharcha;
unsignedintposition_flag;
floatposition_q=0,position_qp=0,position_qd=0;
floatposition_h=0,position_hp=0,position_hd=0;
floatposition_jian;
floatposition_jia;
floatposition;
floatposition_cha,position_zhong;
floatpwm1_p;
floatpwm1_diff;
unsig
4、nedintjishi_flag;
floatdiff_q,diff_h;
floatSpeed_tar,Speed_cur,speed_p;
floatpwmtemp,pre_pwmtemp;
floatPID_P=200;
floatPID_I=300;
floatPID_D=0.1;
floaterror=0;
floaterror_min=-0.1;
floatlast_error=0;
floatpre_error=0;
floatbanjing;
voiddata_init()
{
unsignedinti;
for
5、(i=1;i<7;i++)
{
caiji_ad[i]=0;
}
position_flag=0;
angle_data=2600;
position=0;
angle_pre=0;
diff_q=0;
diff_h=0;
out=0;
outjudge_flag=0;
pwm1_p=2600;
pwm1_diff=0;
jishi_flag=0;
DDRA=0xff;
DDRB=0x0f;
upp=0;
}
voidSET_PLL()
{
CLKSEL=0X00;
PLLCTL=0Xe1;
SYNR=4;//设置总线频率为(
6、SYNR+1)*8MHz
REFDV=1;
PLLCTL=0x60;//怎么设置?
asmNOP;;//空操作,进行简单的延时,等待锁相环的响应
asmNOP;
asmNOP;
while((CRGFLG&0x08)==0);//时钟校正同步无执行语句?
CLKSEL=0x80;//使用PLLCLKoscclk是啥?
}
voidinitPIT()//定时中断初始化函数5MS定时中断设置
{
PITCFLMT_PITE=0;//PIT功能关
PITCE_PCE0=1;//定时器通道0使能
PITMUX_PMUX0=0;//通道
7、0
PITMTLD0=200;//200分频,在40MHzBusClock下,为200kHz。即//1/200ms=0.005ms
PITLD0=1000;//16位定时器初值设定。PITTIME*0.005MS=5ms//注意!!!可能影响舵机响应时间
PITINTE_PINTE0=1;//定时器中断通道0中断使能
PITCFLMT_PITE=1;//PIT功能开
}
voidAD_Init()
{
ATD0CTL1=0x00;//7:1-外部触发,65:00-8位精度,4:放电,3210:ch
ATD0CTL2=0x40;
8、//AFFC=1,对结果寄存器的访问将自动清除转换完成标志位
ATD0CTL3=0x80;//右对齐无符号,4个ad通道采样,NoFIFO,Freeze模式下继续转
ATD0CTL4=0x01;//765:采样时间为4个AD时钟周期,ATDClock=[BusC