USB Voltage Sag
I received a couple of reports that Retro USB doesn’t work correctly with the Apple Aluminum Keyboard, model A1243 and its smaller sibling A1242. This is Apple’s standard wired USB keyboard, so it’s fairly common. The A1243 has an integrated hub with two USB ports for other devices. I don’t have one myself, but I was able to borrow an A1243 from a neighbor so I could take a look. What I found was not good.
During the USB enumeration process, there’s a huge voltage sag on the VUSB +5V supply. This is true whether VUSB is fed from the Macintosh’s ADB +5V supply, or from an external 5V supply. During USB enumeration, VUSB abruptly drops from 5V down to about 2.7V over a period of half a millisecond. Then it recovers, drops again, and repeats the process three or four times. Meanwhile the microcontroller starts reporting USB “bus turnaround” errors. Eventually the voltage bouncing stops after about 6 ms, but the keyboard never enumerates successfully.
At first I thought this was a simple problem: I just needed a bigger capacitor on VUSB. When the A1243 enumerates, it must switch on some internal power-hungry circuit that momentarily draws a lot of current, dragging down VUSB. The Retro USB board has a single 10 uF ceramic capacitor on the +5V USB supply. But when I tried larger capacitors up to 220 uF, they barely made a dent in the degree of voltage sag. With the 220 uF cap, the voltage sags bottomed out at 3.4V instead of 2.7V, but I still got lots of USB errors and failure to enumerate. 220 uF is already a jumbo-sized capacitor, and I can’t imagine fitting something even larger on the Retro USB PCB.
My second thought was to add an inline inductor between the VUSB supply and the USB connector. That would prevent too much current from being drawn all at once. I only had a single suitable inductor on on hand, with an uncertain value: the bag said 22uH, but the component was labeled 223 which I believe means 22mH. At any rate, it didn’t help much, and VUSB still sagged down to 3.2V while the keyboard failed to enumerate. With failures of both the capacitor and inductor techniques, I’m out of other ideas for ways I can minimize or eliminate this VUSB sag.
But wait, there’s more to this mystery. The A1243 actually enumerates OK, with no VUSB sag at all, if nothing is connected to its USB ports. It’s only when a mouse or a flash drive is connected to the A1243 that the big voltage sag occurs. And these same mice and flash drives don’t cause any voltage sag when they’re connected through a different unpowered hub. I’ve come to the conclusion that the A1243 contains a big capacitor that only gets charged during USB enumeration, and only if something is connected to one of its hub ports, so that the hub function is enabled.
I was sometimes able to get the A1243 with an attached mouse to enumerate successfully, if I powered the Retro USB board from an external 5V supply instead of the Macintosh ADB 5V supply. The same degree of voltage sag was still there, so I’m not even sure why it worked, and success seemed to depend on exactly which mouse I tried.
The A1243 also causes problems in other scenarios, even where no voltage sag is observed. It works OK when it’s connected through a separate unpowered hub. But if a mouse is also connected to that same hub, there’s no voltage sag, but there are large numbers of USB errors and none of the devices ever enumerate successfully.
There’s clearly something strange about the A1243’s power requirements, as evidenced by this Apple forum thread full of complaints. A hundred people all agree that their computer wasn’t recognizing their A1243 anymore, until they used the USB extension cable that’s bundled with the keyboard, then it magically began working again. A few people said a 3rd-party USB extension cable also solved their problems. It sounds bizarre, but if the extension cable is acting as a small source of additional inductance and capacitance, I could imagine it having a beneficial effect. However, when I tried using the extension cable with Retro USB and the A1243, the voltage sag was still just as bad and the problems remained.
If the A1243 weren’t such a common keyboard, I’d simply write it off as an unknown incompatibility. But given how common this keyboard is, I really want to find a way to make it work.
Read 12 comments and join the conversation12 Comments so far
Leave a reply. For customer support issues, please use the Customer Support link instead of writing comments.
Thanks for looking into this. The A1243 is the only keyboard I use – it’s the best I’ve had, and I need the extended part of it.
I don’t think the A1243 *with a mouse attached to it* will ever work with the current Retro USB hardware. It draws way too much current momentarily when its hub function is enabled, and the board can’t supply it. From searching the web, I see that the A1243 causes problems on many computers, so it’s not just limited to Retro USB.
I think the A1243 probably can work with the current Retro USB hardware if the keyboard’s built-in hub isn’t used. That means attaching the mouse and the A1243 to another hub. In the blog post I said this didn’t work, but I later found that it does work, as long as the keyboard is connected to a higher-numbered hub port than the mouse. I tested all possible permutations of port connections to confirm that’s true. I’ve no idea why, but I suspect it’s a bug in the USB stack’s code. At first I thought it might be a general problem with cascaded hubs, but when I tried the older A1048 keyboard (which also has a built-in hub), it worked fine no matter what numbered ports the keyboard and mouse were connected to.
A hypothetical future revision of Retro USB could probably work with the A1243 with a mouse attached to it, if I can find a way to limit the voltage sag during enumeration. I was finally able to get the A1243 with an attached mouse working with 470 uF of output capacitance for VUSB, so it’s possible. But the voltage still sagged momentarily to 3.9V, which is scary. And 470 uF of capacitance would break ADB-to-USB mode, unless I also made other changes to the hardware’s design. That might be an investment of time and money that I can’t justify, even if the A1243 is a popular keyboard.
The funny thing is that if the A1243 just had a big capacitor directly connected to VUSB, instead of one that’s dynamically switched, it wouldn’t really be a problem. There would be a big inrush current at insertion time, which is what you typically read about when there’s discussion of USB current problems. But if the system booted up with the A1243 already connected, it would be fine. By delaying the moment of peak current demand until the A1243’s hub function is enabled, after the host selects a USB configuration, it makes the problem much worse.
OK, here’s the secret formula for the A1243 with the current hardware and firmware:
1. Connect a hub to the Retro USB
2. Connect a mouse to the hub
3. Connect the A1243 to the hub, on a higher-numbered port than the mouse
4. Don’t connect anything to the A1243 built-in hub
See diagram. If you’re unsure how your hub ports are numbered, try it one way, and swap the connections if it doesn’t work.
I’ll keep looking into why this works, and how to manage the current demand of the A1243 built-in hub with an extra capacitor or other hardware change.
Continuing my monologue, and thinking further about the voltage sag when using the A1243’s built-in hub: I think an inductor is the wrong approach. An inductor would limit the 5V voltage sag as measured at the Retro USB board, but it would do nothing to help the A1243 downstream. The keyboard would still see its supply voltage sag way down, until it no longer worked correctly, causing the enumeration process to fail. If I want this to work, I think the only viable approach is to somehow *feed* the current surge rather than trying to prevent it, and that basically means a capacitor. I’ve seen that 470 uF of capacitance works, although the amount of voltage sag is still uncomfortably high, and it might need as much as 1000 uF to limit the sag to an acceptable level. That seems like a whopping huge amount of capacitance, and makes me suspect I’m approaching this problem the wrong way. But maybe my expectations are wrong and a jumbo capacitor is a fine solution.
Not directly related, but I’d be interested in hearing what tools you use– i.e. logic analyzer, oscilloscope, etc. You’re doing pretty neat stuff, and are way ahead of me in the projects you’re tackling, so it would be great to hear what you’re happy with, what you’d like to change, etc.
I remember some manufacturers have produced USB keyboards that intentionally violate the USB specs. I think I\’ve seen a DELL(?) USB keyboard rated 5 V 1.2 A that required a special USB port (but with a standard USB connector) to provide two USB ports each supporting 500 mA.
I would try to measure the problematic keyboard supplied by a PC or Mac, and compare that with the Retro-USB. I can imagine that the keyboard uses some non-standard techniques to test the host\’s supply capabilities.
I would also try to supply the keyboard from a good lab supply, and measure that, initially limited to 500 mA (USB spec), then increase to 1.2 A (200 mA for the keyboard, 2x 500 mA downstream), and finally to 2.5 A (USB A connector limit).
@Roy, all of the measurements described here were collected with a Saleae logic analyzer, which also has an analog measurement function. http://www.bigmessowires.com/2015/01/07/saleae-pro-8-logic-analyzer-review/ I also have a Rigol oscilloscope that I very rarely ever use: http://www.bigmessowires.com/2013/12/06/rigol-ds1074z-oscilloscope-review/
@Tux2000, you may be right the keyboard violates the USB spec. On the bottom of the keyboard it says 5V 1A, which would certainly violate the spec for a bus-powered device if it’s accurate. The USB descriptor says it uses 300 mA max, which sounds more likely. But the problem isn’t really the continuous current demand anyway, but the brief inrush current over a few milliseconds when the built-in hub ports are enabled. I can follow all the sub-steps of the enumeration process up to that point, and it doesn’t seem to be doing anything unusual.
470 uF of output capacitance isn’t quite as absurd as I initially thought, and modern capacitors in that range aren’t so physically large as I’d feared. Looks like the USB spec actually calls for 120 uF minimum, so my existing 10 uF is definitely woefully inadequate. A TI hub example I looked at showed 220 uF output capacitance at each port, and a 1000 uF bulk capacitor at the power input. Several examples also showed ferrite beads before the output capacitor at each USB port. I think those were more to filter noise than to limit startup current though. You can tell I’m out of my comfort zone here and not really sure what the heck I’m doing…
You’re right in thinking that ferrite beads are for noise suppression. They increase the inductance in the wires, and hence slow down the edges of digital signals. As for the capacitor, remember that you can wire capacitors in parallel, and the capacitance value adds up. So to get about 1000uF, you could use two 470uF in parallel, or three 330uF, or maybe five 220uF. That may make the physical arrangement a bit simpler than having one big 1000uF capacitor.
John is right, you can use several caps in parallel. As a very welcome side effect, this can reduce the overall impedance. Using low-ESR models reduces it further, improving the reaction to load peaks.
A common solution for nasty loads is to have one or more big caps wired in parallel for slow peaks, then a little cap around C/10 to C/50 for medium speed peaks, and a non-electrolytic cap around C/100 to C/1000 for fast peaks, all wired in parallel, close to the load.
Also, you don\’t have to use physically big caps. Modern low-ESR caps are quite small. And luckily, USB requires only 5 V, so you can get away with 6.3 V SMD models.
I assume a drop from 5V to 2.7V over 0.5 ms is considered a slow peak? 0.5 ms is a long time in computer terms. Digressing a little, do you think a 6.3V rated capacitor is enough for a 5V design? I’d been reading some advice that suggests derating the capacitor by at least 2x, so that would mean a minimum 10V rating. The idea was to avoid routinely operating the capacitor close to its rated maximum voltage, just to be extra-safe, but maybe that’s being overly paranoid.
The capacitor’s physical size doesn’t seem to be the problem I’d feared. I have some 220 uF capacitors here that are the size of my thumb, which is what I was looking at when I got worried about the size of a 470 uF or 1000 uF. But the ones I have are probably 10-20 years old. As you said, modern ones seem much smaller.
For rework of the current board version, I’ll have to use a single PTH capacitor, since that’s all I can realistically fit. Looking at http://www.newark.com/rubycon/16pk680mefc8x11-5/aluminum-electrolytic-capacitor/dp/39T8553 or https://www.digikey.com/product-detail/en/rubycon/10PK1000MEFC8X11.5/1189-1050-ND/3133980. If I’m able to redesign the board in the future, I can switch to SMD capacitors, either one large one or two smaller ones in parallel.
Argh, it seems the “secret formula” work-around for the A1243 that I posted above doesn’t work, at least not reliably. I’d thought there was only a big voltage sag when another device was connected to the A1243’s built-in hub, but it appears that’s incorrect. I’m testing with a different A1243 now (the first one was a loaner), so maybe there’s some variation, but at least with this one I always get the big voltage sag. That means there’s no work-around possible aside from a hardware modification to the Retro USB, or else using a powered hub for the A1243.
Have you tried detecting the situation, and simulating a unplug/replug sequence to see if that works? If you luck out, you\\\’ll be able to fix it in software alone.