Controlling the LM2596 with minimal modification of the DCDC board is the main challenge. The most obvious way to do this is by manipulating the LM2596 feedback input with PC.3. Setting two different voltage levels is simple, and it has already been demonstrated.
The next level is closed loop control of the output voltage within a certain range.
The adjustable variant of the LM2596 (the one used in cheap boards) compares the feedback signal with a fixed reference voltage of about 1.23V (1.18V to 1.28V through the temperature range) using a fixed voltage divider, and sets the converter duty cycle accordingly
Variable controlling of the output voltage requires the following elements:
A) Reading the output voltage can be done by either 1) reading the output voltage, by 2) reading the feedback voltage, or 3) with a combination of the two.
B) Controlling the output voltage with the STM8 can be done by 1) setting the feedback voltage, by 2) changing the feedback ratio, or 3) with a combination of the two.
The B3603 (refer to HaD Power Supply B3603 Alternative Firmware) uses method A1-B1.
I want to try A2-B2, A3-B2, or even A3-B3.
Here is how:
- The DCDC board has a low pass filtered measurement of voltage "Vout" which limits the control amplification P. It would be usable for "slow but accurate" I control.
- Fast feedback measurement can be done by "unfiltered" conversion with PC.3 if the conversion is synchronized with the LM2596 150KHz oscillator. Gain is likely limited by the acceptable noise.
- Using the native feedback loop of the LM2596 would allow much better control performance, but this requires a sufficiently variable voltage divider controlled by the µC (two levels is trivial)
- Controlling the feedback ration might be possible by controlling the voltage divider switch duty cycle with PC.3 PWM. If this works depends on the behavior of the LM2596.
- Using a small capacitor in the feedback loop, similar to what's described in LM2596 datasheets, might create a "B3 property".
Synchronization and control is possible with the help of Timer1:
- TIM1 can do up to 107 ticks in one oscillator cycle
- ADC conversion can be linked to a TIM1 compare with TRGO
- closing the control loop by setting the PC.3 "feedback duty cycle" can be done in a TIM1 overflow (or compare) interrupt
Open questions are:
- whether the LM2596 remains stable with such a kind of "bending"
- how can TIM1 be synchronized with the LM2596 oscillator without using an additional GPIO
Suggestions, or feedback, are welcome!
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
Hi K.C.!
I had planned to synchronize TIM1 with the LM2596 oscillator PLL style, but I don't know yet if I can create a sufficient PLL sync using the ADC (this depends on the choice of signal processing, I guess :-))
Variant B3 basically injects a DC offset but the "PLL" synchronization is a necessary prerequisite.
Edit: removing the LED display is an option. That would free up GPIOs for building an 8bitish R-2R "feedback DAC".
Are you sure? yes | no
LM2596 block diagram
Think of the feedback amplifier (GM) as a summing amplifier. V1 is connected to your output. You should be able to inject a DC offset on V2 to shift that output up or down. (You don't get to play with RF, but there is some fixed gain.)
That DC offset can be coming from my 1 GPIO + opamp sigma delta DAC built with opamp integrator.
Are you sure? yes | no
Yes, that's an option!
However, I have a gut feeling that the problem would be the digital control feedback loop. I'll have to figure out the value of C5 in the output voltage measurement (A1).
The alternative, reading the output voltage through the feedback loop (A2), only works if the GPIO switches from "low side output" to "analog input" at the right time in the LM2596 oscillator cycle.
Are you sure? yes | no
Same as my power supply, I would only care about the low pass DC output for trimming up/down the output. The firmware PID loop figures out the trimming by monitoring the output. I used a 30Hz update loop I think.
I would let the chip handle the more exciting AC transient response. i.e. a few Hz up to may be a fraction of the switching frequency (usually 1/6 to 1/10).
Are you sure? yes | no
On a second thought:
LM2596 doesn't have RF, and I have difficulties understanding GM (which is used without feedback and drives an "active capacitor" - this looks to me like a fixed amplification low-pass-filter). On the plus side: In the adjustable variant, R1 and R2 are also missing. Currently I don't see how turning GM into a summing amplifier can work. Of course, using an external summing amplifier is possible.
Are you sure? yes | no
GM is a fix gain amplifier. You can think of it having its RF connected internally. The adjustable version of the chip have the inverting input directly to the FEEDBACK pin where you normally connect a voltage divider.
So you already have R1 connected to the output. Now normally the lower side of the voltage divider which is V2 is connected to GND. If you now connect that branch to a DC offset, you can level shift the feedback node. This converts the feedback circuit similar to the summing amplifier form.
Alternatively you can work out the voltage at the feedback pin as a voltage divider with the ground side connected to a floating DC offset using simple algebra.
I have done that to level shift a +/- 3.3V signal to a 0-3.3V shown below for ADC front end. As long as the voltage you are level shifting is larger than the desired output and have the same polarity, a passive network can work. Most would have missed that and wasted an opamp and ended up with an inverted signal that they have to be converted back in firmware.
In you case, the divider ratio is not 1:1. A PID loop can iterate and inject the need offset value when you close the loop using the output voltage.
Are you sure? yes | no
Cool, that's good to know. Most likely applying a DC offset the way you pointed out is the the most viable option (and it's simple, too).
Are you sure? yes | no
You won't be able to synchronize to the switcher without using a GPIO line. Not unless the part can oversample and process data.
>24.2 ADC main features
External trigger option using external interrupt (ADC_ETR) or timer trigger (TRGO)
Pin 12 can be set as ADC_ETR
-------------------------------------------------------
If you are willing to throw in extra hardware, a $0.77 I2C 4 digits LED display can free up lots of I/O.
https://www.aliexpress.com/item/4-digital-display-with-adjustable-brightness-LED-module-clock-Point-Accessories-Blocks-for-arduino/32216576572.html
For adjusting the output, you can try to inject a DC offset into the feedback node similar to my 1k power supply project.
Are you sure? yes | no