Issues of an STM32-based device where the MCU can adjust its own voltage? - Page 1
Forum section: electronics / projects

author: daqq
author_rank: Super Contributor
timestamp: September 28, 2024, 08:30:07 pm
content: Dear forum members,I am designing an STM32-based measurement device where the MCU will be able to control its own power supply voltage. It will do so because it's required to have adjustable logic levels. Nothing fancy, just switch between 1.8V, 2.5V and 3.3V.I want to do so by switching the feedback resistors of an adjustable output LDO (https://www.onsemi.com/pdf/datasheet/ncp705-d.pdf) through external NPN transistors to ground. The feedback network will be of lower impedance than recommended - this will be to make sure that the capacitance to ground added by the inactive NPN transistors and the resistors they are switching will not affect the feedback network significantly.The safety will be ensured by the calculation of the feedback network that the only way to achieve maximum voltage will be to turn on both transistors. By default (transistors open), the output voltage would be 1.8V, by switching on the additional parallel resistors, the voltage can be increased, but only to 3.3V.Pretty much the schematic in the attachment (the actual LDO will be different and the resistance values will be for a different feedback, this is just a convenient model I have in LTSpice to test out the concept).My question is whether there could be any issues with this sort of dynamic input voltage switching?By dynamic I mean once every few seconds at worst and not during any critical operations, with enough time for everything to settle to the new voltage. Of course the brown out will be set to the minimal value. There will be no USB, only logic in, logic out, and the ADC will check itself against an external 1.25V reference, and there'll be no fancy ADC stuff anyway.My gut tells me that this should work. The only thing that I can think of is that some PLL will need to re-lock briefly or something?Can you see any issues?Thanks,David

author: Manul
author_rank: Super Contributor
timestamp: September 28, 2024, 09:01:27 pm
content: Don't use BJT, cause they will not be ohmic near zero CE voltage. Use small mosfets. In fact you don't even need mosfets or other external components. Just use MCU pins. They will be around 25-30 Ohms when driven low. Configure them as open drain outputs and job done, they are also low capacitance.Such voltage transients should not be a problem for MCU, just watch that they are not super fast. Ballpark value - not faster than 100us / 1V. Maybe faster is ok, I don't know, you need to try.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: September 29, 2024, 08:44:18 am
content: Quote from: daqq on September 28, 2024, 08:30:07 pmNo, it's the other way around. When you turn on one (or both) of the BJT's the output goes lower. Maximum output voltage is when the transistors are off.Using a MOSfet as a switch instead of a BJT probably gets you a more accurate output voltage, but it will work good enough with a BJT. Application notes (or even the datasheet itself) of the LM317 uses BJT's as suggestion for a "programmable output voltage".But do not use the I/O pins for this directly. Sure, it works as Manul writes, but if you ever inadvertently change the pin to an output high, then you will fry your microcontroller.I think that the core of all STM32 chips runs on something like 1.8V and they have an internal regulator, but even so, I'd try to make the power supply voltage switch slowly, for example by adding a capacitor between the base of the BJT and GND. This gives PLL's, crystal oscillators and who knows what else happens inside the STM32 some time to adjust to the changing voltage.

author: Manul
author_rank: Super Contributor
timestamp: September 29, 2024, 10:09:23 am
content: Quote from: Doctorandus_P on September 29, 2024, 08:44:18 amI'm afraid daqq is correct, why would an output get lower, when bottom leg of divider gets lower?Quote from: Doctorandus_P on September 29, 2024, 08:44:18 amWhy fry? If you drive it high, then that switchable resistor will effectively be in parallel with the top leg of voltage divider. That will lower the output voltage, not increase it. When GPIO peripheral is not initialized, pins are floating, then code sets GPIO to open drain. Seems ok to me. GPIO will not magically reconfigure itself and even if it does, I see nothing catastrophic. Looks like simple, elegant solution. Voltage ramp speed must be checked though and can be adjusted by changing feedforward capacitor (in parallel with top leg of divider). Higher value capacitor will make voltage ramp slower.

author: daqq
author_rank: Super Contributor
timestamp: September 30, 2024, 06:56:47 am
content: Thanks for the replies.Manul: I'm not sure why BJT transistors shouldn't work? Yeah, they won't be really ohmic, but with near zero current, the voltage drop on them should be near zero anyway, no? I can use MOSFETs, though they'll have to work from 1.8V. Should be pretty common these days though.As to using pins directly, I would like to avoid that - if I mess up the software and turn the pin on as a output, logic high, then the voltage would drop to near zero, possibly causing some reset loop.Doctorandus_P: No, that's not how the circuit works. If you lower the resistance on the "bottom" side of a feedback resistive divider for this application, the voltage goes up.

author: darkspr1te
author_rank: Frequent Contributor
timestamp: September 30, 2024, 03:41:38 pm
content: Maybe you could adapt this,https://hackaday.com/2024/09/30/switch-your-rp2040-between-3-3-v-and-1-8-v/

author: Manul
author_rank: Super Contributor
timestamp: September 30, 2024, 06:13:13 pm
content: It will certainly work with BJT, but BJT is less precise and less efficient as a switching element. It takes current to control, thus wasting power. It is common to use mosfet for switching and BJT for linear applications. It is not a rule of course. In old days they used BJT for everything including logic ICs, which was very inefficient compared to CMOS. But it's your design, I was simply sharing how I would do.Quote from: daqq on September 30, 2024, 06:56:47 amIf you mess up software, you simply fix it. I mean, you probably use SWD interface - STLink programmer, so it can inject it's own 3.3V while programming. I really don't see how you could brick the device into unrecoverable reset loop. Furthermore it never happened to me that I set configuration registers and they somehow change by accident. Software is deterministic. That is to some extent an opinion, always design with choices you are comfortable with.