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.

Digital Control in MCU

Status
Not open for further replies.

garimella

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

I have recently simulated a digital control system comprising a PI compensator for a integerator plant for tracking a sawtooth signal. Everything works fine in simulation.
Converted to difference equation and implemented the algorithm in MCU and I am experiencing a lag. internally generated sawtooth lags external signal by substantial amount. what could reason and how to fix it?
 

Hi,

No values we can calculate with.

Thus we have to guess:
* it's a timing problem
* maybe caused by the algorithm
* maybe caused by using wrong variables (float)
* or maybe caused by wrong algorithm parameters
* or maybe a programming mistake: not using timers to ensure a fixed loop calculation rate
* or maybe, or maybe, or maybe...

Klaus
 

Hi

I am going to provide details. But please have a quick look at my matlab simulation code provided. In bode plot, I see variable phase lag. I use this program to discretize(open loop TF) and implement in MCU.

Code:
t=1/2500
D=.7  // damping
w=3500 //natural frequency
a=2*D*w
b=w*w
g=tf([a b],[1 0 0])
w=feedback(g,1)
h=c2d(g,t,'tustin')
%step(w)
bode(w)
 

I think slow convergence is due to floating point variables. Tried using Fixed point arithmetic. But the output seems to be oscillating. The code is given below. All variables are Q15 format. Should I operate on Q32?

D=.84;
w=50;
kf=_Q15ftoi((w*w)*.0004);
kp=_Q15ftoi((2*D)/w);
ki=_Q15ftoi(1.0);
pi=0;
i=0;
input=_Q15ftoi(0.5);

while(1)
{
// error goes through first stage integrator. The output of integrator goes through PI compensator
error=_Q15sub(input,Output);
i=_Q15add(i,Q15_MUL(error,kf)); //Integrator stage;add,sub are microchip in-buit functions
pi=_Q15add(pi,Q15_MUL(i,ki)); //PI stage
Output=_Q15add(pi,Q15_MUL(i,kp));
printf("%f\n",(double)_itofQ15(Output)); // output oscillating- should settle at 0.5
}

_Q15 Q15_MUL(_Q15 x, _Q15 y)
{
long temp,test1,test2;
test1=x;
test2=y;
if ((test1==0x8000)&& (test2==0x8000))
{
temp=0x7fff;
}
else
{
temp=(test1*test2)>>15;
}
return(temp);
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top