Using an AVR to switch its own supply between 3.3V and 5V - Page 1
Forum section: electronics / projects

author: nitro2k01
author_rank: Frequent Contributor
timestamp: February 02, 2015, 04:08:19 pm
content: Greetings. I have a circuit consisting of an FT232 and an AVR microcontroller. I know want to implement the ability for the microcontroller to switch its own power supply (and in effect the FT232's Vccio) between 3.3V and 5V. The total power consumption of the circuit is, let's say, 100 mA maximum. The problem is really two subproblems, 1) achieving a controllable regulation and 2) ensuring that the FTDI chip and the AVR can handle the transition without crashing.The AVR is clocked from the FTDI chip, using a clock output on one of its IO pins. The voltage needs to be regulated to, or not too far from, 3.3V by default when the AVR is held in reset, and thus the control output is floated.As for problem 1, here are a couple of more or less dodgy solutions I've thought of:Controlling the ground pin on an LDO. With this option, I would control the ground pin digitally to either ground or Vcc, or possibly a value in between using a voltage divider. When 5V regulation is desired, the AVR pulls a pin high as to raise the reference above ground and, ideally, turn the pass transistor fully on to enable a 5V supply voltage. For example, a jellybean LM3940 is specified for a 100 mV drop for 100 mA which would be acceptable. However, I'm worried about the stability. Would the circuit be prone to oscillate in the 5V mode in this configuration? Are there LDOs that are specifically specified to work in this mode?Another dodgy idea I have is to use an LDO and an external FET to short the input and output of the LDO to effectively bypass it. Assuming the LDO isn't sink/source, but only has a pass transistor, I'm thinking it should be fairly happy in this configuration. What's the norm for an LDO, single pass transistor, or sink/source? Anything else I'm missing?Another slightly less dodgy alternative I've thought of is to roll my own regulator using an opamp, a pass transistor and the 3.3V output from the FTDI chip's regulator as a reference. One of the inputs of the opamp could then be gated by the AVR to force it into 5V operation.Any other obvious methods I've missed?Then there's problem of handling the transition. I'm assuming this should be fairly ok, as long as the transition happens fairly slowly. Is there data on this, or would I just have to figure this out empirically?Any advice is welcome.

author: zapta
author_rank: Super Contributor
timestamp: February 02, 2015, 04:38:33 pm
content: What's your input voltage? If it's 5V then you will need to bypass the LDO.One option is to use a regulator with feedback input and switch a resistor to ground to raise the voltage.Note that some AVRs cannot run at full speed at 3.3V.

author: tom66
author_rank: Super Contributor
timestamp: February 02, 2015, 04:39:10 pm
content: Ok, I do have to ask... Why do you want to do this? I can't really think of a good reason to do it. If you need to communicate with a 5V device occasionally, why not run at 5V all the time, or use a level shifter circuit?If you really want to do it, the best way is to use an adjustable regulator like an LM317 or LM1117 and vary the adjust pin, output voltage will rise if you inject current into ADJ.

author: nitro2k01
author_rank: Frequent Contributor
timestamp: February 02, 2015, 04:53:51 pm
content: Quote from: tom66 on February 02, 2015, 04:39:10 pmI'm interfacing an external device (in particular Gameboy cartridges) which can either be 5V and 3.3V for the newer cartridges. So, I need to provide both power and compatible IO. Using level shifters would take care of the particular problem of switching the AVR's supply voltage on the fly, but I would still need to produce 5V or 3.3V arbitrarily for powering the external cartridge.Quote from: tom66 on February 02, 2015, 04:39:10 pmI should perhaps have pointed it out, but the device is powered over USB, and 1+ V dropout voltage of a non-LDO is not acceptable. But I detailed this option in my post, but for using an LDO. I'm looking for practical advice on how the device would behave when trying to pass the input voltage directly by overdriving the ground/adjust pin. At some point I'll have to sit down by the bench and try different things. Until then I thought I'd ask here.

author: georges80
author_rank: Frequent Contributor
timestamp: February 02, 2015, 05:13:29 pm
content: If you want to do it via firmware versus a old fashion manual switch...I'd just use a p channel FET that when turned on passes the input voltage (USB nominal 5V) straight to the output of the 3.3V regulator. Choose an LDO that has the necessary topology to safely allow the output pin to be driven higher than the regulated 3.3V (they exist).i.e. the p channel FET drain/source is in parallel with the regulator. Gate pulled up (to USB 5V through say a 100k resistor) unless the uC drives it low, use an npn to pull the gate low. Base of of the transistor via a suitable resistor to a uC GPIO and a pull down to keep the npn off until the uC gets out of reset and programs the GPIO to be an output and drive a low (3.3V operation) or high (5V operation).cheers,george.

author: zapta
author_rank: Super Contributor
timestamp: February 02, 2015, 05:16:40 pm
content: Since your input is 5V you need to somehow bypass the LDO with low resistance, either a SPDT switch or a SPST switch (shorting the input and output of the LDO, it's a common practice though not sure if it's covered by the datasheets).Here is an arbitrary SPST switch, there are many othershttp://www.ti.com/lit/gpn/tps22914c

author: mariush
author_rank: Super Contributor
timestamp: February 02, 2015, 06:04:29 pm
content: There are LDOs that have only about 50-150mV of voltage drop, so you could configure the regulator to output about 3.3v. If you feed it with 5v, you'll get 3.3v, if it receives 3.3v you will get about 3.1-3.2v (which should be close enough to work).See for exampleLP2980 (up to 50mA) :http://uk.farnell.com/texas-instruments/lp2980im5x-adj-nopb/ldo-adj-o-p-1-23v-15v-0-05a-sot/dp/2436419TPS79301 (up to 200mA) :http://uk.farnell.com/texas-instruments/tps79301dbvr/v-reg-ldo-1-2-5-5v-smd-sot-23/dp/2437829MCP824 (up to 300mA) :http://uk.farnell.com/microchip/mcp1824t-adje-dc/ic-ldo-adj-300ma-sot-223-5/dp/1578392The amount of voltage drop varies with the current, if your mcu only draws 10-20mA for example, the dropout voltage will be under 100mV with most of these tiny ldos.So you make sure the ic is always powered by 3.3vAnd if you really want to improve efficiency by taking out the ldo if your input voltage is 3.3v, then optionally you could use one adc pin and a resistor divider to measure the voltage and if you detect more than 3.3v or so, you could use a mosfet or something to bypass the LDO.

author: nitro2k01
author_rank: Frequent Contributor
timestamp: February 02, 2015, 06:51:23 pm
content: Quote from: zapta on February 02, 2015, 05:16:40 pmThank you. This is the kind of things I wanted to know.mariush: You've got it backwards. I always have 5V from USB, and want to produce 5V or 3.3V for the system's Vcc.

author: zapta
author_rank: Super Contributor
timestamp: February 02, 2015, 06:55:56 pm
content: Quote from: nitro2k01 on February 02, 2015, 06:51:23 pmSome boards even go one step further and feed high voltage on the output of the LDO without any vin. See Digispark for example, the LDO can get 5V on the output from the USB without vin from the auxiliary power.https://s3.amazonaws.com/digistump-resources/files/97a1bb28_DigisparkSchematic.pdf

author: georges80
author_rank: Frequent Contributor
timestamp: February 02, 2015, 07:15:11 pm
content: Quote from: nitro2k01 on February 02, 2015, 06:51:23 pmLike I wrote earlier, there ARE regulators that specify the ability to have higher voltage applied to their outputs regardless of input voltage (or lack of). An example is the MIC5235 from micrel, download the datasheet and have a read.cheers,george.

author: uChip
author_rank: Contributor
timestamp: February 03, 2015, 12:05:42 am
content: Quote from: georges80 on February 02, 2015, 07:15:11 pmInteresting. I've seen and copied a number of circuits that make use of USB power connected directly to the output of the 5V reg and wondered whether this was legitimate or not. The circuits where I've seen it use the MIC5219 or MIC5205. I could not find any mention of this configuration in those datasheets. I just looked at the MIC5235 ds. I assume you are referring to the "Reverse Current" aspect of the spec. Reverse Current is not specified for the MIC5205 or 5219. But since the regulator does not get hot I assume that reverse current is minimal for these devices as well. Nice to know that it's a (somewhat) spec'd use. Thanks!- Chip

author: tszaboo
author_rank: Super Contributor
timestamp: February 03, 2015, 07:44:37 am
content: You could feed the input voltage to a MCP1252-33X50. That has boost operation and pin selectable 3,3 or 5V output. Basically all you need.

author: nitro2k01
author_rank: Frequent Contributor
timestamp: February 03, 2015, 11:02:19 am
content: Quote from: NANDBlog on February 03, 2015, 07:44:37 amThat's a very interesting contender. Thanks.

author: dannyf
author_rank: Super Contributor
timestamp: February 03, 2015, 12:19:08 pm
content: Just take a linear 3.3v regulator, and put a divider on it to produce 5v. The divider can be controlled by a mcu's pin so the output is a mcu-selectable 3.3v/5v output.Done.

author: eneuro
author_rank: Super Contributor
timestamp: February 03, 2015, 10:13:13 pm
content: Quote from: georges80 on February 02, 2015, 07:15:11 pmEven LM7805 or LM2940-5.0 with additional diode from its output to input in custom AVR programmer allows me run MPU with external voltage apllied directly on top of MPU without oryginal power supply switched on, while this diode bypassed back main voltage regulator and that is why I have such diode in most of my designs

author: zapta
author_rank: Super Contributor
timestamp: February 03, 2015, 10:19:55 pm
content: Quote from: NANDBlog on February 03, 2015, 07:44:37 amIIRC, you have an article somewhere explaining why USB 5V is not actually 5V so this DC/DC actually solves two problems.

author: langwadt
author_rank: Super Contributor
timestamp: February 04, 2015, 12:05:53 am
content: with 5V in and 5V you don't need the regulator to be regulating you just need lowest drop out, so I'd thinkusing an LDO with a MCU pin connected to the sense pin so you can short it to ground would work.Set the sense pin divider for 3.3V, short the sense pin to ground when you just want lowest dropout

author: eneuro
author_rank: Super Contributor
timestamp: February 04, 2015, 07:24:59 am
content: Quote from: NANDBlog on February 03, 2015, 07:44:37 amQuite nice cheap, but probably we need have some kind of power supply voltage monitor to ensure this voltage changed as well as maybe even restart MPU to avoid program crashSuch Vcc voltage level change doesn't afffect MPU. eg. its internal oscilator ?Probably we need restet MPU in hardware after such power supply voltage change and wait some time for voltage to stabilize or missed something?

author: tszaboo
author_rank: Super Contributor
timestamp: February 04, 2015, 09:09:57 am
content: Quote from: eneuro on February 04, 2015, 07:24:59 amAlthough, I dont know how the MCP switches it's voltage, I suspect based on the internal circuit, that the voltage just ramps up/down, when the switch happens. I think it is possible that there isnt any problem when the switching happens, but it could depend on the bypassing, or the MCU used.If this is not working as expected, I suggest the following: Connect a D-flipflop on the voltage selector pin of the MCP, so it will remember the voltage if the MCU goes into reset. It could be also useful, if the poergood pin of the MCP is connected to the reset of the MCU, so when the transition happens, the MCU resets itself.This is something which should be tested.

author: dannyf
author_rank: Super Contributor
timestamp: February 04, 2015, 11:41:51 am
content: QuoteBy changing the divider. The same approach I mentioned earlier. For small load, a linear regulator is all you need.

author: nitro2k01
author_rank: Frequent Contributor
timestamp: February 04, 2015, 12:44:57 pm
content: Quote from: dannyf on February 03, 2015, 12:19:08 pmYes, I even suggested this method in my original post.What I was looking for with the question is more practical advice. For example, would this circuit be more prone to oscillate than an LDO normally would? Should I put a capacitor between the "virtual ground" and output to reduce oscillations, or is it sufficient to put it between system ground and the output? And, would there there be any point putting the virtual ground point even higher than the nominal 1.7 V over ground, to ensure the pass transistor is fully turned on to minimize the voltage drop? Or would this on the contrary cause stability problems? Again, practical stuff. Of course, I will sit down and experiment as soon as the components will arrive, but I thought I'd ask here in the meantime.I'm still considering the suggested MCP1252-33X50 switching reg, since it's relatively cheap and has the secondary benefit of dealing with potentially dodgy USB cables or supplies.

author: dannyf
author_rank: Super Contributor
timestamp: February 04, 2015, 04:22:59 pm
content: QuoteThere is no answer to (most of) your questions, as such behaviors are very device specific, and without your trying it out, you will not know for sure.From a "guestimate" point of view, I would suspect that if the regulator is driving into a large capacitor, it will likely have excess voltage when going from 5v to 3.3v and likely will oscillate when going from 3.3v to 5v.Such anomalies should be minimized with low capacitance and a heavy load.QuoteNot sure what "virtual ground" you are talking about but in the setting we are discussing, there is no "virtual ground" as it is typically understood.

author: nitro2k01
author_rank: Frequent Contributor
timestamp: February 04, 2015, 04:29:06 pm
content: Quote from: dannyf on February 04, 2015, 04:22:59 pmThis is what I'm calling the point of the voltage divider where the ground pin of the regulator connects, as this officially a "ground pin" and not an adjustment pin on many linear regulators, even if used in this way. The regulator thinks 1.7 V over system ground is its ground. Whether you call this a virtual ground or not is semantics, but the quote marks should be a hint that I wasn't being literal.

author: tszaboo
author_rank: Super Contributor
timestamp: February 04, 2015, 04:39:05 pm
content: Quote from: dannyf on February 04, 2015, 11:41:51 amYes, I can read datasheet, I'm not suupid. I'm talking about the ramp speed overshoot/undershoot or if you have an electrolytic cap of say 470uF on the output, does it discharge it rapidly or the load has to do it... It has a block called "switch control" what can do number of things when the pin is changed.

author: georges80
author_rank: Frequent Contributor
timestamp: February 04, 2015, 06:24:09 pm
content: I still recommend a linear regulator for 3.3V and a p chan FET to bridge the regulator for 5V operation.With most 5V stuff being spec'ed at +/-10% rail, that gives operation from 4.5V to 5.5V. That'll cover most USB 5V variations.Unless you are going into mass production of this 'product', it seems a simple solution takes care of things for a hobby level project. Additionally if this was a production product you would be focusing on the USB current spec (standby current, pre-enumeration current, post enumeration current etc etc)...Modern LDO regulators are very stable and typically will operated with near to no input capacitance (or 1uF at most) and very little at the output (a few uF) and all handled nicely with ceramic x5r/x7r capacitors, no need for honking large electro's etc.cheers,george.

author: langwadt
author_rank: Super Contributor
timestamp: February 04, 2015, 09:35:31 pm
content: Quote from: georges80 on February 04, 2015, 06:24:09 pmWhy bother with a fet if you can just use the LDO itself?There are still plenty of LDOs that will do odd things if you don't use the right output capacitor

author: georges80
author_rank: Frequent Contributor
timestamp: February 04, 2015, 09:49:59 pm
content: Quote from: langwadt on February 04, 2015, 09:35:31 pmBecause its easy to do without having to worry about the LDO ground pin issues/capabilities or configuring the feedback resistors for 3.3V/5V or any of the other suggestions regarding floating the ground pin etc etc.Anyhow, the OP has several ways to do it, all depends on his needs/comfort level and how accurate he wants/needs the 5V to be. USB good enough or really 5V (buck/boost etc). Given it appears to be a hobby project, most of the suggested schemes will work good enough.cheers,george.