PID PWM

J

Thread Starter

Joe

Hi there,

I'm trying to control a motor using PWM modulation.

I did something similar to:

dutyCycle[n] = dutyCycle[n-1] + Kp*error[n] + Kd*(error[n]-error[n-1])

Basically dutyCycle adjusts until there is no error. I tried this out and it seems to work correctly. It this correct? Or is it not a PD controller?

I did some research and it seems that there exists an incremental form of the PID. But it involves proportional, derivative and integral gains. What is the use of the integral when dutyCycle is acting as an integral sum?

Thank you
 
W

William Sturm

By adding the dutyCycle[n-1] factor, you are integrating the output. You technically have a PID loop. Most PID loops integrate the error and use an integral gain factor. You need to prevent the output from rapidly rising to 100% or falling to 0%, otherwise you have an oscillator. Your example may work with a perfect load (no lag or inertia). The problem with a PD loop is that zero error = zero output, you will always have some level of error that is proportional to your PWM duty cycle. I would suggest starting with a PD loop, and then slowly integrate the error until it is at zero.

Bill Sturm
Abbeytronics LLC
 
Top