First project: USB power best practice help needed

Status
Not open for further replies.

thomasp

Active member
Hi,

First post and first project. I am a novice at this. First a big thanks to Paul and team for such a great product!

I have built a MIDI controller using a Teensy 3.5 with 10 encoders and 10 LED rings. All working fine.

I am using 10 LED rings with 24 RGBW LEDs each so 240 LEDs in total (>18 A theoretically at full max). Using only minimal LED brightness and one color at a time, my controller draws a maximum of 480 mA from the USB connection (LEDs and encoders draw 5V from the VIN pin). I measured this using one of these USB power monitors).

I would prefer to keep using USB power only and no external power supply as i do not need high brightness and my power budget seems to fit with the USB 2.0 500 mA max.

But I need some guidance on some questions relating to using USB power which I could not find answers to when googling:

  1. As USB 2.0 offers only 500 mA max, is it safe to run the controller so close to the max?

  2. I read a comment from Paul that I can edit the "bMaxPower" var in usb_desc.c to announce to the USB host that I need the full 500 mA. How can I detect that the USB host is unable to provide that much current so I can deactivate the LEDs on my MIDI controller via code?

  3. If I would specify my controller to only be used on USB 3.0 ports so I can get the 900 mA that USB 3.0 provides, is there a way I can detect on the Teensy (via code? / other?) that I am not connected to a USB 3.0 port / not getting the 900 mA so I can accordingly not start up the controller LEDs? Do I need to vary the "bMaxPower" variable for USB 3.0 or is the 900 mA available as a baseline?

  4. Theoretically, if my code has a bug or the LED controllers malfunction (I had one LED ring from an eBay vendor light up to max due to what I assume was a flaky part / data line timing) I assume this would damage my Teensy and / or the USB host. Are there any overcurrent protection components I can add to my circuit to prevent my controller to unexpectedly try to draw a huge amount of current and damage things?

  5. If I decide to add an optional external power supply (so controller can be run via USB power at low LED brightness or via external power at high LED brightness), how could I do that and is there a way I can detect via code / other components that I have external power available and accordingly use higher LED brightness?

Thanks for your help!
Thomas
 
Teensys and many devices have poly fuses
https://en.wikipedia.org/wiki/Resettable_fuse
https://www.pjrc.com/teensy/schematic.html (top left corner)
Note that low brightness does not limit the max current, just the average over the complete cycle
https://softsolder.com/2015/11/18/neopixel-current/
https://softsolder.com/2015/11/27/neopixel-current-vs-arduino-power-supply-voltage/
Statistically there will be moments you are drawing the full 18 Amps, filter caps and limiting colour (dim white = 3 LEDs pulsing, dim red = 1 LED pulsing)
Computer USB supplies will normally cut your device off if it draws to much current (you may have already met the OS warning if playing with LEDs) so unlikely to be damaged, dumb wall wart supplies are a different question and may run until destruction, or possibly worse enter a cyclic power up/emergency stop cycle that is very rough on electronics and will probably kill the teensy.

1 - the onboard fuse will taper current as you approach 500mA so fairly safe, see below
2 - Unsure if there is an in code way, one method that also applies to 4 is to monitor the USB voltage via a divider - if it droops then you have exceeded the current available.
3 - Do not believe the Teensy can do the current negiation for USB3.0 but not something I've dug into
4 - see answer for 2, some clever live voltage monitoring and possibly additional poly fuse may do what you want.
5 - If allowing external power you will need some process to separate 5V USB from 5V external otherwise you may be sending 5.1V external power capable of 50 Amp into your PC running at 4.9V - Sane design will avoid problems but better if you avoid this yourself.

Basic option is two diodes in the classic OR arrangement - works and is robust but gives you 4.5V out
You can also look at smart switching arrangements like used in the Uno that are often sold as 'active diodes' to select between power
Some old school barrel jacks have a third contact - with no plug in this contacts the + to run on battery, when plug pushed in this is displaced to feed external power to the device (and isolate the non rechargeable batteries)
 
Last edited:
Thanks GremlinWrangler for this. Very helpful and giving me good pointers to work with.

Your point on the LEDs statistically drawing the max current during PWM pulse high is very interesting and had not occurred to me. The LEDs I am using are RGBW so have a separate LED element for white. So assuming I never mix any of the RGBW elements, the theoretical max current draw at the pulse high should be about 5A? In practice, does this mean I need to spec a power supply to account for 5A even if pulsing it would result into average current draw of much smaller amount? The spec sheet for the LED lists a PWM frequency of 1.2KHZ.
 
Last edited:
The safe answer is that you should be specing for worst case current draw. With very careful code design and power filtering (to spread average current across the 1.2khz PWM surges) you can probably get away with it, especially with some degree of self monitoring watching for droop of the power supply towards the 3.6 volt point where function of the Teensy is impacted, Potential problem of course is that a LED update message is sent that draws to much current to keep the teensy alive but not enough to actually force the LEDs into reset so things get stuck.

How well this works depends on your ability to write code that avoids accidental high brightness, the exact nature of the power supply and how you filter to stabilise the LED voltage, noting that drooping will also cause colour shifts. Access to a decent osciliscope will simplify this (see screen shots on the second softsolder link) since that filtering will be very much experiment and see how it works (resonance that spikes the supply high will kill the Teensy), and certainly your software testing needs to happen with a worst case capable power supply .
 
Status
Not open for further replies.
Back
Top