

Stupid programmer question: where does the tread go?  Joel J [more] 



Thread Tools  Rate Thread  Display Modes 
#1




PID Control algorithm(to control PWM Duty Cycle based on Current)
Hi All,
How to arrive at a proportional gain Kp and ki in a PI control algorithm? We have to control the PWM Duty Cycle to a motor based up on the current drawn by the motor. If the desired current is 5A, & if we measure current as 6A, then how will we know what should be the duty cycle to get the desired current. Because most of the explanation on the web says that desired  measured * Kp gives the duty cycle. How to convert the error which is in terms of current to duty cycle. More over, the current is varying at different voltage levels, i.e the measured current for a 70% and 60% duty cycle at 10V is different than the measured current for 70% and 60% dty cycle at 12V. 
#2




Re: PID Control algorithm(to control PWM Duty Cycle based on Current)
The conversion units from amps to duty cycle is included in the constant values Kp and Ki.
e.g. (6A  5A) * (Kp %/A) = Kp% To get the duty cycle, add all components: (error * Kp) + (integrated error * Ki) = duty cycle. The constants Kp and Ki are usually determined experimentally, through trial and error. I would recommend tuning your motor at a constant voltage to determine Kp (start with Ki = 0), and then changing the voltage to determine Ki. 
#3




Re: PID Control algorithm(to control PWM Duty Cycle based on Current)
Hi,
Thanks for your reply. We are trying as u said tuning KP but we see lot of oscillation in the current output. Thanks 
#4




Re: PID Control algorithm(to control PWM Duty Cycle based on Current)
You might want to consider using a feedback loop instead of strictly PID.
Think of it this way  when the error drops to zero, you don't want to set your Duty Cycle to zero, you want to keep it exactly the same. New Duty Cycle = Old Duty Cycle + Error * Constant. 
#5




Re: PID Control algorithm(to control PWM Duty Cycle based on Current)
Quote:
Quote:

#6




Re: PID Control algorithm(to control PWM Duty Cycle based on Current)
Thanks Ether, I originally had it in my mind that the proportional error would be the driving force in the system, but focusing on I should work better.
I should have wrote P instead of PID. 
#7




Re: PID Control algorithm(to control PWM Duty Cycle based on Current)
Oscillations are a result of a functioning PID loop that is not properly tuned. Play with multipliers for P and I to gauge their effect, as a prelude to proper tuning. Start with 1 for P and 0 for I, and work from there.
P gives you a direction and magnitude for your correction towards setpoint. I takes care of longterm error, allowing the value to creep towards setpoint when P is small. D keeps the correction from happening too fast. 
#8




Re: PID Control algorithm(to control PWM Duty Cycle based on Current)
Quote:
Keep cutting it in half until it stops oscillating, then bring it up slowly until it just starts to oscillate. 
#9




Re: PID Control algorithm(to control PWM Duty Cycle based on Current)
Realizing if you put 3 controls engineers in a room you will get 4 different way to do tuning. One way to empirically tune a PID.
1) with the Ki & Kd gains set at 0. increase the Kp until the process value, PV, (in your case current) starts to oscillate. Do not confuse noise with oscillation, although the more noise the slower your PID will have to be. Kp will never get you to the set point unless you add a manual offset to the output. Set Kp to about half of that. 2)keeping Kp set to the value in step 1, Do the same to Ki. This will give you starting values that you can tweak to your hearts content. 3)Kd stands for destabling. Most of the time I leave it at 0. But on some systems it can be useful. Start small & work up. 4)Test your tuning by making a step change to set point and watch how it responds. Over tuned will oscillate wildly. Under tuned, it will slowly reach set point with out any over shoot. Classically tuned it will over shoot and then settle on set point with decreasing oscillation. 
#10




Re: PID Control algorithm(to control PWM Duty Cycle based on Current)
This article helped our team. Well worth reading.
http://igor.chudov.com/manuals/Servo...houtaPhD.pdf Hugh 
Thread Tools  
Display Modes  Rate This Thread 

