El-cheapo mcu-controlled power supply - Page 1
Forum section: electronics / projects

author: dannyf
author_rank: Super Contributor
timestamp: February 18, 2014, 11:40:02 pm
content: In a separate thread, I thought about loud to myself how a digitally controlled power supply would work.I proposed this schematic as a concept to implement a CC power supply.

author: dannyf
author_rank: Super Contributor
timestamp: February 19, 2014, 12:02:14 am
content: The design has a fatal flaw, as a power supply: it is not fail-safe.Unless the mcu failure leads to a strong low on OC1A, Q1's gate will be pulled high by R3, generating maximum output.That, fortunately, can be solved by replacing R3 with another device controlled by the mcu that will fail LOW.

author: dannyf
author_rank: Super Contributor
timestamp: February 19, 2014, 12:04:11 am
content: This particular power supply will faithfully generate a constant current.There are cases where you simply want to set a limit for the output current: if the output current hits the limit, you want to turn off the output, rather than switching to the CC mode and maintaining the current to the set limit.In those cases, you can eliminate U3A and / or change the control logic in the mcu.

author: dannyf
author_rank: Super Contributor
timestamp: February 19, 2014, 12:04:52 am
content: You can also add a CV mode to the power supply and it can work side-by-side with the CC mode - the circuits are almost identical.

author: dannyf
author_rank: Super Contributor
timestamp: February 19, 2014, 12:33:42 am
content: It could be a tight implementation if you use a quad opamp.

author: cellularmitosis
author_rank: Unknown
timestamp: February 19, 2014, 12:57:26 am
content: Interesting. Any thoughts on how many of these you can run from a single micro? Bit banging the PWM even...

author: dannyf
author_rank: Super Contributor
timestamp: February 19, 2014, 01:08:04 am
content: QuoteSo there are three modes of operations:1) CV/CL (constant voltage, current limit): the output is a constant voltage. Once the current limit is hit, the unit goes into protection (=turned off).2) VL/CC (voltage limit and constant current): the output is a constant current. Once the voltage limit is hit, the unit goes into protection.3) CV/CC (constant voltage, constant current): the output is a constant voltage, unless the current limit is hit. At that point, the output is a constant current. vice versa.

author: dannyf
author_rank: Super Contributor
timestamp: February 19, 2014, 01:12:23 am
content: MCU requirement:2 digital pins for pwm output;4 analog pins for current / voltage settings and measurements;2 optional digital pins for expanded functionalities (to be explained);1 optional digital pin for on/off;3-6 optional digital pins for lcd display.So 6 - 15 pins total.Plus one timer, one dual channel 10-bit pwm generator, one 4-channel adc. ram/flash usage is minimum.

author: dannyf
author_rank: Super Contributor
timestamp: February 19, 2014, 01:16:07 am
content: QuoteThe algorithm is simple / fast. For each voltage / current pair, you need two adc channels and one pwm channel. So I tend to think that you can run a lot of it concurrently, as long as there is sufficient hardware/peripheral support.QuoteThat can be very dicey. The bulk of the code now runs in interrupt so to add on top of that high frequent isr usage isn't likely a good idea.

author: dannyf
author_rank: Super Contributor
timestamp: February 19, 2014, 11:58:24 am
content: A potential application for the CC portion of the circuit would be to use it as a battery charger: it would have a voltage sensor (and a temporature sensor). When the voltage is low, it would fully charge the battery in CC; When the voltage rises sufficiently, it would switch to a trickle charge mode. User can cycle through some pre-set current levels.If you can get 8 - 16 channels of pwm, you can charge that many batteries concurrently and independently.

author: dannyf
author_rank: Super Contributor
timestamp: August 08, 2014, 11:40:12 pm
content: I am reviving this topic, as I am slowly making some progress on this.The issue with the original concept is that the stability of a mixed signal control loop is hard to determine - in the design above, the mcu is adjusting its output voltage (pwm) to counter the shocks to the power supply's output.I thought I would take it in a different direction:1) the control loop itself is fully analog; This means that the voltage and current settings can be adjusted by analog means, like via pots. In this regard, it is just like good old power supplies, coil meter read-out (or dedicated digital read-out), and the user can adjust output settings via pots;2) alternatively, the mcu can be retained to do two things:2a): to digitally display the output voltage / current;2b): to generate the analog voltage to set the output voltage / current (aka replacing the pots used in 1) above). The voltage generation is entirely controlled by the user and completely decoupled from the output generated by the power supply.As you can see, the mcu is not in the control loop.

author: dannyf
author_rank: Super Contributor
timestamp: August 09, 2014, 12:11:10 am
content: Construction:1) so far, I have only built the CV portion of the circuit. I used a mosfet for M1, LM393 for U1/U2 and U3. Because of the use of LM393 (LM358 similarly), the minimum output voltage is less than 10mv.2) Over the next couple weeks, I will build out the CV portion.3) U3 (the current sensor) can be replaced by an IC. Many choices available. My preferred choice is LTC6102.4) If you utilize a mcu with two opamps (PIC16F17xx family for example), you can pretty much build this whole thing on a chip.5) for now, I will finish an all-analog unit before I move to a mcu-based unit.

author: dannyf
author_rank: Super Contributor
timestamp: August 09, 2014, 01:31:07 am
content: Built the CC portion of the circuit: current sensor is half of a LM393 + 2n5401.Did some preliminary test, and the circuit performed as expected.The minimum output voltage on the CC side is about 50-60mv. ie. you cannot completely shut off the current, due to the input voltage range for LM393. That will improve will the use of a better current sensor.

author: mikerj
author_rank: Super Contributor
timestamp: August 09, 2014, 10:38:03 am
content: I'm almost certainly missing something, but why are you starting with an inherently unstable CC circuit and trying to stabilise it with a micro, rather than starting with a stable CC design?

author: dannyf
author_rank: Super Contributor
timestamp: August 09, 2014, 11:23:31 am
content: Not sure what you meant by "inherently unstable" CC loop.The two designs are identical in the analog loops. The difference is that in the first design, the pwm output from the mcu is actively adjusted based on the power supply's output voltage or current. In the 2nd design, the pwm output is not changed at all.The differences in the high-side current sense amplifiers utilized are non-essential - the PNP used in the 2nd design is to accomodate an OC-output from the LM393.Both designs are "inherently unstable" for the CC loop in that there is the result of enforcing a current limit will naturally lead to relaxation of that very limit.Both designs are " stable" for both the CC/CV loops in that as designed, they don't exhibit any oscillation on the output, in spite of such inherent instability.If you can expand on what you meant, maybe I can be more specific.

author: mikerj
author_rank: Super Contributor
timestamp: August 09, 2014, 11:52:54 am
content: Quote from: dannyf on August 09, 2014, 11:23:31 amYou mentioned that the design was "inherently unstable" in your second post, perhaps I misunderstood what you were referring to? I'd assumed you meant that the CC circuit was not stable, but could be stabilised by implementing feedback via the micro.EDIT: When I here the term "unstable" applied to circuits, I naturally think of things oscillating. It sounds like it's more of a linearity problem?

author: dannyf
author_rank: Super Contributor
timestamp: August 09, 2014, 01:14:39 pm
content: The CC loop activates when the output current is bigger than the target, pulling down the opamp's output voltage, thus reducing the voltage / load on the current. This allevates the over-current condition, causing the CC loop to be no longer in effect. Thus the over-current will return, and the cycle continues.That's what I meant by it being "inherently stable".

author: c4757p
author_rank: Super Contributor
timestamp: August 09, 2014, 01:18:38 pm
content: That's not inherent instability, that's just negative feedback...

author: mikerj
author_rank: Super Contributor
timestamp: August 11, 2014, 09:36:34 am
content: Quote from: dannyf on August 09, 2014, 01:14:39 pmThat probably means you have inadequate gain or phase margin. The circuit should operate at an equilibrium point where the voltage at the load (controlled by the CC circuit) is held at the correct value to deliver the set point current. I can see two possible issues: the combined phase delay through the two slow op-amps in the feedback back path means that without very careful compensation it's almost guaranteed to oscillate, and the fairly high value inductor in series with the load. It is notoriously difficult to get stable operation when driving an inductive loads from a constant current current circuit.

author: prasimix
author_rank: Unknown
timestamp: October 29, 2014, 04:42:10 pm
content: Hi dannyf, I'd like to know did you test CC mode with short circuit condition on output? Does it generate any instability?

author: dannyf
author_rank: Super Contributor
timestamp: October 29, 2014, 05:44:08 pm
content: Yes and no.If you lower the load's resistance gradually (via an electronic load for example), the CC loop is stable.If you suddenly short the load, it oscillates. You can alleviate or cure that by increasing the time constant of the control loop, thus worsening the dynamic performance of the power supply.

author: prasimix
author_rank: Unknown
timestamp: October 29, 2014, 06:25:12 pm
content: Hm, that's something that I experienced with my current design. Do you mean that there is no cure for unexpected short circuit condition? What I'm asking is does it mean that current control loop is not a way of providing short circuit protection? Thanks.

author: dannyf
author_rank: Super Contributor
timestamp: October 29, 2014, 09:47:49 pm
content: QuoteYou can get the loop to stablize under unexpected shorting if you slow down the loop response, like sampling the output every 100ms or more - my experiment.Now, that may not be an issue as most of those supplies are indeed "DC" supplies in that they don't respond well to dynamic loading.QuoteIt is a viable way to limit current to a set limit. Just that it may not be desirable under some conditions. You have to be willing to compromise between stability and dynamic performance.

author: prasimix
author_rank: Unknown
timestamp: October 30, 2014, 08:14:30 am
content: Quote from: dannyf on October 29, 2014, 09:47:49 pmMy idea is to have short circuit condition under control without MCU assistance (if you mean by that 100ms or more sampling rate). I found in some HP/Agilent PSU that they are using separate SCR crowbar with or without, now I believe obsolete,MC3423. I find that Linear has interesting solution:LT4356. Another one is Analog devicesAD8214

author: dannyf
author_rank: Super Contributor
timestamp: October 30, 2014, 01:35:49 pm
content: I built a separate, mcu-assisted CC/CV power supply - the control loop is entirely done with analog parts and the mcu simply sets the desired output levels, both current / voltage, with or without reading the output.It would boot up to a short circuit load, and be perfectly stable. However, it is unstable going from normal load to a short circuit suddenly and I couldn't find a way to get it to stablize either.Those types of circuits are inherently unstable, given the way current control is done.

author: zapta
author_rank: Super Contributor
timestamp: October 30, 2014, 03:08:52 pm
content: CC is typically used for protection rather than actually CC mode (no point running an electronic board in CC mode).If a cheap real CC is difficult, you can relax the requiements, e.g. a circuit breaker like behavior.

author: HackedFridgeMagnet
author_rank: Super Contributor
timestamp: October 30, 2014, 10:38:53 pm
content: If you want to test LEDs with your psu you would want CC mode.Edit: Sry I was assuming you were talking about an El-cheapo mcu-controlled bench power supply.

author: Marco
author_rank: Super Contributor
timestamp: October 31, 2014, 02:44:16 am
content: What about taking one of those ESP2866 boards and using it as the microcontroller to make a (LXI?) network controlled power supply? Cutting out the display and controls would really cut down on cost.Maybe use one of those cute little Xinyuanyang flyback power supplies, they look easy to mod, get it to produce a volt or so above the desired output voltage and you won't even need any real heatsinking (you will need batteries or do something clever to be able to drive the gate voltage on a source follower regulator though, you can just increase the extra voltage too but then you're back at needing a major heatsink). So 5 bucks for the power supply, 5 bucks for the ESP2866 board, a couple bucks worth of components and a plastic box and a lot of hours of unpaid engineering work. If your time is free you can make this very cheap