Designing a Buck-boost Converter with Feedback on an Arduino

A buck-boost converter is a switch-mode DC-DC converter that outputs a voltage that is either larger or lower than the input voltage. A buck-boost converter circuit has a layout that is similar to that of a buck converter and a boost converter circuit; in fact, it is a hybrid of the two.

The buck-boost converter has two distinct topologies:

  • Buck-boost converter inverting
  • Topology that is not inverted

Topology Inversion

The output voltage in an inverting topology is the polarity of the input voltage reversed.

Its arrangement is identical to that of the switch, and the output voltage is changeable dependent on the duty cycle of the switch.

The input voltage linked to the inductor charges it up and sends energy to the load while the switch is in the ON state.

The inductor is directly linked to the load in the OFF state, and the two energy storage devices in the circuit give energy to the load. As a result, our DC component is inverted yet directly proportional to the duty cycle of switching.

Because there is no connection to ground, there is a slight complexity with this circuit. However, if you’re working with separate, independent power sources like batteries, this constraint is irrelevant.

Topology that is not inverted

The output voltage is not reversed in this case, but it may be altered in either direction, meaning it can be reduced or raised. This is the commonly used generalised topology, which we shall utilise for a really fascinating circuit ahead. The buck converter and boost converter circuits are combined in this configuration.

The circuit functions as a boost converter when S1 is closed and S2 is switched. We obtain a buck converter circuit when S2 is open and S1 is oscillating. As a result, depending on our needs, we can raise or reduce our output voltage.

A flyback buck-boost converter is another type of buck-boost converter. The inductor is divided here to create a transformer. As a result, the voltage ratios of the transformer’s main and secondary windings are doubled, but there’s another benefit to this circuit: isolation (more technically, galvanic isolation). As a result, a flyback converter adjusts the output voltage while also providing isolation. This circuit is found in many low-power supply, such as phone chargers.

This circuit’s inner workings are fairly basic. The primary coil is charged when the switch is turned on, and the capacitor distributes the energy to the load. When the switch is turned off, EMF is created in the secondary coils, which causes the diode to conduct, enabling energy to flow to the load.

Constructing a Buck-boost Converter with a Feedback Circuit

The design for a basic buck-boost converter driven by PWM signals is relatively simple and comparable to boost and buck converter circuits.

When S1 is shorted, the circuit acts as a boost converter, producing 1/(1-D)Vin as the output voltage, and when S2 is shorted, the circuit acts as a buck converter, producing DVin as the output voltage.

We can construct an automated buck-boost converter circuit that automatically changes the output voltage while keeping it steady by adding feedback from the output and input terminals. In addition to the preceding design, we must utilise a voltage divider to sense input and output voltages and provide this information to the Arduino’s analogue input pins.

We utilise Arduino pins 5 and 6 to deliver PWM signals to the power MOSFET for PWM signal input. We’ll need to hack into the PWM and change Timer0’s frequency setting to 62.5 kHz PWM.

The input voltage data is sent to analogue pin 0 on the Arduino, while the output voltage is sent to analogue pin 2. Also, Schottky diodes are used to reduce diode losses; 1N5817 Schottky diodes are ideal for such applications.

As a result, we created an automated buck-boost converter that uses feedback-based input and output voltage detection to automatically stabilise the output voltage.

Code :

#define vin_pin A1
#define output_voltage_sense A2
#define input_voltage_sense A0
#define boost_pin 5
#define buck_pin 6
int raw_vin=0, raw_vout=0, raw_iout=0;
float Vout_max=13.0, Iout_max=1.0, Vout_min=11.1, Iout_min=0.1,Vin_thresold=10.5;
float Iout_sense;
float Vout_sense;
float Vin_sense;
uint8_t duty_cycle = 25;
String mode="";
bool startup=true;
unsigned int count=0;
void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);

 TCCR0B = TCCR0B & 0b11111000 | 0x01;
 analogWrite(buck_pin,255);
analogWrite(boost_pin,0);
}

void loop() {
  if(Serial.available()) {
    String data = Serial.readString();
    Vout_max = data.toInt();
    Vout_max = Vout_max/10;
    Serial.print("Vout_max= ");
    Serial.println(Vout_max);
  }
  
  for(int i=0;i<10;i++) {
raw_iout += analogRead(input_voltage_sense)-513;
raw_vin += analogRead(vin_pin);
raw_vout += analogRead(output_voltage_sense);

  }
  raw_iout=raw_iout/10;
  raw_vout=raw_vout/10;
  raw_vin=raw_vin/10;
  Iout_sense=float(raw_iout)*0.0586;
  Vout_sense=float(raw_vout)*0.046;
  Vin_sense=float(raw_vin)*0.046;
if(count>100) {
Serial.print("Vin= ");Serial.println(Vin_sense);
Serial.print("Vout= ");Serial.println(Vout_sense);
Serial.print("Iout= ");Serial.println(Iout_sense);
Serial.print("Duty cycle= ");Serial.println(duty_cycle);
Serial.print("Converter MODE : ");Serial.println(mode);
count=0;
}
if(startup==false) {
regulate(Iout_sense, Vin_sense, Vout_sense);
auto_cutoff(Iout_sense,Vin_sense, Vout_sense);
}
else {
  soft_start();
}
delay(600);
count++;
}

void regulate(float Iout, float Vin, float Vout) {
if(Vout_max<Vin) {
  mode="";
  mode="Buck mode";
  analogWrite(boost_pin,0);
  if((Iout<Iout_max && Iout>Iout_min) && (Vout<Vout_max)) {
    if(duty_cycle<250) {
    duty_cycle+=2;
    }
    analogWrite(buck_pin,255-duty_cycle);
  }
  else if((Iout>Iout_max) || (Vout>Vout_max)) {
    if(duty_cycle>2) {
    duty_cycle-=2;
    }
    analogWrite(buck_pin,255-duty_cycle);
  }
  
}
else if(Vout_max>Vin) {
  mode="";
  mode="Boost mode";
  analogWrite(buck_pin,0);
  if((Iout<Iout_max) && (Vout<Vout_max)) {
    if(duty_cycle<220) {
    duty_cycle+=2;
    }
    analogWrite(boost_pin,duty_cycle);
  }
  else if((Iout>Iout_max) || (Vout>Vout_max)) {
    if(duty_cycle>4) {
    duty_cycle-=2;
    }
    analogWrite(boost_pin,duty_cycle);
  }
  
}
}


void auto_cutoff(float Iout,float Vin, float Vout){
  if((Vout>=Vout_max) && (Iout<Iout_min) || (Vin<Vin_thresold)) {
    analogWrite(boost_pin,0);
    analogWrite(buck_pin,255);
    Serial.println("Charging Completed.");
    delay(64000);
  }
}

void soft_start() {
  if(Vout_sense<=Vout_min) {
  regulate(Iout_sense, Vin_sense, Vout_sense);
Serial.print("Vin= ");Serial.println(Vin_sense);
Serial.print("Vout= ");Serial.println(Vout_sense);
Serial.print("Iout= ");Serial.println(Iout_sense);
Serial.print("Duty cycle= ");Serial.println(duty_cycle);
Serial.print("Converter MODE : ");Serial.println(mode);
Serial.println("Soft Start Activated");
  delay(64000);
  }
  else {
  startup=false;
  }
}

Life is precious, once you realize that you have only one

KP

Help without any expectations, Give without expecting anything in return – KP

When you lose your money, You lose something. When you lose your health, You lose something important. When you lose your character, You lose everything.

KP

Helping Hands.

About the author

pondabrothers

View all posts

2 Comments

Leave a Reply

Your email address will not be published.