SEPIC CONVERTER WITH MPPT

Photo of author

By Jackson Taylor

Home » Electronics Topics » Power Electronics » SEPIC CONVERTER WITH MPPT

As an Amazon Associate we earn from qualifying purchases.

CIRCUIT

YouTube video
Circuit diagram

WAVE FORMS (all signal is taken with respect ground , else will be noted )

Waveform

INPUT FROM SOLAR PANEL

Input from solar panel

GATE OF MOSFET

Gate of MOSFET

DRAIN OF MOSFET

Hardware Hack

Stop Buying New Batteries for Your Tech

Electronics are expensive, but their power sources don't have to be. Discover the simple engineering trick to recondition dead batteries and bring your gadgets back to 100% capacity.

Watch the Free Video
Drain of MOSFET

ACROSS THE INDUCTOR L1 (1mH)

Inductor L1

ACROSS THE INDUCTOR C2 (.47UF)

Inductor C2

ACROSS THE INDUCTOR L2(1mH)

Inductor L2

ACROSS THE DIODE (BYQ28E)

Diode BYQ28E

OUTPUT VOLTAGE

PROGRAM( FOR THE INPUT SOURCE IS  SOLAR PANEL)


//r=33
//V=12.54
//feed back by 10k and 1k
//adc value ---1.27V for 14
//adc=1.270/4.88mV ==260
//to get adc value =v/.053
//for 13----245
//for 13.5--254
//for 14--260
int c=0;int pwmpin=10,a;
int p=50;
int power,pp,cp;
#include <LiquidCrystal.h>
LiquidCrystal lcd(3, 4, 5, 6, 7, 8);//LCD RS-3,En-4,D4-5,D5- 6,D6-7,D7-8
int x,y;
void setup()
{
  x= analogRead(A0);
  delay(1);
  setPwmFrequency(pwmpin,1);
  analogWrite(pwmpin,p);
  lcdstart();
  Serial.begin(9600);
  delay(100);
}
void loop()
{
  int y=analogRead(5);
  Serial.println(y);
  delay(1);
  int i = (analogRead(A0)-x);
  delay(1);
  pp=y*i;
  //
  if(y>265)
  {
    p=p-1;analogWrite(pwmpin,p);delay(30);
    Serial.println("hhhh");
  }
  if(y<260)
  {
    Serial.println("less");
    p=p+3;if(p>220)p=220;
    analogWrite(pwmpin,p);
    delay(30);
    int cv=analogRead(5);
    delay(1);
    int i = (analogRead(A0)-x);
    delay(1);
    cp=cv*i;
    if(cp<pp)
    {
      p=p-8;
      //if(p>160) p=p-9; else   p=p-3;
      if(p<1)p=0;analogWrite(pwmpin,p);
      delay(30);
    }
  }
  c++;
  if(c>30)
  {
    c=0;
    int i = (analogRead(A0)-x)*36;//*12.56=45//0.045
    delay(1);if(i<0)i=0;
    float v = y;
    v=v/18;
    float w=(i*v)/1000;
    //delay(100);
    lcd.clear();
    lcd.setCursor(0, 0); lcd.print(i); lcd.print("mA");//Serial.println(w);
    lcd.setCursor(8, 0); lcd.print(v); lcd.print("v");// Print a message to the LCD.
    lcd.setCursor(0, 1); lcd.print(w); lcd.print("W");// Print a message to the LCD.
    c=0;
  }
}
void lcdstart(void)
{
  lcd.begin(16, 2);// set up the LCD's number of columns and rows:
  lcd.setCursor(0, 0);
  lcd.print("CUK converter");// Print a message to the LCD.
  //delay(500);
  //lcd.clear();
}
void setPwmFrequency(int pin, int divisor) {
  byte mode;
  if(pin == 5 || pin == 6 || pin == 9 || pin == 10) {
    switch(divisor) {
      case 1: mode = 0x01; break;
      case 8: mode = 0x02; break;
      case 64: mode = 0x03; break;
      case 256: mode = 0x04; break;
      case 1024: mode = 0x05; break;
      default: return;
    }
    if(pin == 5 || pin == 6) {
      TCCR0B = TCCR0B & 0b11111000 | mode;
    } else {
      TCCR1B = TCCR1B & 0b11111000 | mode;
    }
  } else if(pin == 3 || pin == 11) {
    switch(divisor) {
      case 1: mode = 0x01; break;
      case 8: mode = 0x02; break;
      case 32: mode = 0x03; break;
      case 64: mode = 0x04; break;
      case 128: mode = 0x05; break;
      case 256: mode = 0x06; break;
      case 1024: mode = 0x7; break;
      default: return;
    }
    TCCR2B = TCCR2B & 0b11111000 | mode;
  }
}

/**
 * Divides a given PWM pin frequency by a divisor.
 *
 * The resulting frequency is equal to the base frequency divided by
 * the given divisor:
 *   - Base frequencies:
 *     o The base frequency for pins 3, 9, 10, and 11 is 31250 Hz.
 *     o The base frequency for pins 5 and 6 is 62500 Hz.
 *   - Divisors:
 *     o The divisors available on pins 5, 6, 9 and 10 are: 1, 8, 64,
 *       256, and 1024.
 *     o The divisors available on pins 3 and 11 are: 1, 8, 32, 64,
 *       128, 256, and 1024.
 *
 * PWM frequencies are tied together in pairs of pins. If one in a
 * pair is changed, the other is also changed to match:
 *   - Pins 5 and 6 are paired on timer0
 *   - Pins 9 and 10 are paired on timer1
 *   - Pins 3 and 11 are paired on timer2
 *
 * Note that this function will have side effects on anything else
 * that uses timers:
 *   - Changes on pins 3, 5, 6, or 11 may cause the delay() and
 *     millis() functions to stop working. Other timing-related
 *     functions may also be affected.
 *   - Changes on pins 9 or 10 will cause the Servo library to function
 *     incorrectly.
 *
 * Thanks to macegr of the Arduino forums for his documentation of the
 * PWM frequency divisors. His post can be viewed at:
 *   http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235060559/0#4
 *
 */

PROGRAM( FOR THE INPUT SOURCE IS NOT SOLAR PANEL)


//feed back by 10k and 1k
//adc value ---1.27V for 14
//adc=1270/4.88 ==260
//to get adc value =v/.053
//13----245
//13.5--254
//14--260
int p=125;
void setup()
{
  setPwmFrequency(6, 1);
  analogWrite(6,p);
  Serial.begin(9600);
  Serial.println("HAII");
  //delay(5000);delay(5000);
}
void loop()
{
  int a=analogRead(2);
  delay(1);
  //Serial.println(a);
  //Serial.print("P=");
  //Serial.println(p);
  if(a>260)
  {
    p=p-1;
    analogWrite(6,p);
    if(p<0)p=0;
  }
  if (a<245 )//&& a>150
  {
    p=p+1;
    if(p>220)p=p-1;
    analogWrite(6,p);
  }
}
void setPwmFrequency(int pin, int divisor) {
  byte mode;
  if(pin == 5 || pin == 6 || pin == 9 || pin == 10) {
    switch(divisor) {
      case 1: mode = 0x01; break;
      case 8: mode = 0x02; break;
      case 64: mode = 0x03; break;
      case 256: mode = 0x04; break;
      case 1024: mode = 0x05; break;
      default: return;
    }
    if(pin == 5 || pin == 6) {
      TCCR0B = TCCR0B & 0b11111000 | mode;
    } else {
      TCCR1B = TCCR1B & 0b11111000 | mode;
    }
  } else if(pin == 3 || pin == 11) {
    switch(divisor) {
      case 1: mode = 0x01; break;
      case 8: mode = 0x02; break;
      case 32: mode = 0x03; break;
      case 64: mode = 0x04; break;
      case 128: mode = 0x05; break;
      case 256: mode = 0x06; break;
      case 1024: mode = 0x7; break;
      default: return;
    }
    TCCR2B = TCCR2B & 0b11111000 | mode;
  }
}

/**
 * Divides a given PWM pin frequency by a divisor.
 *
 * The resulting frequency is equal to the base frequency divided by
 * the given divisor:
 *   - Base frequencies:
 *     o The base frequency for pins 3, 9, 10, and 11 is 31250 Hz.
 *     o The base frequency for pins 5 and 6 is 62500 Hz.
 *   - Divisors:
 *     o The divisors available on pins 5, 6, 9 and 10 are: 1, 8, 64,
 *       256, and 1024.
 *     o The divisors available on pins 3 and 11 are: 1, 8, 32, 64,
 *       128, 256, and 1024.
 *
 * PWM frequencies are tied together in pairs of pins. If one in a
 * pair is changed, the other is also changed to match:
 *   - Pins 5 and 6 are paired on timer0
 *   - Pins 9 and 10 are paired on timer1
 *   - Pins 3 and 11 are paired on timer2
 *
 * Note that this function will have side effects on anything else
 * that uses timers:
 *   - Changes on pins 3, 5, 6, or 11 may cause the delay() and
 *     millis() functions to stop working. Other timing-related
 *     functions may also be affected.
 *   - Changes on pins 9 or 10 will cause the Servo library to function
 *     incorrectly.
 *
 * Thanks to macegr of the Arduino forums for his documentation of the
 * PWM frequency divisors. His post can be viewed at:
 *   http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235060559/0#4
 *
 */

Frequently Asked Questions

Why use a SEPIC converter for MPPT?

A SEPIC (single-ended primary-inductor converter) can step the voltage up or down while keeping the output polarity the same as the input. A solar panel’s voltage changes with sunlight and temperature, so it can sit above or below the battery or load voltage. A SEPIC handles both cases without changing the circuit. The series capacitor (C2 in this design) also blocks DC between input and output.

See also
CUK CONVERTER WITH MPPT FOR 12V BATTERY CHARGING FROM SOLAR PANEL USING ARDUINO

How does the duty cycle set the output voltage?

In continuous conduction mode, the ideal output-to-input ratio is D / (1 − D), where D is the duty cycle. A duty cycle below 50% gives a step-down, and above 50% gives a step-up. Real circuits lose some voltage in the MOSFET, diode and inductor resistance, so the measured output will be a little lower than this formula predicts. The MPPT code changes the PWM value to move the panel’s operating point along this relationship.

How does the Arduino code track the maximum power point?

The first program reads the panel voltage and current through the ADC and multiplies them to get power. It then changes the PWM value and compares the new power with the previous reading. If power went down, the code backs the duty cycle off. If the output voltage rises above the set limit, it reduces the duty cycle to protect the load. This is a simple perturb-and-observe method.

What is the second program for?

The second program is for testing the converter with a regulated supply instead of a solar panel. It has no power tracking. It only adjusts the PWM so the feedback voltage stays between two ADC limits, which gives a fixed regulated output. This is a safe way to check the gate drive, the waveforms and the feedback divider before you connect a panel.

What should I check if the output voltage is wrong?

  • Check that the feedback divider (10k and 1k here) matches the ADC values written in the code comments.
  • Look at the MOSFET gate and drain waveforms for ringing or a missing switching signal.
  • Make sure the diode and the inductor values match the circuit shown above.
  • Confirm that the PWM frequency change is applied to the pin you are actually using. Changing timer settings can affect delay() and other timing functions.

Revive Your Dead Electronics

Got a drawer full of dead gadgets or a failing car battery? Instead of paying a premium for replacements, use this simple trick to easily recondition them right from home.

See How It Works