基于雙核多接口的智能汽車控制系統(tǒng)設(shè)計(jì)
void Gyro_Process(void)
{
if(Gyro_Start == 1)
{
unsigned int Max,Min,i,Value;
signed long Sum;
Gyro_Data_Num = 0;
while(Gyro_Data_Num < 13)
{
Gyro_Collection();//AD轉(zhuǎn)換后的數(shù)據(jù)采集函數(shù)
}
Gyro_Start = 0;
for(i=1,Max=0,Min=0xffff,Sum
=0;i<13;i++)
{
Value=Gyro_Data_BUF[i];
Sum+=Value;
if(Max Max=Value;
if(Min>Value)
Min=Value;
}
Sum= Sum-Max-Min ;
SUM_Test = Sum;
CarAngel_V=((((signed long)(Sum/10)- (signed long)Gyro_
MidValue)*10000)>>16);
/限幅處理/
if(CarAngel_V > 0)
{
CarAngel_V = (CarAngel_V *
1013) / 1000;
}
if(CarAngel_V<0)
{
CarAngel_V = (CarAngel_V *
1004)/ 1000;
}
if(CarAngel_V>32767)
{
CarAngel_V=32767;
}
if(CarAngel_V<-32767)
{
CarAngel_V=-32767;
}
if(Gyro_Calibration_Flag == 1)
CarAngelRate = (unsigned int)
(CarAngel_V + 32767);
else
CarAngelRate = 32767;
}
}
TPM模塊在伺服電機(jī)中的應(yīng)用
MC9S08DZ60擁有8路獨(dú)立的PWM通道,可以獨(dú)立配置PWM的頻率和占空比,最高頻率為總線時(shí)鐘頻率20MHz,可以滿足對(duì)舵機(jī)和電機(jī)的控制。同時(shí)此模塊還有兩路計(jì)數(shù)器模塊,可以采集碼盤返回的電機(jī)速度值,以便用于速度閉環(huán)控制。其中電機(jī)控制中的PWM初始化如下:
評(píng)論