Arduino - powerd lab bench switch mode buck-boost power supply - Page 1
Forum section: electronics / projects

author: THORs_Hand
author_rank: Contributor
timestamp: September 08, 2017, 09:32:54 am
content: Hello everyone! i saw recently on ebay a buck PSU named DPS5015 and i knew that would be very useful to have but i doesn't have 2 things very important to me, ability to work with voltages down to 5V and the boost topology.i do own everything i need to build the "ideal" PSU for me and this is what i have and what i have in mind with them:I own an arduino uno, I^2C display with 4 integrated buttons on the display module (working on I^2C as well with another adress) and a dead PSU from an old computer (everything is fine except the input caps) and i want to do the following:Build a buck-boost SMPS controlled with that arduino (The PWM capability as far as i know can reach into the order of MHz utilizing the so-called timer1 function) i want that PSU to be able to work with voltages down to 5V (i plan to make this thing portable by using a 5V 2.1A but i also want to use it with voltages up to 20V) i want to control the voltage from a minimum of 1V up to 30V (preferably 50V) with current limiting capability (1mA to 5-10A) i want the arduino to have a voltage feedback to control the duty cycle (to maintain a stable voltage) and also i want to control everything using that 2x16 char. display with the 4 integrated push-buttons via i^2C (link here ->https://www.acmesystems.it/DAISY-24)i need your helpto make this happen, my biggest problem is the coding, i don't know to code in arduino almost at all, the schematic i could do it. but the code is my biggest problem (and the voltage feedback part for the arduino, as far as i know it has an input limit on the analog pins of 5V, maybe a voltage divider with maximum output of 5V at the max. voltage?)

author: Ian.M
author_rank: Super Contributor
timestamp: September 08, 2017, 11:32:05 am
content: Quote from: THORs_Hand on September 08, 2017, 09:32:54 am"I'm a butcher but if I knew how the brain worked I could be a brain surgeon"The guys that do this for a living have typically done a four year university degree in electronics and embedded systems programming, then worked their way up to design engineer through a succession of roles starting at the bottom as the team 'gofer' - effectively an informal apprenticeship. A few then make the jump to lead design engineer with ultimate responsibility for their projects and their own team to manage.You've got a *LONG* road ahead of you. Here's a rough roadmap:Learn C (to ANSI C99 standard).Learn how to code in C on the Arduino platform without letting the predefined stuff get in the way.Lean how to write realtime code for a MCU that doesn't use a RTOS.Learn the ATmega328P MCU in detail.Learn and experiment with switched mode power supply design in detail, to the point where you can successfully build a Buck-Boost SMPSU out of discretes, OPAMPs and Comparators., with no dedicated SMPSU control chips, then test it for stability, accuracy, load step response etc, and redesign the control loop to optimise it.Experiment with driving inductive loads with an ATmega328P generated PWM,and closing the control loop with ADC feedback.Breadboard a SMPSU with an Atmega328P in the loop and develop your software.Finalise your hardware design, order PCBs, build and debug itIts a long road and you are certain to let the magic smoke out of a lot of parts. When testing higher power SMPSU circuits, for %DEITY%'s sake wear safety glasses - various parts can explode violently expelling shrapnel that can easily cause eye damage.If you've got a day job (or other form of real life) limiting the time you can spend at the keyboard and bench you can probably learn enough to do this in a few years, if you don't get diverted along the way. Don't expect to have spare time for other hobbies/interests. You still wouldn't have the deep engineering background the pros have.A design that doesn't put the Arduino in the switched mode control loop (so all it has to do is to change setpoints of digital potentiometers connected to a SPMSU controller chip, and monitor and display output voltages and currents), is considerably simpler on the software side, and the extra hardware complexity is manageable.

author: THORs_Hand
author_rank: Contributor
timestamp: September 08, 2017, 12:05:53 pm
content: Yes, i know what are the steps to finish the project myself, the problem is that i need that project now and i simply don't have time to learn all that, i have a job and this takes most of my time wake-up->drink coffee -> go to job -> work -> home -> do your stuff home -> sleep and over again. i'm sure you know the daily schedule, problem with this is that i don't work in electronics domain or anything related to it. this is why i asked for help on this forum, maybe in 1-2 weekends i could build the circuit entirely, but coding it having in mind how much i (don't) know about programming in arduino is taking this project, months even years to complete. if i'd had the code i could do it much much faster :\

author: Ian.M
author_rank: Super Contributor
timestamp: September 08, 2017, 12:26:31 pm
content: Quote from: THORs_Hand on September 08, 2017, 12:05:53 pmThe problem is the code has to be custom written for your hardware and its a fairly big project to develop and test, with a lot of bench time involved, so unless you can find an open source Arduino based SMPSU project that already has working code and hardware, and copy their hardware design, or are prepared to pay commercial rates to commission the code from an experienced developer and ship them prototype hardware to test it on, you are S.O.L.I'm not even going to suggest seeking participants for a collaborative project as from your comment:Quote from: THORs_Hand on September 08, 2017, 09:32:54 amit seems your knowledge of electronics may be a little on the sketchy side - if you cant with confidence design level shifting and signal scaling and limiting circuits without outside assistance, there is no way you are ready to tackle the hardware design*of even a conventional SMPSU with analog controls, so unless you propose to be the 'deep pockets' and board assembler, you wouldn't be bringing enough to any prospective team to make it worth their while.Copying a SMPSU chip manufacturer's reference design doesn't make you a designer.

author: THORs_Hand
author_rank: Contributor
timestamp: September 08, 2017, 12:45:44 pm
content: That's your opinion ant that's ok, but i took it logical on that section from my post, i know i need a feedback that shifts the for example 0-30V output to 0-5V feedback voltage, so what could be the simplest way? voltage divider, you divide the voltage for example in 6 and the feedback you multiply in code with 6, so arduino knows that there's 30V although the feedback is 5V (translated in a value from 0 to 1024) and if the voltage is higher or lower then 30V arduino will adjust the duty cycle to achieve the desired voltage. there are some simple code parts that i need:i2c displayi2c push button controldriver code (for voltage and current)feedback codeand this is basically it. if i knew to use variables with a ton of online help i could do it myself but it's just way too hard to do it on my own. again, this is why i asked for help.. i don't need to do it on a stand alone AtMega 328P, i don't need everything produced on a PCB (although i would make the circuit like an arduino shield) i don't even need it to be tested 1.000.000 times, if it does what it has to okay. i use it for myself anyway.Why i can't just do it using online help like mentioned above? because variables are too different from project to project, i need to read and adapt each variable and line of code for my project. it's just over my knowledge.And more importand, it's not fair to laugh at me because i don't know to do fancy analog feedback circuits, i want to keep it simple, arduino can do all the work by itself, why not just use it's capability?

author: Ian.M
author_rank: Super Contributor
timestamp: September 08, 2017, 01:16:54 pm
content: Quote from: THORs_Hand on September 08, 2017, 12:45:44 pmIts anything but simple. Control theory, required to design a stable PSU that can cope with sudden load current changes, is usually at least two full course modules of an electronics degree with a fair bit of hard maths.Getting the MCU out of the loop avoids the need for that (by passing it off to the designers of the SMPSU control chip you are going to use and following their 'cookbook recipe' for a stable feedback loop), but then you have to figure out stuff like how to provide the control chip with an equivalent circuit to the resistors that set its output current and voltage, when those resistors may have up to 30V on one end of them, but your DAC or digital potentiometer is limited to 0 to 5V levels. Yes there are higher voltage DACs and digital potentiometers, but ones that can go up to 30V are vanishingly rare and expensive, and fancier control chips that may have low voltage ground referenced inputs for their voltage and current setpoints are usually in deeply novice unfriendly leadless SMD packages that you won't even be able to solder without either a reflow oven or a hot air SMD rework station with a board preheater.If you cant string together other people's chunks of code on the Arduino platform, that is optimised to support less experienced 'maker' programmers by making it easy to package and distribute hardware drivers for all sorts of chips and devices for reuse, you are S.O.L, as what incentive will anyone have to write the whole code for you? There are no alternatives or shortcuts - if you want to create your OWN successfully Arduino based project that isn't a slavish copy of someone else's one, you need to be competent at coding in C, so start learning it. Its probably easiest to learn C on a PC - using any ANSI C99 compliant compiler, writing console mode programs and following a traditional C book likeK&R2nd Ed. If you are planning to transition to embedded stuff, avoid getting bogged down in Windows GUI programming or the filesystem libraries.Your best way forward for now is to set aside your dream PSU and hack together a 'good enough' PSU or set of PSUs for now to support developing your hobby, while looking for a decent quality second hand lab grade PSU within your budget, even if it needs some TLC to get it working to its original specifications. An ATX PSU breakout board that adds safe current limiting or fusing to all the rails, and brings them out to binder posts would be a good start. Don't hack the actual ATX PSU - unless you start with a new high quality one, they tend to go bad so the ability to simply plug in a replacement is essential.Also if you have any interest in linear circuits you'll need a low noise linear adjustabe supply. Start from a 100VA 20V-0-20V or 18V-0-18V mains transformer and build a dual output LM317 + LM337 variable PSU. Initially it wont have adjustable current limiting. It will need a good heatsink and possibly fan cooling. Use a case with a replaceable front panel because you will be doing a lot of mods as you add various features, and try to keep it modular e.g. bridge rectifier, fuses, reservoir caps and regulator ICs on one board, initially with their ADJ terminals hooked to front panel pots, but later you can add in adjustable current limit control board between the pots and the regulators. If you plan to add digital metering, allow space in the case for an auxiliary transformer to power the meters and any logic (and maybe also to power fixed voltage 5V and 3.3V outputs on the front panel).

author: THORs_Hand
author_rank: Contributor
timestamp: September 08, 2017, 01:36:46 pm
content: Thanks for the advice, but i'm not "SOL" yet, i do have solutions for this problem. it's just my big ego wanting some nice features quality PSUs have (a digital display looks better then a 7 segment one) before letting go my ego i'll try for 2-3 weekends doing all i can and i know at this very moment to put together a PSU like the one described in this post. later this evening i will come with a schematic (off the web but modified to suit my needs) and post it here, after that i will begin to build a code and keep updating this post every weekend. if i can do it, good for me, if not. i'll just go back using crap wall adapters as my PSUs) (joking) i want to clarify something. i know a PSU requires a ton of work and knowledge, especially if you want a completly embeeded one that only uses 1 board and does everything (display, control, adjustments) i've been watching dave's project on something similar since the first video and i've seen how hard it is, this is the huge reason why i just use an arduino that controls some tranzistors and a fancy display) i could use a buck-boost circuit or IC off the web and just go with that, or buy the DPS5015 and get along its downsides but no, i want to do it myself, how i want. i'm just too idiot to code) i work in a bank at the moment, in 2-3 months i will begin to make a IT course, after that a job in IT and in the medium future a college, like a proprer one. i want to be prepared in advance for it, and i want to increase my ego doing all sorts of projects. no pun intended, i'm just being honest. (to clarify, i never wanted to work in a bank, i just landed here from highschool bench)

author: Ian.M
author_rank: Super Contributor
timestamp: September 08, 2017, 01:55:56 pm
content: Quote from: THORs_Hand on September 08, 2017, 01:36:46 pmWell you are trying to take far too big a bite at once here. Start with something smaller e.g. measuring voltage up to 30V and current up to 2A with an Arduino. You'll soon discover the limitations of the built in 10 bit ADC - with only 1024 counts between 0 and 5V, the best you can get for a 30V input range is 0.3V resolution, so it isn't even good enough for a three digit display. You'll find you need to use an external 16 bit ADC to get enough resolution to support four digit displays. e.g. a voltage display to 0.01V (2 digits after d.p.) and current to 1mA (3 digits after d.p.)N.B. Novices working with an Arduino or other MCU and currents and voltages higher than a USB port can provide should probably invest in a USB optoisolator to avoid frying the USB ports of their PC.If you intend to go into I.T. you will be crippled if you cant code. Once you know ANSI C, all other procedural programming languages are fairly simple to grasp so you might as well start there. If you really have ZERO aptitude for coding then don't consider a career in I.T. unless you want to end up as a level 1 customer 'helldesk' assistant or as a cable monkey with little opportunity for career advancement and professional development.

author: Avacee
author_rank: Unknown
timestamp: September 08, 2017, 03:39:03 pm
content: Quote from: THORs_Hand on September 08, 2017, 12:45:44 pmI'm not laughing as I admire your enthusiasm and goal but you can't simply use the arduino for the control as it is simply not fast enough.An arduino is not able to read a pin, process it and alter the voltage on another pin quickly enough to be stable - whilst also monitoring other inputs and displaying the information.There is no magic code that will work as the arduino isn't fast enough.I speak from experience here from having made an arduino controlled power supply and having to learn the analog circuitry - and the learning was fantastic and everyone here was very helpful.I appreciate this isn't the answer you are looking for but such code does not exist and you will have to use analog circuitry controlled by the arduino.May I make an suggestion that will work as a good stepping stone: Make a DC Load controlled by an Arduino.The analog circuitry to learn is simpler and will provide a good foundation.The code to learn is simpler and will provide a good foundationThe added benefit of this is you can then use this DC Load to test your power supply - with no reliable load how will you test your power supply?

author: rstofer
author_rank: Super Contributor
timestamp: September 08, 2017, 04:47:13 pm
content: Everything that can be done with an Arduino has been done, including a start toward controlling an SMPS.I didn't watch the entire video for two reasons: First, the subject isn't interesting (to me) and second, there should be a law against posting videos shot with a cell phone or other handheld camera.One thing the author does is show where in the ATmega328 datasheet to find the various control registers and how to pick a configuration. There's a lot to learn from this video. There's a lot of RTFM going on!I don't think the author comes up with an answer to the problem of a lack of timers in the ATmega328, his project is not complete. But it's a start!Now, substitute a chip with more timers and you might have a start. I'm not going to recommend a chip because I haven't done the research. There are other references for that. Note that Microchip makes a living out of devices for power control. I don't know if they are adequate.The C programming is fairly light because all the author is doing is setting up the contents of a few registers. Well, sure, he gets the 100 kHz waveform from 2 pins but he is a long way from finished. Big things are missing, like the feedback loop.Still, searching Google is always a good first step. I almost ALWAYS copy the work of others even if I eventually start over. There is something to learn from others who have gone before.

author: THORs_Hand
author_rank: Contributor
timestamp: September 08, 2017, 05:29:08 pm
content: I'll watch the video, thanks for it. at the moment i try to print Hello World on that Dasy-24 module, i don't get it why it doesn't work)Maybe i'll find a solution to the problem of arduino being everything on a DC PSU

author: rstofer
author_rank: Super Contributor
timestamp: September 08, 2017, 06:43:08 pm
content: I very much dislike I2C and avoid it at every opportunity.Most of the problems revolve around the address byte. Some manufacturers will tell you the address is, say, x40. It's true but you have to shift it left and append the R/W bit and the final address byte will be x80 or x81. Other manufacturers will give you the address already shifted so, say x80 to which you add (not shift and append) the R/W bit and you still wind up with the address byte being x80 or x81. Make certain you understnd how to formulate the address byte.There is an I2C library for Arduino but I haven't used it. I don't know if the library wants the address field shifted or not. I don't know if it automatically shifts the value left and appends the R/W bit or the other way around. Make sure you do...ETA: This is one of the reasons that there is so much interest in scopes that decode serial streams. We can just look at the address byte and understand exactly what was formulated and transmitted by the library.

author: Ian.M
author_rank: Super Contributor
timestamp: September 08, 2017, 07:45:01 pm
content: Quote from: THORs_Hand on September 08, 2017, 05:29:08 pmIt shouldn't be *impossible* to do a switched mode controller in an ATmega328P provided you implement the peak current limit comparator and gate drive cutoff in hardware. (Microchip PICs with ECCP or advanced PWM modules are better off here, because they can cut off the PWM on a cycle by cycle basis when the on-chip comparator trips). The ADC on this AVR can do up to 15Ksamples/sec at full resolution, so you can update the voltage and current feedback at a 7.5KHz sample rate. Use a big inductor and run the PWM at 7.5KHz, with a separate fast PWM for the current limit comparator trip point, and, assuming a 16MHz oscoillator, you've got about 2130 instruction cycles per PWM cycle to take two ADC readings, do the control loop maths and update the main PWM duty cycle and current trip point PWM duty cycle. That should be manageable in an ISR written in assembler, maybe even in C. If using the Arduino libraries, the Timer 0 ms interrupt used by millis() and the serial interface may get in the way - you'll probably have to disable it and write a handler that runs in the PWM interrupt to get a predictable control loop response time.It wont be a very *GOOD* SMPSU: poor control loop bandwidth - a switching frequency in the audio range - and poor resolution for setting output voltage and current, but it would be an interesting learning experience.

author: rstofer
author_rank: Super Contributor
timestamp: September 09, 2017, 05:09:04 pm
content: Given that the OP doesn't really have time invested in C and the fact that the Arduino may not even have the capability, why not keep all the analog stuff (ADC, comparators) outside and generate the timing with a CPLD. It wouldn't take much logic to do the PWM thing and reading ADCs could happen very quickly and in parallel.If I were going to do this, I would look at the PWM/timing issues and see how to stuff them in a simple CPLD. Then I could use 16 bit ADCs (which the Arduino doesn't have) and real comparators.Given the parallel operation inside a CPLD makes it a lot more attractive when things need to happen quickly.