vineethramesh
Newbie level 4
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?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
"Converter" means exactly what?
int pid(int in) {
I = in*Ki + I
P = in*Kp
return I + P
}
int IIR1 (int in) {
out = (in - out)*ka + out
return out
}
It's not the way how a forum works.sir, i need the pic 16f877a code for pi or pid control.
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); } }