biswaIITH
Full Member level 4
- Joined
- Aug 23, 2014
- Messages
- 205
- Helped
- 27
- Reputation
- 54
- Reaction score
- 28
- Trophy points
- 1,308
- Location
- Hyderabad
- Activity points
- 2,923
hello folks i am controlling the output voltage of a buck converter using PIC16F876A. but i am not getting the desired output.
i am using a 11.05 mhz crystal oscillator..
input voltage of the buck converter is 20v
desired output voltage is 16v.
and switching frequency is 20khz
below is the code which is a simple pi controller implemented in pic16f876A
i am using a 11.05 mhz crystal oscillator..
input voltage of the buck converter is 20v
desired output voltage is 16v.
and switching frequency is 20khz
below is the code which is a simple pi controller implemented in pic16f876A
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); } }
Last edited by a moderator: