Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 05, 2016, 03:38:39 15:38


Login with username, password and session length


Pages: [1]
Print
Author Topic: PI/ PID, BUCK  (Read 5306 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, 06:05:45 06: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
*****
Online Online

Posts: 2018

Thank You
-Given: 514
-Receive: 477


Top Topic Starter


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

http://pcbheaven.com/projectpages/Homemade_Soldering_Station/?p=2&topic=worklog
Logged

nothing to say..
solutions
Hero Member
*****
Offline Offline

Posts: 1446

Thank You
-Given: 590
-Receive: 851



« Reply #2 on: October 04, 2012, 01:53:37 13: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, 05:20:30 05:20 »

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

Posts: 208

Thank You
-Given: 775
-Receive: 238


Oink!


« Reply #4 on: October 05, 2012, 07:43:16 07: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: 579

Thank You
-Given: 101
-Receive: 151


« Reply #5 on: October 05, 2012, 08:03:00 08: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, 08:59:41 20:59 by Gallymimu » Logged
Mr. Spock
Active Member
***
Offline Offline

Posts: 193

Thank You
-Given: 302
-Receive: 644



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

Check this :

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

Posts: 17

Thank You
-Given: 9
-Receive: 21


« Reply #7 on: October 10, 2012, 10:15:37 22: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, 08:43:45 08: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, 08:52:42 08:52 by StackPointer » Logged
Dragan
Newbie
*
 Muted
Offline Offline

Posts: 15

Thank You
-Given: 4
-Receive: 6


« Reply #9 on: October 22, 2012, 01:50:16 13: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: 579

Thank You
-Given: 101
-Receive: 151


« Reply #10 on: October 22, 2012, 04:11:27 16: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
*****
Online Online

Posts: 2018

Thank You
-Given: 514
-Receive: 477


Top Topic Starter


« Reply #11 on: October 22, 2012, 06:58:05 18: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

nothing to say..
solutions
Hero Member
*****
Offline Offline

Posts: 1446

Thank You
-Given: 590
-Receive: 851



« Reply #12 on: October 23, 2012, 02:42:43 02: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: 579

Thank You
-Given: 101
-Receive: 151


« Reply #13 on: October 23, 2012, 03:35:09 03: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: 1446

Thank You
-Given: 590
-Receive: 851



« Reply #14 on: October 23, 2012, 10:34:51 10: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: 579

Thank You
-Given: 101
-Receive: 151


« Reply #15 on: October 23, 2012, 04:22:15 16: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, 05:09:16 17:09 by Gallymimu » Logged
solutions
Hero Member
*****
Offline Offline

Posts: 1446

Thank You
-Given: 590
-Receive: 851



« Reply #16 on: October 23, 2012, 10:23:20 22: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: 579

Thank You
-Given: 101
-Receive: 151


« Reply #17 on: October 23, 2012, 10:39:20 22: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, 10:42:57 22:42 by Gallymimu » Logged
flo0319
Junior Member
**
Offline Offline

Posts: 82

Thank You
-Given: 7
-Receive: 16


« Reply #18 on: October 26, 2012, 10:04:12 22: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: 30

Thank You
-Given: 0
-Receive: 11


« Reply #19 on: April 15, 2013, 03:02:22 15: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