PID and PWM to control a motor - please help!!!

Hi,

I have written a PID routine (in C) to control current in a BLDC motor. At first i would just like to implement P control.

What i don't understand, is that if the error is negative (ie. Iactual

Ireference), the output of the controller shall be a negative. Since

the duty cycle of the PWM can only be between 0 and 100% how do you actually reduce the current in the motor through the PWM? Surely you cannot take the absoulte value of the PID result and apply it on the PWM?? Because then wouldn't that also be the same thing as saying increase the current?

Im really confused on this issue, and if anyone could help you'd be absolute lifesavers!! (This is for a Thesis you see...).

Thanks so much in advance, Jess

Reply to
Jess
Loading thread data ...

Try and other articles at this site.

Kelvin B. Hales Kelvin Hales Associates Limited Consulting Control Engineers Web:

formatting link

Reply to
Kelvin Hales

snipped-for-privacy@yahoo.com.au (Jess) wrote in news: snipped-for-privacy@posting.google.com:

PWM-schemed systems can send current through a motor in both directions using an H-bridge circuit. Often, a zero input corresponds to some medium pulse width. Also, the duty cycles valid for input might not cover the full 0-100% range, but might be allowed between two values, like 1-2ms, with 1.5 ms being centered.

Scott

Reply to
Scott Seidman

The output just saturates at 0 (and at 100%). So, for (control output

Reply to
Spehro Pefhany

As touched on by both Scott and Spehro, you need to know what your PWM driver is doing, and therefore what your PWM value means. You may have a PWM driver that can only go one direction, like the model that Spehro was talking about, you may have a PWM driver that uses an H-bridge with

50% duty cycle corresponding to 0, or you may have a PWM driver that takes a duty cycle and a direction command (essentially a sign bit -- and don't laugh, I've done it, it works well and it makes excellent sense for the particular situation I was dealing with).

_Any_ drive that you use is going to have a limited range; it's up to you to know what this range is and design your controller accordingly. If you have a PWM drive that's only positive and a motor that only has to go one direction (say to control the speed of a conveyor), then for negative errors you just set the PWM to zero, and count on friction & whatnot to slow the motor. If you have an H-bridge where 50% duty cycle applies an average drive of zero to the motor then you need to shift your control output by -50%, etc.

Reply to
Tim Wescott

Jess,

In 'professional' controllers it is very common to use the velocity form algorithm. What this means is that changes in deviation result in changes in output. In this case a negative deviation means to reduce the value of the current output by an error * PID amount.

Otherwise the position form is used. In that case a 'constant' is added to the output to bring the process variable of the loop to the setpoint. (This is done with the I and D terms off.) This eliminates the offset experienced by all P only controllers. Now you have an elevated zero on which both + and - deviation can act.

These are the tricks they don't teach you in school.

Walter.

Reply to
Walter Driedger

Actually, they did teach us all that stuff in school; but then my first (Bachelors) degree was in: 'Instrumentation and Control Engineering', and took four years!

:)

Kelvin B. Hales Kelvin Hales Associates Limited Consulting Process Control Engineers Web:

formatting link

Reply to
Kelvin Hales

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.