The Godfather talking
This is god damn my place! Capisci?
Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
March 28, 2024, 11:55:05 23:55


Login with username, password and session length


Pages: [1]
Print
Author Topic: PI/ PID, BUCK  (Read 8870 times)
0 Members and 1 Guest are viewing this topic.
homesh
Inactive

Offline Offline

Posts: 3

Thank You
-Given: 21
-Receive: 0


« on: October 04, 2012, 05:05:45 05:05 »

Greetings Folks,

I want to design a PI / PID controller using ATmega88PA chip.
I am sensing input voltage, input current, output voltage & output current.
I am generating PWM's of constant duty.

Now I want to include PI/ PID control for the system to step down the input voltage by using BUCK topology.

Please guide on below:-
 
How to make PI Equation and how to map that value to OCRx value.
How to integrate/ Differentiate any equation in C (do we have specific library's for doing integration/differentiation or we have to write step of codes?)

if any sample code or app note, please share.

Have A great Day.

Logged
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


« Reply #1 on: October 04, 2012, 12:45:21 12:45 »

http://pcbheaven.com/projectpages/Homemade_Soldering_Station/?p=2&topic=worklog
Logged
solutions
Hero Member
*****
Offline Offline

Posts: 1823

Thank You
-Given: 655
-Receive: 900



« Reply #2 on: October 04, 2012, 12:53:37 12:53 »

There's an AVR app note on PID.

Google is your friend...the Atmel website should be like your wife

Hey Metal  ^^^ that's like downloading a rar extraction utility that's compressed as a rar

How do you solder a soldering iron project???
Logged
homesh
Inactive

Offline Offline

Posts: 3

Thank You
-Given: 21
-Receive: 0


« Reply #3 on: October 05, 2012, 04:20:30 04:20 »

I already reffered that app note of atmel, but it was not of much help.
Logged
Magnox
Active Member
***
Offline Offline

Posts: 249

Thank You
-Given: 976
-Receive: 279


Oink!


« Reply #4 on: October 05, 2012, 06:43:16 06:43 »

How do you solder a soldering iron project???

With your home made reflow oven of course!

PID in C: http://www.control.com/thread/996485795
Logged
Gallymimu
Hero Member
*****
Offline Offline

Posts: 704

Thank You
-Given: 151
-Receive: 214


« Reply #5 on: October 05, 2012, 07:03:00 07:03 »

I would suggest you start with a PI loop and leave out the D.  PI is usually sufficient for most systems.  It's also very easy to implement.

Don't think about I in terms of having to calculate an integral.  Think of it as a summation of error over time.

each time you cycle through your loop you add the error between your measured value and your setpoint to an accumulation variable.  This is your integral error term.  then you can have something as simple as:

Kp is proportional gain
Ki is integral gain
E is error
Ei is your error accumulator
Out is output from controller
Measured_value is the output of the system or whatever your feedback signal is
setpt is your desired value

while(running)
{
Out = Kp * E + Ki * Ei;
E = Setpt - Measured_value;
Ei = E + Ei;
}

I wrote that quickly so I hope I didn't mess any of it up.  You should be able to find similar pseudo code on google.

Remember integration in this case is just summation over time which is why Ei = E + Ei is so simple!

now that pseudocode won't exactly work, you need to setup a consistent loop time and also need to watch out for things like integral windup.  A clamp on the max Ei term is usually sufficient to prevent windup.  If you don't know you can google windup but here is an okay description here: http://en.wikipedia.org/wiki/Integral_windup

« Last Edit: October 22, 2012, 07:59:41 19:59 by Gallymimu » Logged
Mr. Spock
Senior Member
****
Offline Offline

Posts: 260

Thank You
-Given: 465
-Receive: 827



« Reply #6 on: October 05, 2012, 11:51:19 11:51 »

Check this :

www.arduino.cc/playground/Code/PIDLibrary
« Last Edit: October 05, 2012, 12:41:39 12:41 by metal » Logged
TrimmedProbes
Newbie
*
Offline Offline

Posts: 12

Thank You
-Given: 11
-Receive: 30


« Reply #7 on: October 10, 2012, 09:15:37 21:15 »

Hi,
I've cobbled together some fixed point code for a PI regulator (see attached).   I've used the bi-linear transform to convert from the s-domain to the z-domain.  The polynomial coefficients for the multiply and accumulate calculation are also in there.  It won't compile but it should be mathematically correct and you should hopefully get the idea of how a PI loop is implemented in code. .  It generates a voltage reference from the error in the current.

Regards
Logged
StackPointer
Inactive

Offline Offline

Posts: 5

Thank You
-Given: 4
-Receive: 2


« Reply #8 on: October 21, 2012, 07:43:45 07:43 »

Source code from Atmel App note 221 can be very easily converted to work with AVR GCC, it is just few minutes of work, copying, pasting, and little coding to create AVR GCC library. I have created PID library from the source code and used it successfully with small RC servo modified for PID control and for controlling battery voltage with BUCK converter on my MPPT solar charger (very similar to the description in the first post, battery voltage was input value, desired value was calculated from SLA battery temperature).

Here is the medifire link to my library (it is a bit under commented) http://www.mediafire.com/download.php?y3k3u5kjwpvscqs, but I strongly recommend to try converting it by yourself Smiley

Hope it helps.
« Last Edit: October 21, 2012, 07:52:42 07:52 by StackPointer » Logged
Dragan
Newbie
*
Offline Offline

Posts: 15

Thank You
-Given: 4
-Receive: 6


« Reply #9 on: October 22, 2012, 12:50:16 12:50 »

Good day to all .

 I just wanted ti notice that Gallymimus equation for error " E = Out - Setpt;" is not correct . The correct equ will be E = Setpt - Measured_value; ( try to think if you charge integral part of the set point in your equ the error is changing , which is not allways true.

Greetings
Dragan
Logged
Gallymimu
Hero Member
*****
Offline Offline

Posts: 704

Thank You
-Given: 151
-Receive: 214


« Reply #10 on: October 22, 2012, 03:11:27 15:11 »

Good day to all .

 I just wanted ti notice that Gallymimus equation for error " E = Out - Setpt;" is not correct . The correct equ will be E = Setpt - Measured_value; ( try to think if you charge integral part of the set point in your equ the error is changing , which is not allways true.

Greetings
Dragan

Oops told you I wrote it quick... I will update.

Edit: Updated
Logged
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


« Reply #11 on: October 22, 2012, 05:58:05 17:58 »

Good day to all .

 I just wanted ti notice that Gallymimus equation for error " E = Out - Setpt;" is not correct . The correct equ will be E = Setpt - Measured_value; ( try to think if you charge integral part of the set point in your equ the error is changing , which is not allways true.

Greetings
Dragan

Could you please post a working example with explanation?
Logged
solutions
Hero Member
*****
Offline Offline

Posts: 1823

Thank You
-Given: 655
-Receive: 900



« Reply #12 on: October 23, 2012, 01:42:43 01:42 »

I think it's one of those energy saver control loops
 Grin

"Out = Kp * E + Ki * Ei"

When the error goes to zero, Out is, or goes towards, zero  Cry
Logged
Gallymimu
Hero Member
*****
Offline Offline

Posts: 704

Thank You
-Given: 151
-Receive: 214


« Reply #13 on: October 23, 2012, 02:35:09 02:35 »

I think it's one of those energy saver control loops
 Grin

"Out = Kp * E + Ki * Ei"

When the error goes to zero, Out is, or goes towards, zero  Cry


That's a clever and intuitive way to think about it.  If the error is zero there is no need to deliver energy to alter the system.
Logged
solutions
Hero Member
*****
Offline Offline

Posts: 1823

Thank You
-Given: 655
-Receive: 900



« Reply #14 on: October 23, 2012, 09:34:51 09:34 »

It would be if you didn't have "measured_value" in your pseudocode, which has no relationship to Out
Logged
Gallymimu
Hero Member
*****
Offline Offline

Posts: 704

Thank You
-Given: 151
-Receive: 214


« Reply #15 on: October 23, 2012, 03:22:15 15:22 »

It would be if you didn't have "measured_value" in your pseudocode, which has no relationship to Out

I'm not seeing the problem so maybe it isn't clear.  Out is the output of the PID controller to the Plant or system being controlled (named the Process in the diagrams).  Measured value is whatever you want to use as a feedback signal but is typically the output of the Plant or system being controlled.  The previous pseudo code was correct but was updated per Metals request (used to be setpt-out or out-setpt... can't remember)  which was consistent with a diagram like this (where out was the output of the Plant.  Measured_value did not appear in the equation):



The currently written code is consistent with a diagram like this:



Note the nomenclature is a little different but PV in the diagram would correspond to "Measured_value" and MV in the diagram would correspond to "Out"

It's all the same thing.

If that still seems wrong please paste in a version of pseudo code you think to be correct so we can understand each other.
« Last Edit: October 23, 2012, 04:09:16 16:09 by Gallymimu » Logged
solutions
Hero Member
*****
Offline Offline

Posts: 1823

Thank You
-Given: 655
-Receive: 900



« Reply #16 on: October 23, 2012, 09:23:20 21:23 »



Output is the same as MV and makes your pseudocode easier for rookies to understand.

Not everyone here is a PhD
Logged
Gallymimu
Hero Member
*****
Offline Offline

Posts: 704

Thank You
-Given: 151
-Receive: 214


« Reply #17 on: October 23, 2012, 09:39:20 21:39 »

Please post pseudocode in your preferred implementation that would have more universal appeal.

Also please refrain from being rude it's childish for a seasoned engineer.  There is no need to attack my shortcomings as I am fully aware of my education mistakes!

Personally I think the second description with separation of output and measured value is clearer since the output of the PID controller in not necessarily synonymous with the feedback signal that is often measured at the output or periphery of the process, system, plant, but as you suggest whatever is most helpful to the people asking the questions is most important.  So again if you have time to post something easier to understand that would be terrific.
« Last Edit: October 23, 2012, 09:42:57 21:42 by Gallymimu » Logged
flo0319
Junior Member
**
Offline Offline

Posts: 81

Thank You
-Given: 7
-Receive: 17


« Reply #18 on: October 26, 2012, 09:04:12 21:04 »


what you want to control? current, voltage or both?
if you want to make a controller for both, you need to use a controller in cascade.
Also, here is a nice explanation and code example for PID using an Atmega32.
http://projeneering.com/electronics_projects/elec_pid.html 
Logged
nordiceng
Newbie
*
Offline Offline

Posts: 29

Thank You
-Given: 1
-Receive: 11


« Reply #19 on: April 15, 2013, 02:02:22 14:02 »

Using of PI controller is sufficient but you should be able to tune P and I gains correctly
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC