What does a PC actually do with USB descriptor max current value? - Page 1
Forum section: electronics / projects

author: 741
author_rank: Frequent Contributor
timestamp: April 30, 2021, 03:40:34 pm
content: Say 2 devices are attached, one 'configuration descriptor' says 100mA, the other says 500mA.If the 100mA device tries to draw 150mA, will it actually fail?Or, is the PC software simply adding up the total possible, ready to warn the user if 'too much' total current draw (100+500=600mA here) is possible?That is, does the USB port hardware have a programmable physical current limit?

author: ataradov
author_rank: Super Contributor
timestamp: April 30, 2021, 04:30:10 pm
content: In my observations most do nothing. Actual current limiting would be tricky, since you may have very complicated typologies of hubs, powered and not. I guess it would be possible to add all the currents, and refuse to enumerate a new device. But nobody does that in practice. Most host controllers just have a resettable fuse.

author: Bassman59
author_rank: Super Contributor
timestamp: April 30, 2021, 04:47:31 pm
content: Quote from: 741 on April 30, 2021, 03:40:34 pmThe host port does not have a current limiter to enforce the 100 mA spec. So your device that claims 100 mA but actually draws 150 mA might work. But there's more to it.Part of the issue is managing in-rush current. When you attach a device to the bus, the 100 mA limit is meant to ensure that the voltage on VBUS doesn't droop and trip up everything on the bus. A device which draws more than 100 mA should have a switch to control power on parts that don't need to be present immediately at enumeration and can wait until the host gives the OK to continue. If you don't have such a switch then the in-rush current could be sufficient to cause problems. (This in-rush current limit is why the USB 2.0 spec says the maximum capacitance on VBUS should be no more than 10 uF.)The host keeps track of the total requested draw from all devices connected to a bus-powered hub. Consider three devices which claim to draw 50 mA, 150 mA and 350 mA. Connect the 150 mA device first. It will enumerate. The host knows there's a 150 mA load on the bus. Now connect the 50 mA device. After it enumerates, the host knows that the load is 200 mA. Finally, connect the 350 mA device. It will go through enumeration but the host will refuse to connect it to the bus because the total load will exceed 500 mA. Your computer will throw up a nice message box telling you about this.If that 350 mA device (or the 150 mA device) doesn't have the power switch like I describe above, then when you attach it and the total current draw on the bus exceeds 500 mA, an actual current limiter on the hostwilltrip, you'll get a big warning and everything on the bus will stop working. Well, at least that's the case on Apple products and the Dell machine I have here.Of course, USB 3.0 has a higher output current capability. The draw limit before enumeration finishes is bumped to 150 mA and the total draw is bumped to 900 mA. Since the connector for 2.0 and 3.0 are the same, if you plug a 3.0 device which draws more than the 2.0 spec, you'll get complaints, although I haven't seen a computer with only 2.0 ports in a very long time.

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 30, 2021, 05:25:08 pm
content: Not all hosts handle it the same way, but I can assure you at least some of them (mostly laptops/mobile gear) have current limiters. Usually not ultra-accurate, but if you exceed the max current by a significant margin, the host controller will shut the port off and you'll get a message from the OS (something like "this device has malfunctioned".)Inrush current is typically a problem you are likely to encounter. If not managed properly, upon connection of the device, most desktop computers will usually not do anything about it, but most laptops WILL. That's how many designers have been bitten, especially 10-15 years ago, when most engineers still worked on desktop workstations, and often did their testing on them as well. Once you tried on a laptop - OUCH. Back to square one. Now that laptops are ubiquitous, even in labs, this is something that is much less often overlooked.One sure way of exceeding the max inrush current is to put a large capacitor right across VBUS, which is something many designers would be tempted to do without much thought. Don't do this if you want to keep your customers.

author: Cerebus
author_rank: Super Contributor
timestamp: April 30, 2021, 05:52:34 pm
content: From the USB 2.0 specification, the only one I have immediately to hand:QuoteSo basically current limiting is mandated at the whole hub level, but not on individual ports. I have yet to encounter a hub (built in or external) that implements per port limiting or that manages the current limiting according to the descriptor declared loads. A hub can refuse a request for higher power (i.e. > 100 mA) if it doesn't have the remaining power budget for it. Vis:Quote

author: 741
author_rank: Frequent Contributor
timestamp: May 01, 2021, 03:56:06 pm
content: Ummm... All most interesting.As it happens here I have a small SMPS (TPS61041, 22uH) powered from USB. The descriptor says 100mA, the switcher should be drawing maybe 180mA (factoring in voltage ratio and 80% efficiency).If I power the SMPS from a bench PSU (at 5V), the SMPS keeps the output boosted to almost 12V with a 200R load (60mA output).Actual figures are 12.4V no load, 11.6V with the load, a fall of 0.8V. That is not great, but is acceptable for powering a 78L09.If I use USB power (from a desktop PC), the output of the switcher drops to 10V or so under load, but is fine with no load.----OK, changed the descriptor to 110 --> 220mAGuess what...It works now (!)--->?By which, in detail I mean It works better now. It still drops, but only to 11.2V.---EDIT: I am seeing completely inconsistent results. See later post.

author: ataradov
author_rank: Super Contributor
timestamp: May 01, 2021, 04:56:06 pm
content: This is very surprising. Surprising enough that I would actually try to measure the actual current from the USB. If the host indeed accurately limits the current according to the descriptor, it would be a very rare thing.It is possible that it has a couple modes. One for 100 mA and one for over that limit. So try to change it to 110 mA and see where it goes.

author: wraper
author_rank: Unknown
timestamp: May 01, 2021, 05:19:57 pm
content: Quote from: SiliconWizard on April 30, 2021, 05:25:08 pmBut IME it has nothing to do with max current consumption reported by the device.

author: SiliconWizard
author_rank: Super Contributor
timestamp: May 01, 2021, 05:28:51 pm
content: Whereas the question is interesting per se, and per-port limiting is a rare thing (except for the before-enumeration limit of 100 mA, which is quite commonly enforced especially on laptops), you should never assume anything about it IMO. Especially as a designer of USB devices. Whatever max current you set in the descriptors, design so your device never exceeds that.The question of course is more interesting if you're designing USB hosts, except that from the host side, as long as it can provide the current needed on all USB ports, enforcing the limit would be useless - just do whatever is needed so that your ports can provide enough current for the max current allowed by the standard, and protect them accordingly.The max current setting is, AFAIK, meant to ensure that the host CAN provide at least that much current to the device; if not, it should not enumerate, as the device would not be guaranteed to work properly. But as I said, and as is most often the case (except maybe for very particular hosts), if the host can provide the max per-port current allowed by the standard on all ports, then it doesn't need to do anything more except put a hard limit to protect itself.As said above, the before-enumeration current limit is frequently enforced though. Almost always on laptops, less frequently on desktop computers. To implement that easily, there are quite a few power switches on the market with a simple current limiter that you can enable or disable - look up "hot-plug power switches". Most of them have fixed current limits or programmable through an external resistor; it would be relatively easy to implement both the before-enum and post-enum current limit with them and an additional DAC or digital pot. (I don't know any that have current limits programmable through I2C or SPI, but they may exist!)One reason, from the host side, not to implement the post-enum current limit is that there probably are MANY USB devices out there that exceed their stated max current while operating, at least under some conditions (something they should not do as I said above, but there are many things that happen that really shouldn't anyway...)

author: langwadt
author_rank: Super Contributor
timestamp: May 01, 2021, 06:26:47 pm
content: Quote from: SiliconWizard on April 30, 2021, 05:25:08 pmand the USB only allows 10uF on VBUSI've had laptops that would instantly shutoff if you shorted vbus on USB

author: 741
author_rank: Frequent Contributor
timestamp: May 03, 2021, 01:49:25 pm
content: Did some tests with 18R and 30R and 20mA vs 300mA limit.On the first iteration, I 'clearly saw' how much better the bus voltage held up witrh a 300mA limit....I decided to re-test, making careful note. At this point I was fairly confident of the effect.However, when I re-programmed the 300mA back to 20mA I got 'better' results. In summary, I do not think the bMaxPower value affects the current limit on my machine - but something complex, relating to plug/replug (or just a rubbish USB PSU inside maybe) affects VBUS vs current a good deal.Here are my results - Just a PIC16F1459, nothing else and then the test resistors (After TDD has confirmed settings)First RunUSB bMaxPower = 20mA //Checked in TDD utilityVBUS = 4.83 //or so (from memory)Rload = 30R --> 3.7V //or so, (from memory)Rload = 18R --> 3.5V //or so, (from memory)Second RunUSB bMaxPower = 300mA //Checked in TDD utilityVBUS = 4.93Rload = 30R --> 4.18VRload = 18R --> 3.77VUSB bMaxPower = 20mA //Checked in TDD utilityVBUS = 4.93Rload = 30R --> 4.37VRload = 18R --> 4.00V