4 switch Buck Boost Converter

Hi guys,

I need your help!

I am this project 4 switch Buck-Boost converter. So, what I am struggling with is when in buck mode, we want MOSFET 1 and 2 doing the switching (1 in positive waveform and 2 in negative waveform) MOSFET 3 is letting through voltage, and Mosfet 4 is OFF.

When in boost mode, MOSFET 3 and 4 are switching (3 in positive waveform and 4 in negative waveform) and Mosfet 1 is letting through voltage, and Mosfet 2 is OFF. We also have to decrease the Input voltage and output voltage in order for the Arduino to analogy signaling. We need 1/10th of the voltage for the signal, for example for 14V, we need 1.4V and for 5V, we need 0.5V.

I have attached below the final copy of the Buck-Boost code, any assistance will be much appreciated...


#include <Arduino.h>

// Define analog input pins for the potentiometer readings Vin, Vout and Iout
const int vin_Pot_Pin = A0;
const int vout_Pot_Pin = A1;
const int iout_Pot_Pin = A2;

// Define PWM output pins
int mosfetPin1 = 3;
int mosfetPin2 = 4;
int mosfetPin3 = 5;
int mosfetPin4 = 6;

// Define constants for minimum and maximum values
const float Vin_min_buck = 1.2; // Minimum Vin for buck mode
const float Vin_max_buck = 1.4; // Maximum Vin for buck mode
const float Vout_min_buck = 0.5; // Minimum Vout for buck mode
const float Vout_max_buck = 2.0; // Maximum Vout for buck mode

const float Vin_min_boost = 1.8; // Minimum Vin for boost mode
const float Vin_max_boost = 2.0; // Maximum Vin for boost mode
const float Vout_min_boost = 2.5; // Minimum Vout for boost mode
const float Vout_max_boost = 3.0; // Maximum Vout for boost mode

// Variables to store calculated values
float vinVoltage, voutVoltage, ioutCurrent;

void setup() {
Serial.begin(9600);

// Set pins to input or output mode
pinMode(vin_Pot_Pin, INPUT);
pinMode(vout_Pot_Pin, INPUT);
pinMode(iout_Pot_Pin, INPUT);

pinMode(mosfetPin1, OUTPUT);
pinMode(mosfetPin2, OUTPUT);
pinMode(mosfetPin3, OUTPUT);
pinMode(mosfetPin4, OUTPUT);
}

void loop() {
// Read analog values from potentiometers
int vin_duty_cycle = analogRead(vin_Pot_Pin);
int vout_duty_cycle = analogRead(vout_Pot_Pin);
int iout_duty_cycle = analogRead(iout_Pot_Pin);

// Map duty cycles to PWM range
int vin_duty_cycle_mapped = map(vin_duty_cycle, 0, 1023, 0, 255);
int vout_duty_cycle_mapped = map(vout_duty_cycle, 0, 1023, 0, 255);
int iout_duty_cycle_mapped = map(iout_duty_cycle, 0, 1023, 0, 255);

// Calculate voltages and current
vinVoltage = vin_duty_cycle_mapped * ((Vin_max_buck - Vin_min_buck) / 255.0) + Vin_min_buck;
voutVoltage = vout_duty_cycle_mapped * ((Vout_max_buck - Vout_min_buck) / 255.0) + Vout_min_buck;
ioutCurrent = iout_duty_cycle_mapped * ((Vout_max_buck - Vout_min_buck) / 255.0) + Vout_min_buck;

// Determine mode and control MOSFETs accordingly
if (vinVoltage > voutVoltage) {
// Buck mode
analogWrite(mosfetPin1, vin_duty_cycle_mapped);
analogWrite(mosfetPin2, vin_duty_cycle_mapped);
analogWrite(mosfetPin3, vin_duty_cycle_mapped);
analogWrite(mosfetPin4, 0);
} else {
// Boost mode
analogWrite(mosfetPin1, vout_duty_cycle_mapped);
analogWrite(mosfetPin2, 0);
analogWrite(mosfetPin3, vout_duty_cycle_mapped);
analogWrite(mosfetPin4, vout_duty_cycle_mapped);
}

// Print values
Serial.print("Vin Voltage: ");
Serial.println(vinVoltage);
Serial.print("Vout Voltage: ");
Serial.println(voutVoltage);
Serial.print("Iout Current: ");
Serial.println(ioutCurrent);

delay(1000);
}

Please edit your post and insert the code, using the code tags

1 Like

Please post schematics telling which MOSFETs, power supply etc You use.

1 Like

Hi, @swapnilpatel1
Welcome to the forum.

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.