I am working on designing of inductor-less dc-dc boost converter with regulated output voltage of 14V to charge 12V 4.5AH sealed lead acid battery. The converter is boost type which will step-up input voltage on its output. To regulate converter output at fixed volt PWM signals of variable duty cycle are generated with fixed 1 kHz switching frequency. It has two bjt switches which will be on or off in alternate cycle means at one time one will be on and at other second switch be on thus by varying on/off time of both output will be fixed. I have written its code in which arduino uno will receive output of converter from A1 analog pin . after sensing Vout for ADC conversion it is divided by 24 then Vout will be compare to set point of 14V in a loop. If Vout greater than 14V then duty cycle will be decreased to bring it back at 14V or vice versa. Similarly duty cycle is defined by 'value' in program which increase or decrease according to output. finally it will generate pwm signals from pin 9 and pin 10..pin 10 pwm is inverted.
But this logic is not working correctly ..any problem in the code or what. Circuit is always showing 78.4% duty cycle on LCD nor it is increasing or decreasing according to output. plz help how i can correct..
code is below
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
int P1 = 9; // PWM PIN 1
int P2 = 10; // PWM PIN 2
int value = 6; // Duty cycle
float vout; // Output voltage
// the setup routine runs once when you press reset:
long double counter = 0;
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
lcd.print("Welcome to the ");
lcd.setCursor(0,1);
lcd.print("Boost Converter");
pinMode(P1, OUTPUT);
pinMode(P2, OUTPUT);
delay(2000);
lcd.clear();
}
// the loop routine runs over and over again forever:
void loop() {
if (counter = 10000){
if (vout < 14){value += 1;} // Chechking trwshold on Output Voltage
else if (vout > 14){value -= 1;}
if (value < 0){value = 0;} // CHecking PWM duty cycle
if (value > 200){value = 200;}
counter = 0;
}
int sensorValue = analogRead(A1);
vout = sensorValue/24 ;
lcd.setCursor(0,0);
lcd.print("Vout = ");
lcd.setCursor(7,0);
lcd.print(vout);
//Serial.println(vout);
//Serial.print(vout);
// cycle and cycle value
lcd.setCursor(0,1);
lcd.print("Cycle = ");
lcd.setCursor(7,1);
lcd.print(value*0.392);
analogWrite(9, value); // PWM Generation
invertAnalogWrite(10, value);
counter++;
}
void invertAnalogWrite(int pin, int value)
{
analogWrite(pin, value);
TCCR1A = TCCR1A & ~B00110000; //switch off output B
TCCR1A |= B00110000; //switch on the B output with inverted output
}