View Single Post
Old 05-07-2015, 11:18 AM   #7048 (permalink)
artc
EcoModding Lurker
 
Join Date: Nov 2012
Location: West
Posts: 7
Thanks: 1
Thanked 3 Times in 3 Posts
I'm totally confused by the "PI" loop in the Cougar11B code. Can someone please help me see where I've made a mistake:

In config you have:
Kp ( from the example in the code, this is 1 or 2)
Ki ( from the example in the code somewhere between 20 and 160)


In config_pi:

v1 =Kp<<10
pi.K1=v1 (so ~2000)
pi.k2=Ki-pi.K1 (so ~ -1800)


In the main loop:

pi.error_new = current_ref - current_fb;
pi.pwm += (pi.K1 * pi.error_new) + (pi.K2 * pi.error_old);

drop the pi. and substitute for K2 (watch the i's and 1's):

pwm += (K1 * error_new) + ((Ki-K1) * error_old);
pwm += (K1 * error_new) + (Ki * error_old) - (K1 * error_old);
pwm += (K1 * (error_new - error_old)) + (Ki * error_old);

finally :

pi.error_old = pi.error_new;

I can't see an integral term in there. Normally you'd have something like

pi.total_error += pi.error_new;

but the code is just setting new to old, not accumulating.

The first term appears to be a differential term. If so, what's running is a PD controller, but the proportional term (Ki) is acting on the last error, not the current error.

Substituting some imaginary values:

pi.pwm += (2000*10) -1800*50;
pi.pwm += 20000 - 90000 = -70000;

the final signal is pi.pwm >> 16 so the output would change by 254, not unreasonable.

Empirically, the loop is stable, so I feel I must be missing something - PD is not unstable.
  Reply With Quote
The Following User Says Thank You to artc For This Useful Post:
MPaulHolmes (05-07-2015)