Freescale Smart Car Motor PID

Publisher:科技创客Latest update time:2021-08-27 Source: eefocusKeywords:Freescale Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

PID control is one of the most common control methods when it comes to car control. This is also a term that will not be missed in any technical report. In Freescale's XS128 series (II) PWM module, some aspects of motor control have been mentioned. It mainly talks about controlling the motor by combining PID and BANG-BANG control, that is, using BANG-BANG to control the strength and PID to control the accuracy. Let's talk about it in detail below.


Let's talk about control first. The so-called control is divided into closed-loop control and open-loop control, that is, with feedback and without feedback. Of course, PID is obviously a control with feedback. The so-called closed-loop control is to determine the size or direction of the operation according to the actual situation of the controlled quantity. Because in a single-loop control system, the controlled parameter deviates from the given value due to the effect of disturbance, thus generating a deviation, and the adjustment unit of the automatic control system compares the measured value from the transmitter with the given value, and performs proportional, integral and differential operations on the deviation generated, and outputs a unified standard signal to control the action of the actuator to achieve automatic control of temperature, pressure, flow and speed.


However, when it comes to advanced PID, there are adaptive control, fuzzy control, predictive control, neural network control, expert intelligent control, etc. Among them, I have only been involved in fuzzy control for a certain period of time. I don’t understand the others, so I won’t talk about it anymore.


The linear combination of proportion, integration and differentiation constitutes the control quantity u(t), which is called proportional, integral and differential control, or PID control for short. The proportional action P is only proportional to the deviation, the integral action I is the accumulation of the deviation over time, and the differential action D is the rate of change of the deviation.


To use a vivid metaphor, the proportion P represents the present, the integral I represents the past, and the differential D represents the future.


Specifically regarding proportion, integration and differentiation, there is a lot of information on the Internet, so I won’t go into details.


The following is about the adjustment of parameters. Reasonable adjustment of the proportional coefficient, integral coefficient and differential coefficient is the key to the normal temperature operation of the entire PID system.


The best way to find PID parameters is to start from the mathematical model of the system and calculate the parameters based on the desired response. Many times a detailed mathematical description does not exist, so it is necessary to adjust the PID parameters based on actual conditions.


Ziegler-Nichols Method


The Ziegler-Nichols method is a PID tuning method based on system stability analysis. There is no need to consider any characteristic requirements during the design process, and the tuning method is simple.


The setting value of Tyreus-Luyben reduces the effect of oscillation and enhances the stability of the system.


I won’t go into much theoretical detail, I’m too lazy to read more myself.

/****************************************************************

Code Warrior 5.0

Target : MC9S12XS128

Crystal: 16.000Mhz 

by: Pang Hui

Wuhu Lianda Freescale Project Team  

******************************************************************/


sint16 ideal_speed; //ideal speed of the car


//DIP switch selects pulse

const sint16 speed_arr1[253] = {

     37,37,37,85,85,85,37,37,37   

       

};

const sint16 speed_arr2[253] = {

     38,38,38,90,90,90,38,38,38  

};



const sint16 speed_arr3[253] = {

     40,40,40,95,95,95,40,40,40  

};


const sint16 speed_arr4[253] = {

     45,45,45,95,95,95,45,45,45

};


const sint16 speed_arr5[253] = {

     50,50,50,95,95,95,50,50,50 

};


const sint16 speed_arr6[253] = {

     37,37,37,100,100,100,37,37,37

      

};


const sint16 speed_arr7[10] = 

{

    40,40,40,100,100,100,40,40,40

};



void Motor_Change(void)

{  

   

    

    

    if(PORTA_PA0 == 0)

    {

        ideal_speed = speed_arr1[pos_ + 4];

    }

    else if(PORTA_PA1 == 0)

    {

        ideal_speed = speed_arr2[pos_ + 4];

    }                                               

    else if(PORTA_PA2 == 0)

    {

        ideal_speed = speed_arr3[pos_ + 4];

    }

     else if(PORTA_PA3 == 0)

    {

        ideal_speed = speed_arr4[pos_ + 4];

    }

    else  if(PORTA_PA4 == 0)

    {

        ideal_speed = speed_arr5[pos_ + 4];

    }

    else if(PORTA_PA5 == 0)

    {

        ideal_speed = speed_arr6[pos_ + 4];

    }

    else if(PORT_PA6 == 0)

    {

        ideal_speed = speed_arr7[pos_ + 4];

    }

    else 

    {

        ideal_speed = speed_arr1[pos_ + 4];

    }

    

    //ideal_speed = speed_arr7[pos_ + 4];

    

     speed_error = ideal_speed - pulse_count;

    

    if(speed_error >= 10) //Case 1, full acceleration

{

Set_PWM01(10000, 10000);

}

else if(speed_error > -10) //Case 2, use PID to decelerate

{

pid();

}

    else

{

Set_PWM01(0,10000); 

}       

       

}


#define kp_motor 15

#define to_motor 4//1

#define kd_motor 8//10 


sint16 speed_error; //Deviation between ideal and actual speed

sint16 pre_error; //Speed ​​PID previous speed error value ideal_speed - pulse_count

sint16 pre_d_error; //Speed ​​PID The difference between the previous speed error d_error-pre_d_error

sint16 pk; //Speed ​​PID value


void pid(void) 

{

sint16 error,d_error,dd_error;

error = ideal_speed - pulse_count;

d_error = error - pre_error;

dd_error = d_error - pre_d_error;

pre_error = error; //Store the current deviation

pre_d_error = d_error;

pk += kp_motor * d_error + ki_motor * error + kd_motor * dd_error;

if(pk >= 10000) 

{

pk = 10000;

}

else if(pk <= 0) 

{

pk = 0;

}

Set_PWM01(pk,10000);

}


The code of the photoelectric car is used here. I will go to Hangzhou for a competition next week. The depressing thing is that I have to switch from electromagnetics to photoelectrics. I wish myself good results first, hehe.


Many teams are too afraid of PID. In fact, if you really don't want to adjust the PID parameters, or don't have time to adjust them, just look at other teams and write down 3 numbers at random. It is better than open loop. For example, last month when I went to participate in the competition in Anhui Division, I did see many teams without PID. Without PID, let alone crossing the bridge, you dare not accelerate on the straight road, otherwise you will definitely die when turning. Of course, this also needs to be coordinated with reverse braking, which also needs to be written. Don't worry, it should be soon.

Keywords:Freescale Reference address:Freescale Smart Car Motor PID

Previous article:Freescale XS128 Series (III) PIT
Next article:Freescale XS128 Series (I) PLL Phase-Locked Loop

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号