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 friends ..i am using pic 16F876A for controlling the output voltage of a buck converter with a 11.0592 MHz crystal oscillator. Below is the code i am using for it
The input of the buck converter is 17 v .I have given reference load voltage as 12 v. I am feeding 4 v (which i got after using a voltage divider)through channel 1 and feed-backing the load voltage through channel 0 of pic as explained in the code.But i am not getting the result.The output voltage i am getting is 10 instead of 12(desired):-(.
is it because of inaccurate Kp and Ki values????
and one more problem
When i am varying the input voltage (in range 4-5v ),i am getting an around .7-1 v variations in the output load voltage.
Plzz someone answer
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 /*unsigned int adc;*/ int T=227; int err_val=0,I_err=0; int current_duty_2=10; int Emax=6810,Emin=-6810; int Kp=22,Ki=4; int P_term=0,I_term=0; int Sum_err=0; unsigned int ADCRead(unsigned char channel) { unsigned char l_byte, h_byte; unsigned ADR; ADCON0 = 0x81 | (channel << 3); delay_us(40); ADCON0.F2 = 1; while(ADCON0.F2); l_byte = ADRESL; h_byte = ADRESH; ADR = ((h_byte <<8)|l_byte); return (ADR); } void main(void) { unsigned int Ch0,Ch1; TRISA = 0xFF; ADCON0 = 0x81; ADCON1 = 0xC0; TRISC.F1=0; PWM2_Init(20000); PWM2_Start(); PWM2_Set_Duty(current_duty_2); while(1) { Ch0= ADCRead(0); Ch1= ADCRead(1); err_val=Ch1-Ch0; P_term=(Kp*err_val)/T^2; I_err=I_err+err_val; if(I_err>Emax) I_err=Emax; else if(I_err<Emin) I_err=Emin; I_term=(Ki*I_err)/T^2; if(I_term>255) I_term=255; else if(I_term<-255) I_term=-255; 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); } }
is it because of inaccurate Kp and Ki values????
and one more problem
When i am varying the input voltage (in range 4-5v ),i am getting an around .7-1 v variations in the output load voltage.
Plzz someone answer
Last edited by a moderator: