In this Instructable, I will show my Arduino-controlled buck/boost/inverter converter. And what means that "true" in the title, you ask? Well, you have probably already seen a tutorial where somebody just connected a transistor to the PWM output of an Arduino along with a few other parts and called that a buck/boost/inverter converter (for example here). I admit it, I also used it once in my AVR Universal Charger. It works OK when your load is not changing, but if your load rapidly changes, the controller can't react fast enough and this can lead to a very dangerous over-/under-voltage. So generally this is a very bad idea.
A much better way is to use a chip designed exactly for this purpose. Here, we will use TL494 from Texas Instruments. You can find this chip in most computer power supplies or even classical converters. But did you know that we can control the output of the chip from an Arduino? Basically our Arduino will tell the chip what output voltage and max current we want and the chip will do all the hard work, so we do not have to care about Arduino latency. Also, because this chip is analog (compared to digital Arduino), it is superior as far as accuracy goes.
So, to compare those two solutions:
Pure Arduino-base SMPS:
+ (good for educational purposes)
=> do not use this if you dont have to
Arduino + converter chip:
- a few more parts
=> ideal as bench power supply, variable output controller, battery charger
Only converter chip:
=> use for simple tasks
The cost of the extra parts is neglectable - you can get 10 pcs of TL494 from Ebay for about USD 1.30 and you probably have a few resistors laying around the house already. We will build this in a form of a shield for Arduino UNO. I will show you how to build a buck (step down), boost (step up) and flyback (step down or up, the universal one) converters. Some parameters:
Input: 3 - 41 V (it runs even lower, depends on your version)
Output: voltage depends on version, current max 5 amps (but you can really easily scale the whole build)
Cost: without the Arduino a few dollars, depends where you get the parts from
I have not found anything similar on the internet, so I am posting my own research here. But first, let's familiarize ourselves with the TL494.
Step 1: TL494 Basics
So, this chip has been around for quite a while, but I have not found many DIY tutorials using it. Maybe it is because the chip itself looks complicated, but trust me, it is not. Maybe it is old, but it is very very powerful (just look into your computers power supply - chances are really high that you will find one of those there).
If you look onto the pinout (source: datasheet), you will see a lot of IOs. But they can generally be divided into X groups:
- Supply & Clock (Vcc, GND, RT, CT, DTC, COMP) - the first two are used to provide power for the chip; the following two are timining resistor and capacitor; don't mess with the last two ones unless you are sure what are you doing. The frequency formula is f = 1 / (Ct * Rt). So, for a 100 kHz, use 1 nF and 10 kOhm. I recommend not going above this frequency, even though the chip can run at 300 kHz without a problem.
- Output stage (C1, E1, C2, E2, Vref, OutC) - there is a pair of output transistors (C1 is a collector of transistor 1, E1 is the emitter); the chip also provides 5V voltage reference (10 mA max). Finally, there is OutC (or Output Control), which determines wherever our transistor will be running in parallel or push-pull mode. We will use parallel, so hook it to ground.
- Error Amplifiers - again, two paralleled amplifiers - they are the best part about this chip. I will not go into much detail here, just a simple explanation - the chip will try to make both inputs of one amplifier (+ and -) equal (in terms of voltage). So, if we put a reference (either from potentiometer or from a DAC) of 2.5 V on the negative pin and connect the positive pin to the output of the converter, the output will be 2.5 V. If we use a 1:1 voltage divider on the positive input, we will get output of 5 V from the converter.
I recommend that you try and build this circuit first on a breadboard. When it is done, RV1 should control output voltage and RV2 current limit. If it works - you are good to go! If not, hook an oscilloscope to Ct - you should see a 100 kHz ramp wave. Also, check if your amplifiers inputs are really equal.
So we have build a simple step-down converter, but that is not anything special - now we will use an Arduino to control it!
Step 2: Digital to Analog Converter (DAC)
How we will connect an analogue circuit (TL494) to a digital Arduino? We will use a Digital to Analog Converter! Now I do not want to write what was already written, so watch this video to learn about DACs. Basically we have three options:
- RC Filter - this is the least complicated but the least accurate method. You can use two of your PWM pins, filter their output and feed it into the amplifiers of the 494, but there are two big problems - firstly, there will always be ripple, which might get amplified by the 494 and your PWM is only 8 bit, so the resolution will be limited to max_output/2^8. So if your maximal output is 40V, then the resolution will be 40/256 = 156 mV. And in real world, it will be even worse! This is fine for experiments but not that much for a real usage.
- R2R ladder - this solution does not have problems with ripple, but it consumes a lot of your IO pins and you need a lot of parts. Use it only when you are using for example an Arduino Mega with a lot of IOs.
- DAC chip - the best solution. You can get one of them really cheap, they are stable, usually have higher resolution (12 or even 16 bits) and don't need any external parts. I recommend getting 2 channel 12 bit DAC, those are reasonably priced and provide very good resolution (at 40 V, the output the resolution is 9.7 mV). Good DACs are for example LTC1454 (2x12 bits) or MCP4725 (1x12 bits)...
Step 3: Design
Here you can finally see all schematics. For real usage, I really recommend using DAC chips - they are much more accurate than anything you can build. However, if you don't need the output voltage to be that high, you can lower the value of R5/R29/R42 - you will get lower maximal output but higher accuracy (see the formula on the schematic; resolution is Vmax / (2^(DAC_bits)).
Note: on the inverter circuit, the polarity of the output stage is reversed (that's why it's called inverter, obviously)!
To set the output voltage, you can simply set the PWM duty cycle (when using RC DAC) or set the value of your DAC chip.
Step 4: Conclusion
Some general notes on building a switching regulator:
- keep all power tracks as short and as thick as possible
- try to keep all power switching components away from the Arduino and opamp
- use 1% or less tolerance resistors for measuring the current and voltage
- try to use power and digital grounds and avoid ground loops
The final build can be very accurate and reliable. I also learned a lot from it. In the future, I plan on building a smart battery charger with balancing for lithium cells based on this design. The total cost is very low, since there is no special components involved.
I hope you liked this build. This circuit can be used in many ways, from a simple voltage conversion to charging batteries, it depends just on you. If you have any comments, suggestions or questions, feel free to leave them in the comments.