Electrical – PID and motor control by PWM

microcontrollermotorpid controllerpwm

I am having a potentiometer which gives an analog voltage in range of 0-5V. I am considering this POT as throttel input for motor.
If i change the pot speed increase and decrese on the basis of voltage comming from pot.
I am sensing the analog voltage from ADC of my ATMEL mcu. My MCU is working on 5V.

Let say analog input from the POT is 2V. And i am assuming that command signal is 200 RPM fpr motor.
My motor have hall sensor o/p from which i am able to read current speed of the motor which is say 120 RPM.

error = set_speed - current_speed  = 200 -120 = 80 RPM

Now i apply the PID to this error signal(80 RPM) i will get some controller o/p.

Motor speed is controlled by changing the PWM duty cycle (16 bit register).
But big question is that PWM use to control the speed of the motor. Now how to use this controller output to change the PWM duty of my MCU

How PWM relates to controller o/p signal to adjust the speed ?

Best Answer

When setting up a PID regulator you will need scaling parameters, that translates the abstract PID numbers to the real world characteristics. Similarly, you must also have max and min limits on P, I and D respectively, which must also be scaled to the output characteristics.

You will have a specified voltage that is max speed of the motor. This specified voltage has to be translated to a max duty cycle of the PWM. Perhaps it is 5V and then max is 100% duty cycle.

The scale value you have to use for the PID regulator will then be this max duty cycle. The unit will be timer ticks of the timer which you use to generate the PWM.

Also ensure you have some means to synchronize the read of the hall sensor with your PID regulator updates. You cannot regulate the system faster than you can read the sensor. The reads have to get scaled too, likely it will be easiest to scale them to the duty cycle too, so you have the same unit everywhere.

Programming-wise, it is much easier to work with this 16 bit raw timer tick value, than with for example volts, percent of duty, RPM etc.