Buck-boost converter controller

I want to make 24V to 48V buck-boost converter. when I put my controller, it doesn't work well.
I don't know what's the problem.

I use atmega 2560

This is code

#define F_CPU 16000000L
#include <avr/io.h>
#include "UART0.h"
#include <avr/interrupt.h>
#include "ADC.h"
#define set_bit(value, bit) ( _SFR_BYTE(value) |= _BV(bit) )
#define clear_bit(value, bit) ( _SFR_BYTE(value) &= ~_BV(bit) )

double adc_voltage=0,adc_current=0;
static double yv1=0.0;
static double y1=0.0;  
   
  double vout=0,Iout=0,Ioutt=0;
  double verror=0,Ierror=0;

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

  
  pinMode(A0,INPUT);
  pinMode(A1,INPUT);




  
   set_bit(DDRB, 7);                         
   set_bit(DDRB, 6);                         
   set_bit(DDRB, 5);
   TCCR1A=0;
   TCCR1B=0;
   TCNT1=0;
   TCCR1A |= (1 << WGM11) | (1 << WGM10);
   TCCR1B |= (1 << WGM13);    
   TCCR1A |= (1 << COM1B1);                 
   TCCR1A |= (1 << COM1C0)| (1 << COM1C1);  
   TCCR1B |= (1 << CS10);                   
   OCR1A = 160; 
   

}

void loop() {
  


     
 adc_voltage =analogRead(A0);

     
    vout=(adc_voltage * 5 /1024);

   
    
    adc_current = analogRead(A1);
    Iout=(((adc_current-511)*5/1023)/0.185)+0.03;
    

  


   set_bit(DDRE, 4);                      
   set_bit(DDRE, 5);                         

   
   



    
    verror= 2.5-vout;


   
    static double xv1=0.0, xv2=0.0, xv3=0.0, xv4=0.0;
    
    
   xv1=verror+(1.041)*xv2+(0.5519)*xv3+(-0.5928)*xv4;

yv1=(0.9553)*xv1+(-0.7837)*xv2+(-0.9476)*xv3+(0.7914)*xv4;



xv4=xv3;
xv3=xv2;
xv2=xv1;

Serial.print(xv1);
Serial.print("xv1   /");
Serial.print(yv1);
Serial.print("Ireference   /");
static double xv5=0.0, xv6=0.0, xv7=0.0;
   
 
   Ierror=yv1-Iout;

xv5=Ierror+(1.334)*xv6+(-0.3337)*xv7;

y1=(0.07226)*xv5+(0.002667)*xv6+(-0.0696)*xv7;


xv7=xv6;
xv6=xv5;


  
  



   double k= yv1*160/4;
   OCR1B = k-7;                                 
   OCR1C = k+7;                                
   
  
}

This is topology and I'm using voltage current control.

Leave the design job to professionals. This is neither an Arduino problem, nor a hobby project.

If you want advice from the professionals who frequent the forum, post the actual design specifications for the project. The phrase "24V to 48V buck-boost" is meaningless.

Hi, @syback0206
Welcome to the forum.

Building SMPS is a bit of a black art.
Can you please post your circuit that you have developed.
A topology and then saying you use a different voltage and current contol, basically makes the circuit you have posted not worth a lot to this thread.

A hand drawn schematic is fine, please include ALL powersupplies, component names and pin labels.

Can you please tell us your electronics, programming, arduino, hardware experience?

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

For the first time, I am designing a bidirectional DC-DC converter using 2560 atmega. This is a bidirectional converter circuit that I designed.

I am using a 24V battery and plan to keep the bus voltage at 48V. For this purpose, voltage and current control are used. Using voltage distribution, 48V is reduced to 2.5V scale and put into atmega2560, and current is inserted through current sensor.

#define F_CPU 16000000L
#include <avr/io.h>
#include "UART0.h"
#include <avr/interrupt.h>
#include "ADC.h"
#define set_bit(value, bit) ( _SFR_BYTE(value) |= _BV(bit) )
#define clear_bit(value, bit) ( _SFR_BYTE(value) &= ~_BV(bit) )

double adc_voltage=0, adc_current=0;       //Current, voltage detected by atmega 2560
static double yv1=0.0;                                   
static double y1=0.0;  
   
  double vout=0,Iout=0;
  double verror=0,Ierror=0;

void setup() {
  pinMode(A0,INPUT);
  pinMode(A1,INPUT);

   set_bit(DDRB, 7);                          //Set to B7output
   set_bit(DDRB, 6);                          //set to B6 output
   set_bit(DDRB, 5);                          //Set to B5output
   TCCR1A=0;
   TCCR1B=0;
   TCNT1=0;
   TCCR1A |= (1 << WGM11) | (1 << WGM10);
   TCCR1B |= (1 << WGM13);                                    //pwm phase collect mode top=OCR1A
   TCCR1A |= (1 << COM1B1);                                  //oc1b setting pb6 (pin 12) non-inverted mode
   TCCR1A |= (1 << COM1C0)| (1 << COM1C1);    // oc1c setting pb7 (pin 13) inverted mode
   TCCR1B |= (1 << CS10);                                        //Division rate 1 setting
   OCR1A = 160;                                                       //Triangular wave top setting, pwm frequency 50kHZ
}

void loop() { 
  adc_voltage =analogRead(A0);
     
   vout=(adc_voltage * 5 /1024);                                              //Bus voltage represented on a 2.5V scale

   adc_current = analogRead(A1);                                             

   Iout=(((adc_current-511)*5/1023)/0.185)+0.03;                 //Actual Current Flowing

   verror= 2.5-vout;                                                                     //Error entering voltage controller
 
  static double xv1=0.0, xv2=0.0, xv3=0.0, xv4=0.0;
    
  xv1=verror+(1.041)*xv2+(0.5519)*xv3+(-0.5928)*xv4;
  yv1=(0.9553)*xv1+(-0.7837)*xv2+(-0.9476)*xv3+(0.7914)*xv4;

  xv4=xv3;
  xv3=xv2;
  xv2=xv1;                                          //voltage controller

  static double xv5=0.0, xv6=0.0, xv7=0.0;

  Ierror=yv1-Iout;                                                                      //Error entering current controller
   
   xv5=Ierror+(1.334)*xv6+(-0.3337)*xv7;
   y1=(0.07226)*xv5+(0.002667)*xv6+(-0.0696)*xv7;

   xv7=xv6;
   xv6=xv5;                                         // current controller

   double k= yv1*160/4;                  // Change to Triangular Wave Top Scale

   OCR1B = k-7;                                 // duty cycle gate1 pwm 12pin, Implementing Dead Time
   OCR1C = k+7;                                 // duty cycle gate2 pwm 13pin, Implementing Dead Time
   
}

When experiments are conducted while slowly increasing the voltage on the battery side, y1 continues to increase, the LOW SIDE MOSFET continues to be closed, and the HIGH SIDE MOSFET continues to be open. When the experiment was conducted with a PWM open loop, boost and buck modes worked well.
I don't know which part of the code is wrong.

Thank you for your help!

Hi,
Please post a schematic thatt includes the 2560, NOT signal generators all over the place.

Draw a schematic including ALL your hardware and power supplies, using standard circuit symbols.

You have a 50KHz signal in your "schematic" what is it and why have you not drawn exactly what it is?
Have you actually built your project, doing it in stages to develop and over come bugs in hardware and software?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:
PS: I looks like you are using a simulator rather than experiment in the real world.

@syback0206, please do not cross-post. Threads merged.

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