current fed push pull DC-DC converter

i did open loop simulation in proteus.
Design Specification:-

Input Voltage: 10v-14v (varies b/w 10v to 14v)
Output Voltage:24V (constant)
Switching Frequency:50000Hz

for closed loop operation i need arduio coding, please someone help me,

I have written the code but its not working properly, concept of closed loop is depends on the input voltage the output will varries so output should be constant at 24v. by varrying the pulse width applied to the gate of the mosfet.

CODING that i have written:-

#include <LiquidCrystal.h>
#include <PWM.h>
LiquidCrystal lcd(12,11,7,6,5,4);
float duty_cycle=50;
uint32_t frequency = 50000;
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
lcd.print(“Welcome”);
InitTimersSafe();
bool success = SetPinFrequencySafe(3 , frequency);
bool success2 = SetPinFrequencySafe(9 , frequency);
if(success&success2) {
lcd.setCursor(0,1);
lcd.print(“Timer set”);
}
delay(300);
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
float outputvolt= analogRead(A3);
float volt=(outputvolt*5/1023)*5;
if(volt==24)
{
pwmWrite(3, duty_cycle);
delayMicroseconds(10);
pwmWrite(9, duty_cycle);
}
else if(volt<24)
{
duty_cycle=duty_cycle+3;
pwmWrite(3, duty_cycle);
delayMicroseconds(10);
pwmWrite(9, duty_cycle);
}
else if(volt<23)
{
duty_cycle=duty_cycle+1;
pwmWrite(3, duty_cycle);
delayMicroseconds(10);
pwmWrite(9, duty_cycle);
}
else if(volt>28)
{
duty_cycle=duty_cycle-3;
pwmWrite(3, duty_cycle);
delayMicroseconds(10);
pwmWrite(9, duty_cycle);
}
else if(volt>25)
{
duty_cycle=duty_cycle-1;
pwmWrite(3, duty_cycle);
delayMicroseconds(10);
pwmWrite(9, duty_cycle);
}
lcd.setCursor(0,0);
lcd.print(“Volt=”);
lcd.print(volt);
lcd.print(“V”);
lcd.setCursor(0,1);
lcd.print(“Dutycycle=”);
lcd.print(duty_cycle);
lcd.print("%");
}

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile:
PS Please do not Cross Post..

Welcome to the forum :slight_smile:

Please learn the basics, how to measure a voltage, what's PWM, how to drive MOSFETs, how to deal with Gnd, how to create scalable diagrams, etc.

If you have further questions remaining, come back and ask. You also may want to have a look at a PID implementation for Arduino.

I’m sure your schematic drawing software has an option to save the circuit as image instead of partial screen shots.

Sorry for the crude assessment but I see absolute beginner type code (a float will pretty much NEVER be equal to an integer value; no indentation; no pin naming but using the numbers; the ADC has a range of 1024 not 1023 as it starts at 0) for a highly advanced level project. That’s not boding well. You’ll have a LOT of learning to do.

sachinnaik:

float outputvolt= analogRead(A3);

float volt=(outputvolt*5/1023)*5;
if(volt==24)
{
pwmWrite(3, duty_cycle);
delayMicroseconds(10);
pwmWrite(9, duty_cycle);
}

This snippets sums up most of the issues with your code.

  • analogRead returns an integer 0-1023. Not a float. Floating point math takes heaps of memory and is slow.
  • divide by 1024.0 instead of 1023 (the range of 1024, and the .0 to force floating point here)
  • volt == 24 will almost always be false. You have to test for a range, e.g.
 if (abs(volt - 24) < 0.1) { // for voltage between 23.9 and 24.1V we consider it equal to 24.
  • duty_cycle is declared as float, but pwmWrite takes two byte values (i.e. range 0-255) as inputs.
  • pin numbers: give them a name, e.g.:
const byte MOSFET_PIN = 3;

pwmWrite(MOSFET_PIN, duty_cycle);

This makes your code much more readable, and if you change the pins later on for whatever reason you can simply change it at the top of your sketch instead of having to hunt down all the places where it’s used (and inevitably missing one or two).