View Full Version : PID Controller

02-09-2006, 11:27 PM
I have surfed the net a bit for PID controllers and got many results but I am not able to get the suitable info. to start with. Can anyone suggest me some link from where I can get the initial thrust to start working with PID controllers.

My basic application is speed control of dc motors. Moreover I would like to put in a PID control for line following also.

So any suggestions regarding algorithms or if someof you can provide me with a sample code for PID implementation for some simple task using AVR micrcontroller and WinAVR.

02-10-2006, 01:03 PM

The most time consuming process in making a PID control for a motor is getting the right values for kp, kd and ki. When I needed a PID for a robot I set the TIMER1 on the AVR to CTC mode generating an interrupt every 100ms. The ISR transmitted the number of ticks/direction of the left and right drive wheels during that interval to the computer via the serial port. The computer had a program running to read the data and had a PID controller which sent back values to the robot setting the PWM values on the two motors. Once I got values that worked well I just inserted the PWM function into the code on the uCs ISR and removed the transmitting code. Make sure your PID implementation is as light as possible use only integer arithmetic and avoid division.


02-11-2006, 12:39 AM
Hey I wanted some basic information about implementation, but you started with problems faced and other pit falls.

Just tell me what all I need to start off, I will tune it later .

02-11-2006, 01:30 PM
I ve worked for more than a yer on the PID controller trust me I was using a 8051rd2 phillips it is even more complicated the u will ever think about it , I was using a SPI ADC and a I2c DAC we had ordered then for US for FREE :lol: , i wrote around 1500 lines in assembly alone [ NOT INCLUDING THE ACTUAL PID ALGORITHM ] , I tried to wirite the PID algoin C then tried to cross compile but didnt worked , I had got a task based operation inplace with reading adc , writing to DAC , diaplay , and also the keyboard ,,

I could only read the ADC and then write to the DAC using a lookup table , because i had to show it was working to ext examiner , HE was not aware of lookup table thought it was a PID algo and gave me 97 out of 100 :P

Need any help , mangesh_8051@hotmail.com , ive got PCB on orcad


02-11-2006, 07:19 PM
Are you using your PID algorithm to control velocity or position? If your trying to control position one problem you will probably face while implementing a PID is that your robot wont move for ages if the error signal is small because it will take a long time to for the integral component to build up and the robot cant move unless the power to the motor exceeds a certain threshold (because of friction etc). One solution is to add a small constant value to the actuating signal which is just a little less than the signal needed to make the robot move and adding an extra factor to the signal that builds up rapidly if the robot is at a standstill (de/dt = 0) and e != 0.


02-11-2006, 09:06 PM
Hey my only intention behind PID implementation is to get a feel of it so I haven't decided which application would be the easiest to go ahead with the implementation.

Well for a line following robot, i wanted to have two microcontrollers one for motor speed control using PID control system and another micrcontroller for line following in a very strict manner using PID control system.

If this task would be too difficult then please tell me some easy application to go ahead with where I can get the feel of it as how the parameters change the response of the system.

I want to study the behavior on a very elementary PID control system so that I can, in future, implement it on complex systems.

So all your ideas are welcome !

03-28-2006, 07:44 PM
hi devpriya, i am asimov i am in delhi i am also working on pid algorithms
i am trying to make a micromouse and my chassis is ready and i am working on the algorithm my self. i am using an optical encoder for the feed back arrangement. this way i get pulses (digital data)to manuplate which makes their processing more simple and i dont have to depend any more on adcs and dac besides that i use pwm for motor speed control. using the above approach we have to solve a diffrence equation insted of a diffrential equation wich is possible on simple microcontroller . besides this if u r in loook for techinical matter on pid micros try pic micro website and search for pid pimlementation project.
i will like to know more about ur fied and work and ur approach for solving the pid problem.

03-28-2006, 10:14 PM
read a little bit of neural networks..

and go through ..the perceptron model.. it is the basic building block of neural networks..

Alot like PID but easier to understand.. I guess..


03-28-2006, 10:33 PM
I think all of us are taking the core problem in the wrong direction. Implementing PID on a microcontroller like AVR is difficult but not impossible.

If you just want to study the working of a PID controller then do one thing. Do not use any practical system like DC motor. Make a second order system of your own using capacitors and resistors. As you designd the system on your own so there is a less problem of callibration, so you can assume decent values of Kp, Ki, and Kd.

Fix a time interval which serves as your sampling interval, make sure you design an algorithm which completes its computations within this interval. Use the algorithms of differentiation and integrals meant for discrete systems, avoid mathematical computations as far as you can.

Think over it and give your inputs. We can discuss in more details.

04-16-2006, 10:01 AM
ok fnds i am putting up a link for pid implementation its on microchips site i this it should get things clear



04-17-2006, 08:48 PM
Hey people, I have an all wheel drive robot ready and all the four wheels have separate dc motors. I have attached optocouplers to all the four wheels too.

Now tell me to make the robot move straight I need to keep all the rpms same. For this purpose what can be the easiest approach and it should be descent one which doesnt get affected by loading and unloading the motor. Shall I go for a PID control system or something else ?

06-01-2006, 11:08 PM
well sorry for not resopndig to devpriya post. i had been busy with college work. i will have to figure out what to do as i ahvent worked on this problem as yet but soon i will post a message about it .

06-17-2006, 01:35 AM
i thought about the pid implementation. what i felt was now once u have made the platform with motors and encoders. the next step is to moldel ur system as a diffrence equation , here u will have to determine various system coefficients like friction coefficient for the motor and gear box, the inertia cofficient term for the whole platform(mass euivalent in the rough terms) and how exactly one determines this is still wage in my mind one way colud be to use various duration pulse widths to see the system response. i dont know if i am really right cricticism are allowed . i havent reached this stage of my micro mouse. but i guess i will figure out how to formulate the diffrence equation.