Modifying an Arduino Mega and chipKIT Max32 for 5V Operation

Max's Arduino Mega and chipKIT Max32 both require 9V external supplies, but he really wishes to power them from a single 5V supply.

Well, nothing is simple, is it? I ran into a minor "gotcha" with regard to my Bodacious Acoustic Diagnostic Astoundingly Superior Spectromatic (BADASS) display project. As you may recall from my previous blog on this topic, I'm planning on implementing a 16 x 16 array of tri-colored LEDs using NeoPixel Strips from Adafruit. I'm also planning on controlling these little beauties using an Arduino Mega 2560 R3 microcontroller development board.

When it comes to processing the audio stream from my iPad to extract its frequency data, which will subsequently be handed over to the Arduino Mega to be displayed, I'm planning on experimenting with a variety of approaches. (See also Linking 2 MCUs with a Home-Grown Interface.) A couple of these approaches will involve a chipKIT Max32 microcontroller prototyping platform.

The NeoPixel strips require a 5V power supply. Each LED can draw as much as 60mA if all three of its RGB channels are full-on. In reality, it will be rare indeed for all 256 LEDs to be fully on, but I prefer to design for worse-case scenarios. In this case, this would be 60mA x 256 = ~15.6A. In order to accommodate this, I ended up purchasing a 26A highly-regulated power supply as shown below.

Now, the Arduino Mega and the chipKIT Max 32 both require an external supply of between 7V and 12V. When this supply is fed into the board, it is first regulated down to give a constant 5V supply and then regulated down again to provide a 3.3V supply. Alternatively, these boards can also be powered from a USB programming cable, which can provide a 5V supply.

The problem is that things tend to get messy if you are powering each unit from a different supply. Quite apart from anything else, I really donít want three power cables coming out of the display. Also, if you are using different supplies, then you can't be sure which sub-unit will power up first and you can end up with one unit back-driving another, which is not generally considered to be an ideal situation.

The bottom line is that I really want everything to be driven from my 26A supply. That way I cut down on the cables and on the power supplies, things are neat and tidy, and everything will power up together.

WARNING: The following describes some modifications that I decided to make to my microcontroller boards. Please understand that I am not recommending that you do this to your own boards, because you could easily damage them and invalidate any warranties that came with them. (Yes, these are the obligatory weasel words, but it always pays to remember the old saying: "Eagles may soar, but weasels rarely get sucked into jet engines.")

Modifying the Arduino Mega
This is the point where my techno-weenie chum Ivan Cowie leaps into the center of the stage with a cloud of smoke and a fanfare of trumpets. Ivan, whose office is in the next bay to mine, is a diva when it comes to power supplies and their wily ways (which explains why he's currently writing the All About Batteries mini-series here on EETimes).

Ivan first looked at the PDF schematic diagram for the Arduino Mega. You can access the entire schematic by clicking here, but the relevant portions are shown below:

Subset of the Arduino Mega schematic diagram.(Click here to see a larger image.)

Within just a couple of seconds, Ivan had determined what was required. Since he was jabbing his finger at different parts of the schematic and chattering away at the same time, it was easy to see how he came to his conclusions. The following is pretty much the way he explained it on the fly…

As we see, the external power supply comes in at the top left-hand side. First it is passed through diode D1, which is used to prevent the USB port from back-driving the main power supply (we'll come back to this later). The output from this diode is VIN, which is fed into the regulator IC1. It's the output of IC1 that drives the +5V signal.

But wait, look here… In the bottom of the schematic we see signal USBVCC. This is the five volt supply from the USB cable. This signal is passed to transistor T1, and the output from T1 is also connected to the +5V signal. Thus, the +5V signal may be driven from the external power supply via the voltage regulator, or it may be driven from the USB port.

Now look at the resistor divider formed from two 10KΩ resistors in the bottom left-hand corner of the schematic. This is fed by VIN. If no external supply is connected, then the output from the resistor divider, the CMP signal, will be 0V. This is fed to one of the inputs to comparator IC7B. The other input to IC7B is fed from the +3V3 supply. This means that if no external supply is connected, then the output from comparator IC7B will turn transistor T1 on, thereby allowing the USBVCC supply to drive the +5V line.

By comparison, suppose we have a 9V supply. The voltage drop across diode D1 could be anywhere from 0.3 to 1.0V, depending on the type of diode. If we assume a worse-case value of 1V, then VIN will be 8V. When this is fed into the resistor divider, the signal CMP will be 4V. This will cause the output from comparator IC7B to disable transistor T1, thereby blocking the USBVCC supply and allowing the output from the regulator to drive the +5V signal.

@Don J: The better solution would be to replace IC1 with another FET like T1 and drive it's gate with an inverted version of the T1 gate drive.

I wish I could get you and Ivan in the same room together -- he was just in my office waving the circuit diagrams around saying almost exactly the same thing -- he suggests replacing IC1 with a depletion mode FET (he suggested IXTH16N10D2) -- plus we no longer need to add the resistor in parallel on the resistor divider, but we do have to cut a couple of traces and add a couple of wires.

Personally, for simplicity, I'm just going to keep our existing solution and say that I will always have the Arduino powered from my external 5V supply -- and occasionally I may also plug in the USB cable for programming purposes, but never to power the board.

The simpleset solution I came up with is to replace IC1 with a Schottky Diode instead of the jumper. This would allow the USB to power +5V at 5V, however the external supply would power +5V at a few tenths below 5V. But at least +5V would not have the ripple.

The better solution would be to replace IC1 with another FET like T1 and drive it's gate with an inverted version of the T1 gate drive. This would require an inverter (which could be a small signal BJT or another FET), and may need a pull-down on VIN... more parts, but a better overall solution. Still need to spec out the parts and packaging (which can be fun... :-)

Max, Thanks for the response and the waveforms, they are about what I expected. I have been noodling on this also, but don't have any good answers yet either.

I think you can use this circuit with just the USB connected as long as you are not relying on the 5V supply for anything other than feeding the 3.3V regulator. The 3.3V regulator should tolerate this oscillation and maintain the 3.3V supply within range.

I hope Ivan doesn't lose any sleep this weekend, and I'm sure he'll come up with a clever solution, I just hope I can beat him to it :-)

@Don J: Max, I'm concerned about this circuit operating from USB power only...

Arrggghhh! We hang our heads in shame. It turns out you are correct. Things are not as we would wish them to be.

We powered up the Arduino Mega (with our modifications) using only the USB power. Here's an image of the output from the comparator, and here's an image of the +5V supply rail as being supplied by the USB cable with the transistor turning on and off. As you can see, the +5V rail is oscillating between around 4.5V and 4.7V with a frequency of ~2.6KHz (sad face).

The Arduino itself tolerates this -- the default "Blinky LED" sketch works just fine (which is what lulled me into a false sense of security) -- but it's not possible to predict how well any shields would tolerate this.

On the bright side, everything is rock solid when powered by the external 5V supply, which was the main point of this exercise -- also, things work as planned if both the main supply and the USB cable are connected (in which case the main supply is the power source; the USB is used only for data).

So I just have to remember not to connect these boards only to the USB cable. Having said this, Ivan is taking this very personally -- he just went off muttering to himself that he's going to ponder this problem over the weekend, so once again, watch this space LOL

If you want to reprogram the Arduino all that you have to do is to disconnect the regulated 5V power from the POWER:5V pin, plug in the USB and reprogram. This would also necessitate removing any shields that you have connected, if they're relying on more than the 500mA you can suck from USB (or plug in a wall-wart if you don't-want/can't disconnect easily from the rest of your system).

The only thing that you can't do with the completely unmodified setup that I described is to use serial output back across the USB cable to the PC. That relies on the USB being connected, so perhaps *that* you can't do in situ for reasons that you cite. But even that could be worked-around by using a simple USB-TTL converter and just connecting RX, TX and GND that you can get from eBay sub-$10. These typically use CP2102s, PL2303s or (for $1-2 more) the oft-used FT232RLs. Of course, if you're fly enough to still have an RS-232 port, it's even cheaper because that's just a MAX232, and a DB-9.

Once again, I'm unsure if this solution carries over the ChipKit boards because I haven't looked into those. It should have been a requirement since BYO5V is fairly widely used for USB-untethered Arduino projects, so IMO it's a high-want feature.

I believe that some PoE sheilds are essentially BYO5V, as they knock-down 48V through a switching regulator and inject their 5V output through their shield pin down into the Arduino. Alternatively, they could drop to 7-12V and use POWER:VIN instead, relying on the baseboard's LREG to provide the 5V (similar to the wall-wart case). I've seen PoE PDE power interfaces that do either (12V PoE output into POWER:VIN or 5V into POWER:5V).

@ewertz: My premise was exactly the one that you stated -- that you wanted to eliminate all of the cables and rely just on the perfectly good 26A/5V supply. Was that not the whole point...?!?!?

Well yes -- that's true -- when the system is deployed I want all the sub units to run off a single 5V/26A supply.

However -- even when everything is connected up, I might still want to connect a USB cable to one of the microcontroller boards in order to upload a new program (in which case I want the board to use the USB for data and continue using the external supply for power).

It's also conceivable that I might want to remove a microcontroller board from the system and take it to my work bench and power it just using a USB cable -- I think that's where "Don J" is saying a problem may occur.

I can, of course, always ensure that I have an external power supply plugged in -- which would remove any problem -- but now I want to check it out on a 'scope with just USB power to see if it works or not...

@Don J: Max, I'm concerned about this circuit operating from USB power only...

We did consider this, and we decided that the RC time constants associated with the resistor divider and capacitor C12 ... along with the three capacitors associated with the voltage regulator -- along with the hysteresis assocuiated with IC7 -- would mean that things would work as we wished.

But now you have us wanting to be able to answer you definitively, so I'll bring the Arduino back into the office tomorrow (it's currently at home) and we'll put it on a 4-channel 'scope and capture the waveforms ... watch this space...