Okada
Banned
Hi
This project is a different project and not related to my other projects and hence I have started a new thread.
This is about Buck-Boost Converter.
I need to get 325.0V DC from 150V to 300V AC.
Attached is the circuit. The DC-DC Converter Inductor and Capacitor values are not yet calculated and also the PWM frequency is not calculated.
I am just implementing the logic of synchronous Buck_Boost Converter in C code.
Please have a look and tell me if the code is correct or not. I think the buck and boost codes are inverted becuause in buck mode the duty percentage will be less than 1 and in boost mode it should be more than 1. Right ? Please confirm this.
If I get the code correct then I will calculate the PWM frequency, Inductor and capacitor values.
My Max Iout will be 6A.
Here is the mikroC PRO PIC code.
This project is a different project and not related to my other projects and hence I have started a new thread.
This is about Buck-Boost Converter.
I need to get 325.0V DC from 150V to 300V AC.
Attached is the circuit. The DC-DC Converter Inductor and Capacitor values are not yet calculated and also the PWM frequency is not calculated.
I am just implementing the logic of synchronous Buck_Boost Converter in C code.
Please have a look and tell me if the code is correct or not. I think the buck and boost codes are inverted becuause in buck mode the duty percentage will be less than 1 and in boost mode it should be more than 1. Right ? Please confirm this.
If I get the code correct then I will calculate the PWM frequency, Inductor and capacitor values.
My Max Iout will be 6A.
Here is the mikroC PRO PIC code.
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 // LCD module connections sbit LCD_RS at LATB4_bit; sbit LCD_EN at LATB5_bit; sbit LCD_D4 at LATB0_bit; sbit LCD_D5 at LATB1_bit; sbit LCD_D6 at LATB2_bit; sbit LCD_D7 at LATB3_bit; sbit LCD_RS_Direction at TRISB4_bit; sbit LCD_EN_Direction at TRISB5_bit; sbit LCD_D4_Direction at TRISB0_bit; sbit LCD_D5_Direction at TRISB1_bit; sbit LCD_D6_Direction at TRISB2_bit; sbit LCD_D7_Direction at TRISB3_bit; // End LCD module connections sbit Shutdown_AC_DC_Converter at LATC5_bit; char msg[21]; unsigned char myFlags = 0, pwm_duty = 0; double Vin = 0, previous_Vin = 600; double Vout = 0, previous_Vout = 600; double Iout = 0, previous_Iout = 30; sbit start_stop_buck_pwm_flag at myFlags.B0; sbit start_stop_boost_pwm_flag at myFlags.B1; void main() { asm clrwdt CM1CON0 = 0x00; CM2CON0 = 0x00; SLRCON = 0x00; ADCON1 = 0x80; ADCON2 = 0b10110101; ANSELA = 0x07; ANSELB = 0x00; ANSELC = 0x00; ANSELD = 0x00; ANSELE = 0x00; TRISA = 0xC7; TRISB = 0x00; TRISC = 0x00; TRISD = 0x00; TRISE = 0x00; PORTA = 0x00; PORTB = 0x00; PORTC = 0x00; PORTD = 0x00; PORTE = 0x00; LATA = 0x00; LATB = 0x00; LATC = 0x00; LATD = 0x00; LATE = 0x00; Delay_ms(180); LCD_Init(); LCD_Cmd(_LCD_CURSOR_OFF); LCD_CMd(_LCD_CLEAR); LCD_Out(1,1,"Vin = "); LCD_Out(2,1,"Vout = "); LCD_Out(3,1,"D% = "); LCD_Out(4,1,"Iout = "); PWM1_Init(2000); PWM1_Set_Duty(0); PWM1_Stop(); PWM2_Init(2000); PWM2_Set_Duty(0); PWM2_Stop(); Shutdown_AC_DC_Converter = 1; while(1) { asm clrwdt //AC Vin range 150V rms to 320V rms //equivalent DC voltages are 210.13V and 453.00V DC Vin = ADC_Read(0) * 453.0 / 1023.0; //5V Vin = 453V DC which is = 320V rms Delay_us(20); Vout = ADC_Read(1) * 325.0 / 1023.0; //2.5V Vin = 325.0V DC Delay_us(20); Iout = ((((double)ADC_Read(2) * 5.0 / 1023.0) - 2.5) / 0.1); Delay_us(20); if((previous_Vin != Vin) || (previous_Vout != Vout)) { if(Vout < 511) { //Run in boost mode if(start_stop_buck_pwm_flag == 0) { PWM1_Stop(); PWM2_Start(); LATC2_bit = 0; // LATC1_bit = 1; start_stop_buck_pwm_flag = 1; start_stop_boost_pwm_flag = 0; } /*eg: boost mode, input will be less than output required output is constant 325.0V DC So, only input voltage is monitored if Vin is 170V AC rms then DC will be 170 * 1.4142 - 2 = 238.4V DC this has to be converted to 325.0V DC So, 238.4/325.0 = 0.7336 D = 1 - 0.7336 = 0.2664 duty value to be used with PWM1_Set_Duty() library function is (255 duty value is 100%) 255 * 0.2664 = 67.9 = ~68 */ pwm_duty = 255.0 * (1.0 - floor(Vin / 325.0)); PWM2_Set_Duty(pwm_duty); } else if(Vout >= 511) { //Run in buck mode if(start_stop_boost_pwm_flag == 0) { PWM2_Stop(); PWM1_Start(); LATC1_bit = 0; LATC2_bit = 1; start_stop_boost_pwm_flag = 1; start_stop_buck_pwm_flag = 0; } /*eg: buck mode, input will be more than output required output is constant 325.0V DC So, only input voltage is monitored if Vin is 270V AC rms then DC will be 270 * 1.4142 - 2 = 379.8V DC this has to be converted to 325.0V DC So, 325.0/379.8 = 0.856 D = 0.856 (duty is always less than 1) duty value to be used with PWM1_Set_Duty() library function is (255 duty value is 100%) 255 * 0.856 = 218 */ pwm_duty = floor(255.0 * (325.0 / Vin)); PWM1_Set_Duty(pwm_duty); } LCD_Out(1,8,FloatToStr(Vin, msg)); LCD_Out(2,8,FloatToStr(Vout, msg)); LCD_Out(3,8,FloatToStr(((double)pwm_duty * 0.392), msg)); previous_Vout = Vout; } LCD_Out(4,8,FloatToStr(Iout, msg)); } }