Author Topic: usb data lines and switching  (Read 1084 times)

0 Members and 1 Guest are viewing this topic.

Offline lilshawnTopic starter

  • Regular Contributor
  • *
  • Posts: 70
  • Country: ca
  • I break stuff...then fix it...sometimes
usb data lines and switching
« on: August 25, 2021, 06:03:15 pm »
i'm going to be designing a device to switch usb devices on and off a computer system. (the computer will not be running at the time) they are extremely low current devices and don't require any kind of sustained transfer speeds or anything like that ... but they cannot all be just plugged in without interfering with each other. so the plan is to switch the device i need at the time "on" leaving the others "off".


so I have one USB-B port with a cable going into the computer and multiple USB devices plugged into a "hub" of sorts. (a series of USB-A ports)

my plan is to tie all the ground/D+/D- lines together, then use a ULN2003 to "switch" the USB5+ power "on" from the USB-B port to the appropriate USB-A port. essentially "powering" the individual USB device. keep the data line runs as short and even as possible to eliminate any kind of corruption or interference.

is it okay to tie these data lines together in this fashion?

(scabbed together schematic for reference)

thanks for your help!
 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5055
  • Country: ro
  • .
Re: usb data lines and switching
« Reply #1 on: August 25, 2021, 06:52:19 pm »
The uln2003 is gonna have a significant voltage drop.

I also wouldn't tie the D+ and D- wires together.  Consider analog mux chips or mechanical relays.

Mechanical relays would be easiest, as you'd have the lowest resistance, and they're cheap..  a 5v DPDT relay is 1$ and let's you switch the D+ and D- wires between 2 ports , so 3 relays would be enough for the data wires.

Here's an example of a DPDT relay : https://www.digikey.com/en/products/detail/cit-relay-and-switch/J104D2C5VDC-20S/12503179
See datasheet at page 2 for how the pins of relay are positioned.

The ground wire can be kept always wired, for the voltage wire you'd have to use either relay or have it hardcoded on the selector switch.
You could use a 4 position slide switch with 2 sets of contacts , a set could be used to route the voltage, the other could be used to turn on the specific relays

relay 1  - default off = port A   , relay 1  - on  = port B   
relay 2  - default off = port C   , relay 2  - on  = port D

Relay 3 connects either relay 1 outputs or relay 2 outputs to computer port

relay 3  - default off  = relay 1  , relay 3 - on  = relay 2

So : 
port A  :  relay 1 off, relay 2 off (don't care) , relay 3 off
port B  :  relay 1 on , relay 2 off (don't care) , relay 3 off
port C  :  relay 1 off (don't care) , relay 2 off ,  relay 3 on
port D  :  relay 1 off (don't care) , relay 2 on , relay 3 on

So worst case scenario, you're gonna 2 relays energized, consuming maybe 30-50mA from 5v.

The design isn't safe to switch between ports live, as there's a delay until a relay turns off and until the other relay turns on, so if you slide between positions it could be that data wires of two ports would be simultaneously connected.
But, you can simply add a on/off switch to disconnect the whole box from 5v input, wait a second or so, change the slider position,  turn back on ... and you don't have to reboot the computer.

You'll need to add one diode to each relay for protection but that's easy, if you're a beginner you'll find tutorials on the internet about why that's needed..


« Last Edit: August 25, 2021, 06:57:10 pm by mariush »
 

Offline lilshawnTopic starter

  • Regular Contributor
  • *
  • Posts: 70
  • Country: ca
  • I break stuff...then fix it...sometimes
Re: usb data lines and switching
« Reply #2 on: August 25, 2021, 07:55:29 pm »
thank you for your insight.

you are correct, i have no plans to switch this live. it will be done before the computer is switched on, and powered off before it's changed.

you think something like a MAX4899AE would work better in this instance?

IE power all the usb devices and then switch out the D+ and D- lines with the 4899? devices consume about 50ma peak each, so powering all the devices is not an issue.
 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 5055
  • Country: ro
  • .
Re: usb data lines and switching
« Reply #3 on: August 25, 2021, 09:22:50 pm »
Yeah, looks like it would work.
That chip works with max 3.6v, so you'd probably want a 3.3v linear regulator powering it.
I'd still keep the ports unpowered, and power only the active port - basically device has to be powered to communicate with the pc to initialize. If you plug device and gets powered and then you turn on the pc, the device may not work until it's reset again.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf