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!