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.

PI Controller in MCU

Status
Not open for further replies.

garimella

Full Member level 5
Joined
Aug 25, 2011
Messages
255
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
3,223
Hi

I have some clarification regarding implementing PI Controller in MCU. I have seen two approaches
First one is direct translation of PI controller equations in software and second one is converting continuous domain to discrete domain and then getting corresponding difference equation, which can be put back to action. I was interested to know which one is better?
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
49,387
Helped
14,435
Reputation
29,134
Reaction score
13,225
Trophy points
1,393
Location
Bochum, Germany
Activity points
284,249
Software controller is time discrete by nature. In so far z domain implementation is the straightforward approach and more exact than "simulated" continuous PI.

In can still make sense to use popular PI parameters for controller setup and calculate parameters of time discrete transfer function internally. Most commercial digital PID controllers do.
 

gary36

Full Member level 3
Joined
Mar 31, 2018
Messages
169
Helped
0
Reputation
0
Reaction score
0
Trophy points
16
Activity points
1,535
Hi FvM
I was referring to this link in implementing PI controller in C for MCU's https://batchloaf.wordpress.com/2013/06/11/simple-pi-control-using-the-dspic30f4011/
I do not understand how the final output works. For example if we consider only proportional controller, the output=kp*error. Well this is just an open loop. closed loop TF should be kp/kp+1. I have seen similar such formulas all over the place. I do not see feedback parameter getting into the equation.
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
49,387
Helped
14,435
Reputation
29,134
Reaction score
13,225
Trophy points
1,393
Location
Bochum, Germany
Activity points
284,249
I don't understand what's the problem with this simple PI code. It's a "simulated" continuous PI, implemented as difference equation. To get the exact transfer function, you should analyze it in z domain.

What do you mean by feedback parameter? The loop is closed in hardware outside the code. The overall closed loop transfer function also depends on the controlled "plant" and the RC lowpass used to average the PWM output.
 

gary36

Full Member level 3
Joined
Mar 31, 2018
Messages
169
Helped
0
Reputation
0
Reaction score
0
Trophy points
16
Activity points
1,535
Ok I got it. Model gets closed from outside.
 

gary36

Full Member level 3
Joined
Mar 31, 2018
Messages
169
Helped
0
Reputation
0
Reaction score
0
Trophy points
16
Activity points
1,535
I was trying to implement closed loop PI controller within MCU. No inputs from field. The TF laplace domain is skp+ki/s(kp+1)+ki. I translated this to z domain using Tustin method and converted to difference equation. Assuming Kp=100 and Ki=1000 and T=0.001, i get y(n)=.0099y(n-1)+0.9901x(n)-0.0098x(n-1). The input is simply a constant 1.0 and I expect output to rise and stay at 1.0. I get same answer in simulink. But looking at difference equation, i really do not understand the meaning of x(n-1) because there are no previous values of x. Since input is constant x(n-1) will always be 1.0. So what Am i doing wrong?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top