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.

PID control of converter using PIC16f877a

Status
Not open for further replies.

vineethramesh

Newbie level 4
Newbie level 4
Joined
May 4, 2019
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
45
i have to control my converter voltage using pid controller. i am using pic16f877a for programming pid loop. can anyone help me by providing the code?
 

"Converter" means exactly what?

i am using a sepic converter. ac to dc converter. my input is 75 volt and output is 12 volt. my requirement is to control the output voltage . if i give 10 volt as reference in pid controller, i should get 10 volt as output.
 

Hi,

The type of controller you use depends on the open-loop frequency response, especially the phase angle at desired crossover frequency. Most of the times, PI controllers suffice.

PID based feedback loop are much more difficult to design than PI based ones.

You may need to say why you prefer PID control to PI.
 

sir, i need the pic 16f877a code for pi or pid control. i have to do both controllers for the academic purpose. if you have the code for pi controller please help me sir....
 

PI Controller:

Code:
int pid(int in) {
I = in*Ki + I
P = in*Kp
return I + P
}

It's that simple. Almost. You'll want protection so I can't rollover and ideally anti-windup on I as well.

You'll also need to know where you want to place your poles and zeros and understand how to map the Ki and Kp coefficients to them. I'd also want a final pole although it may come elsewhere (like an analog filter on the ADC input). But if not you'd want a single pole IIR for an additional pole.

A simulation tool like matlab or PSIM would be ideal for experimenting with this.

If TypeIII compensation is needed you'd add a D term and another single pole IIR. The IIR is quite easy as well:

Code:
int IIR1 (int in) {
out = (in - out)*ka + out
return out
}
 

Hi,

sir, i need the pic 16f877a code for pi or pid control.
It's not the way how a forum works.
We will help to solve problems with your own code, but we are not here to write code for you.

If you want someone to do your job you should consider to pay for it.
And then you have to give a full specification/requirement ....
Currently we don't know essential informations like your languuage and compiler, PID loop timing, sample frequency, inputs, outputs, data format... flow chart...

Klaus
 

sir i have the code, but when i am compiling it in MP lab ,it is showing some errors. please help me to solve it.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
float adc;
float set_ref=3;
float err_val=0,I_err=0;
float current_duty_2=50;
float Kp=1,Ki=2;
float P_term=0,I_term=0;
float Sum_err=0;
void main() {
ADCON1=0x80;
TRISA=0xFF;
TRISC.F1=0;
PWM2_Init(20000);
PWM2_Start();
PWM2_Set_Duty(current_duty_2);
while(1)
{
adc=ADC_Read(1);
err_val=set_ref-adc;
P_term=Kp*err_val;
I_err=I_err+err_val;
if(I_err>30)
I_err=30;
else if(I_err<-30)
I_err=-30;
I_term=Ki*I_err;
Sum_err=(P_term+I_term);
if(Sum_err>255)
Sum_err=255;
else if(Sum_err<0)
Sum_err=0;
current_duty_2=Sum_err;
PWM2_Set_Duty(current_duty_2);
}
}

 

Hi,

And now you want us to find out what errors the compiler shows?

The error messages give you the information what's wrong. You have to read them.

Klaus
 

main error showing is the pwm2_init. "identifier whose declaration cannot be identified" this is the error message shown.
 

The error suggests this is code written for a different compiler that has 'pwm2_init' built in as a library or that you are missing the source file that contains it.

Brian.
 

Either use the original compiler, use an equivalent library function in MPLAB or write your own function.
The name suggests it is a function to initialize the PWM registers so it should be very simple, read section 8.3.3 of the datasheet it explains everything.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top