Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

why does this simple program not work

Status
Not open for further replies.

garimella

Full Member level 5
Joined
Aug 25, 2011
Messages
260
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
3,276
Hi
I have a simple code to learn about PI controller. The set point is 1.0 and output is not converging. What is the problem?


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int main() 
 {  /* Variables*/
    double input,output,kp,error,ki,kpo,kio,T;
     input=1.00;
     kp=1;
     ki=0.1;
     output=0;
     T=1/100;
     
      while(1)
    {  
          error=input-output;
          kpo=error*kp;
          kio=kio+(error*ki*0.01);
          output=kpo+kio;
          printf("output is %f\t%f\t%f\t%f\n",error,kpo,kio,output);
    }
  }

 
Last edited by a moderator:

I don't know why it isn't working
I note that kio is not initialized and you never use T
I tried to simulate it with excel, since it is only a few lines.
output oscillates between (about) 2+x and (about) -x, where x is 0.01, 0.02, 0.03... and increases like that every iteration

I suggest you check your equations and initial values.

I changed input to 5, kp to 0.1, ki to 2, and the output converged to 5 (< 1% error) at about 265 steps
I then changed input to 3 at step 265 and the putput converged to (< 1%) at step 435

looks like changing some parameters is sufficient
 

Hi
I hooked these values kp=1 and ki=0.1 in simulink and works ok. Converges in 100s. But no random fluctuations. I also changed the values as you suggested and indeed there was convergence. Strange but why does my earlier program oscillate so much?
 

an overly simplified answer:
control theory rests on the roots of quadratic equations.
depending on the roots, you can get decay (e^-x), decay with oscillation (e^-x sin x), growth with oscillation (e^x sin x) and maybe even just growth (e^x)

the parameters you chose led to growth (albeit small) with oscillation (that's what it looked like to me)
choosing different parameters led to different result.
 

You wrote "output=kpo+kio;" instead of "output=output+kpo+kio;"
 

You wrote "output=kpo+kio;" instead of "output=output+kpo+kio;"
That's o.k. Problem is unsuitable combination of kp and ki, as already stated. kp=1 seems generally problematic. A controller with practical use has set point and process value inputs, by the way. I understand that the simplified example is modelling a plant with unity transfer function.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top