DC motor PID loop Info needed.

GopherT

Joined Nov 23, 2012
8,012
Anyone implent PID feedback via simple opto sensor on a DC motor?
Preferably in Assembly?
Max.
I have and it was a mess - I don't have it but we used it on a small line-following robot - controlled the left and right wheels to keep on the center.

Doing it in C was infinitely easier and actually possible to explain to someone else.

I'll look if the robotics team still has the files. The team I was helping moved to arduino Teensy since it is so small, fast (70MHz) and easy to use.
 
I have done a few projects with PID control.
There is a basic formula to use to calculate the output.
Sadly I left it behind when I changed jobs so cant remember much about it now.
I think there were 3 error variables (3 measures of input from opto) and the formula was done on these to produce a shift in output voltage.
 

GopherT

Joined Nov 23, 2012
8,012
I have done a few projects with PID control.
There is a basic formula to use to calculate the output.
Sadly I left it behind when I changed jobs so cant remember much about it now.
I think there were 3 error variables (3 measures of input from opto) and the formula was done on these to produce a shift in output voltage.

Code:
previous_error = 0
integral = 0
start:
error = setpoint - measured_value
integral = integral + error*dt
derivative = (error - previous_error)/dt
output = Kp*error + Ki*integral + Kd*derivative
previous_error = error
wait(dt)
goto start
If you check for errors on a regular interval, you can ignore the (dt), or change in time term. Just adjust the coefficients of P, I and D, Which are Kp, Ki and Kd, respectively. These terms indicate the importance of each term in correcting errors.
 

Thread Starter

MaxHeadRoom

Joined Jul 18, 2013
19,697
I think I will try using/adapting the Microchip program for the working Pendulum project they have in their library, it has PID loop Assembly and C versions.
Max.
 
Top