As an Amazon Associate we earn from qualifying purchases.
This page shows how to simulate a closed-loop boost converter in Proteus using an Arduino. The circuit steps a 24V DC input up to a regulated 40V output. The Arduino reads the output voltage, then raises or lowers the PWM duty ratio to hold it near the target. The full Arduino code is below, along with an explanation of how it works and what to check if the simulation misbehaves.
How the 24V to 40V boost converter works
A boost converter has an inductor, a switch (usually a MOSFET), a diode, an output capacitor and the load. When the switch is on, current builds up in the inductor. When it turns off, the inductor current flows through the diode into the capacitor and load, which lifts the output above the input voltage.
For an ideal converter in continuous conduction, the output voltage is Vout = Vin / (1 − D), where D is the duty ratio. For 24V to 40V, the ideal duty ratio is 1 − 24/40 = 0.4, or 40%. On an 8-bit Arduino PWM scale of 0 to 255, that is a value of about 102. Real circuits lose some voltage in the switch, diode and inductor, so the duty needed in simulation is usually a bit higher than the ideal figure.
Instead of fixing the duty ratio, the Arduino adjusts it continuously. That is why the output stays close to the target when the load or input changes.
What you need in Proteus
- An Arduino Uno model. If your Proteus version does not include one, add a third-party Arduino library for Proteus.
- A MOSFET driven from digital pin 9 (the PWM output).
- An inductor, a fast diode, an output capacitor and a resistive load.
- A resistor divider that scales the output voltage down to a level the Arduino can read on analog pin A2.
- The compiled .hex file from the Arduino IDE, loaded into the Arduino part.
A boost converter is built from ordinary components, so you do not need a special converter library in Proteus. You only need the Arduino part and standard power electronics parts. The download link above contains the project files.
Arduino program
The code below sets the PWM frequency on pin 9, reads the feedback voltage on A2 and nudges the duty ratio one step at a time.
int p=0;//starting duty ratio-maximum 255
int pwmpin=9;
void setup()
{
setPwmFrequency(pwmpin,1);
analogWrite(pwmpin,p);
}
void loop()
{
int a=analogRead(A2);
//delay(1);
if(a>220)
{
p=p-1;
analogWrite(pwmpin,p);delay_for_proteus();
if(p<0)p=0;
}
if (a<205 )//&& a>150
{
p=p+1;
if(p>220)p=240;
analogWrite(pwmpin,p); delay_for_proteus();
}
}
void delay_for_proteus(void)
{
//delay(200);
}
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
*
*/
How the code works
PWM frequency
setPwmFrequency(pwmpin,1) sets the divisor to 1 on pin 9, which uses Timer1. According to the comments in the code, that gives the full base frequency of about 31 kHz. A high switching frequency lets you use a smaller inductor and capacitor. Because pin 9 uses Timer1, delay() and millis() keep working, but the Servo library will not.
Feedback and duty adjustment
The Arduino reads A2 as a value from 0 to 1023. The code then compares it with two thresholds:
- If the reading is above 220, the output is too high, so the duty value
pgoes down by 1. - If the reading is below 205, the output is too low, so
pgoes up by 1. - Between 205 and 220, nothing changes. This dead band stops the duty ratio from constantly hunting back and forth.
With a 5V reference, those readings correspond to roughly 1.0V to 1.07V at the pin. Your resistor divider should therefore scale the 40V output into that window. Check the divider values in the downloaded project against your own setup.
The empty delay function
delay_for_proteus() is a placeholder with its delay line commented out. Proteus can run slowly with a 31 kHz PWM signal and a fast control loop. If the simulation is too heavy, enabling a delay there slows how often the duty changes, which can make the run smoother.
Things to watch in the code
- Clamp before writing. In the over-voltage branch,
analogWriteruns before thep<0check. Ifpis already 0, it can be written as −1 once, which on an 8-bit timer may be treated as full duty. Moving the clamp aboveanalogWriteavoids this. - The upper limit looks odd. The line
if(p>220)p=240;jumps the duty up to 240 rather than holding it at 220. If you want a ceiling, set it to the value you intend as the maximum. A high duty ratio in a boost converter is risky because the gain rises sharply as D approaches 1. - Step size. Changing the duty by 1 per loop is gentle, but it makes the start-up ramp slow. That is normal for this simple method.
Running the simulation
- Open the project from the download and check that the Arduino part has the compiled program loaded.
- Set the Arduino clock frequency in its properties to match your board (16 MHz for a standard Uno).
- Start the simulation and watch the output voltage with a voltmeter or oscilloscope probe.
- Look for the output rising from 24V towards 40V, then settling as the duty ratio stops changing.
- Change the load resistor and confirm the Arduino pulls the voltage back toward the target.
Related projects
If you want to compare approaches, see another Arduino boost converter simulation on this site, or this boost converter using Arduino example. For higher power, there is a closed-loop boost converter with an IGBT. A similar 24V to 48V design is also available as a MATLAB Simulink closed loop model.
FAQ
Why does the simulation run slowly in Proteus?
A fast PWM signal and a tight control loop create many events for Proteus to calculate. Enable the delay in delay_for_proteus(), or lower the PWM frequency by using a larger divisor, to reduce the load.
Can I use a different PWM pin?
Yes. Pins 3, 5, 6, 9, 10 and 11 support the frequency function in this code. Pins 5 and 6 use Timer0, so changing their frequency can disturb delay() and millis(). Pin 9 or 10 is usually the safer choice.
What duty ratio should I expect for 24V to 40V?
Ideally about 40%, or roughly 102 on the 0 to 255 scale. Losses in the components push the real value higher, so the feedback loop will settle somewhat above that.
Do I need a special library to simulate a converter in Proteus?
No. You build the power stage from standard parts such as a MOSFET, inductor, diode and capacitor. You only need an Arduino model if your Proteus version does not already include one.