Search This Blog

Tuesday, July 31, 2018

Low Cost KVM Switch

My new 3 port KVM with USB and HDMI 1.4
Projects / KVM Switch  
Original post date: 03/13/2017

KVM is a hardware device that allows you to control/manage several computers from one set of keyboard/mouse and monitor. It is a bit different than a software solution as you can use it at preboot or other situations where the remote viewing software isn't working.

There seems to be a void for affordable modern KVM switches even though all the pieces are out there. Cheap $5 HDMI 1.4 switch has already most of the parts except for switching keyboard and mouse. It is a matter of adding a USB MUX for a minimal functioning KVM. I'll try to use as much off the shelf parts as possible to lower the complexity/cost.

The low end KVM are similar to the old one I have.  It has a pair of PS/2 connectors for Mouse and Keyboard and a VGA input for each port.  VGA is pretty much absent on main stream PC.
My old 4 port KVM
Sadly the ones with more modern day interfaces cost a bit too much for me.  I think can build one cheaper leveraging consumer grade HDMI switch.

HDMI Switching

I have previously opened up a $5 3-to-1 HDMI switch. The HDMI switch is implemented with AZHW37 HDMI mux that is controlled by logic level signals controlled with a 8-pin microcontroller to handle the buttons and selection LED.  This has just enough smarts inside for the video switching in a basic KVM.

HDMI Switch Reverse Engineering



Microcontroller
U3 is an unmarked microcontroller in SOIC-8 that is controlling the HDMI switch. It is probably a good place to attach external cables to the USB MUX.
Pin 1: Vcc
Pin 2: HDMI Switch: S1
Pin 3: HDMI Switch: S2
Pin 4: Push button
Pin 5: J1 +5V sense via 10K series resistor
Pin 6: J3 +5V sense via 10K series resistor
Pin 7: J4 +5V sense via 10K series resistor
Pin 8: Gnd
The +5V presence tells the microcontroller which port has active video. The microcontroller cycles through them each time the Push button get grounded. It'll also switch to the next available video source if the current one is no longer active. This is all we'll need for a minimalist KVM.

The 3 Blue LEDs are buffered by transistors Q1- Q3 scattered on the PCB. They are controlled by the HDP[1..3] (Hot Plug Detect Status) signals which tells the video source that the monitor is present. That save them some extra I/O on the microcontroller.

R10 (1K) control the brightness of the three LED. I swapped it out with a 4K7 as last thing I want is a blue spot light shining just below my monitor.

HDMI Switch

U2 Pin 9 PS: Power saving Selector - pull up by R2.
U2 Pin 22 HDP_ctl: HPD output selector - pull up by R4.

This means that the truth table on page 8 of the datasheet is being used.  I have annotated the port mapping in blue.


Regulator
U1 is a switch mode power supply providing +3.3V for all the circuits. C10 is a bulk cap for the input after 3 Or'ing diodes. On my PCB, it is about 4.22V.

The output connector J2 on the PCB is a bit off centered with respect to the opening in the case. This leaves a gap on the left side where a ribbon cable (up to 8 conductors) can exit.

PS/2 KVM

PS/2 devices are not hot pluggable, so a KVM emulates a pair of PS/2 mouse/keyboards for each of the computers. It pass through keystrokes, mouse events and commands. It also has to remember the LED states of the keyboard/mouse so that it can restore the states switching between different computers.

Unlike PS/2, USB is designed to be hot pluggable. i.e. The KVM (Hub Based) connects/disconnects the USB port for each time it switches. The OS level support simplifies the design a lot. Windows even saves the LED states of keyboard and restores it upon reconnecting.

USB 1.X Switching - The easy way

If you want to switch USB 1.X signals, you can probably get by with a 74HC4052 (Dual 4:1 Analog MUX) in more easy to solder packages. The 74HC4052 covers all the logical combinations, so it is a matter of taking advantage of that to match up with the HDMI switch and discarding the combination not covered by the HDMI.

The connections on the 74HC4052 would probably look like this. S1, S2 are fed from the HDMI switch.


Most of the commodity keyboard/mouse are USB 1.X devices, so this is probably good enough.

You do have to make sure that the USB HUB you are using is only USB 1.x (i.e. 1.5 or 12Mbps) as the MUX is not rated for USB 2.0. USB unlikely Ethernet doesn't falls back gracefully if the signal quality is bad. You just have to shop for the cheapest $2 hubs from China which are still USB 1.1.

Hardware Design

I have decided to try to make a USB 2.0 switch. If used carefully I can attach a USB memory stick or other devices to the hub.

There are proper USB 2.0 MUX out there e.g. On Semi NCN9252. It is a fine pitched (0.4mm) DFN parts targeted for skinny consumer electronic devices. Their pin placements doesn't exactly make sense without a multilayer PCB, but I have to work with what is available.  If you are uncomfortable with these fine pitch, you might want to go with the other alternatives I mentioned before.


As an alternative, one could possibly make a USB 2.0 MUX out of 3 DTDP relays. Short pieces of twist pair from CAT5/6 could be used to wire things together. CAT5/6 have 100 ohms impedance which is within the USB specs.

They use a different combination for selecting the channels than the HDMI switch. 

There are a couple of ways to connect the control pins to the USB MUX.
  • Invert one of the logic signals e.g. S1 from HDMI and relabel the ports
  • A Dual 4 to 1 MUX (e.g. 74HC153) can be used as a pair of 4 entries lookup table.
  • Use a cheap microcontroller to remap the ports. This is what I am using along with an implementation of hotkey support.
I have thrown together a breakout PCB that I am going to order because of the tight tolerances and the high speed signals. There are some additional requirements that I haven't sorted out yet, so those are going to be on a separate PCB with a modular approach.

I used 3 schottky diodes as Or'ing diodes to provide power for the USB hub. The diodes prevent power from leaking back to unpowered PCs. Cheap hubs do away with the protection Schottky diode, so we only have 1 diode drop to worry about. A self powered hub can also be used.



Order from OSH Park

STM8S003 controller board for handling hotkey and HDMI to USB mux mapping.



Order from OSH Park

PCB Signal Impedance
It is hard to get the right impedance on a 0.062" (1.6mm) doubled sided PCB on thin tracks and prototype design rules. (Online impedance calculator: here)


Due to the relative distances vs 62 mil thick PCB, edge coupling will have a significant effect. Normally you are supposed to maintain a few d clearance between differential pair to other signals and grounds. I tried to lower the impedance Z0 by having continuous ground fills right next to the traces. :P


The differential tracks highlighted in yellow has cross section and impedance like this:


USB specs: Differential Impedance 90 ohms +/-15%: (i.e. 76.5R to 103.5R)

Effective Single Ended Impedance for each of the data line = Zd//Z0 = 160R//142R = 75R.
Effective Differential Impedance between the data lines = 2*Z0' // Zd = 150R // 160R = 77R

Note: This is a really rough first order approximation. A 3D field solver would get more accurate results.

In reality, you can probably get away quite a bit as long as you keep the tracks short. I don't think the dollar store sells fully compliant cables, but they sort of works in most cases as the cables are short (1 meter).

This PCB dimension is supposed to fit inside a modified DB25 hood. The PCB to be mounted using the two screws for the clam shell to handle the insertion/extraction force of the USB connectors.

Optional Features
Keyboard Hotkey (Implemented)
Most of the KVM offers a way of selecting the PC host by means of a keyboard sequence. e.g. double clicking CTRL key on my old KVM select the next PC.  A microcontroller can be used to decode the PS/2 keystrokes and simulate a button press on the HDMI switch which then switches between the active sources.


If the keyboard that you are using doesn't use PS/2, then you might need to do one of the following:

1. USB to PS/2 back to USB
USB keyboards are often backward compatible with PS/2 protocols. This is converted back to USB using an inexpensive active PS/2 to USB dongle.

Finally the internal HDMI switch signal is used to select the USB MUX. This might seem like a round about way, but it simplifies the design by not needing to deal with USB.


I don't know if these cheap dongles would handle the new multimedia/internet keys. It might be possible to add the hotkey code to this project: PS/2 to USB keyboard converter for Teensy with mousekeys and NKROP.

HPD handling (Phase II of the project)

"Microsoft guidelines recommend that KVM switches pass unaltered any I2C traffic between the monitor and the PC hosts, and do not generate HPD events upon switching to a different port while maintaining stable non-noise signal on inactive ports." -wiki
This requires a bit smarter handling of the HPD (Hot Plug Detect) status signal to the PC. The idea is to deassert the signal when the PC is initially connected. This allows the PC to read in and configure the monitor DDC data via I2C, but mask the signal when switching to other ports. This way the switch do not need to emulate the DDC for each port.

This would require replacing/augment the existing microcontroller inside the HDMI switch and replacing the HPD signals (from the HDMI MUX) to the connectors.

Ten's EDID Inserter works on a different way by replacing the DCC (at a per port basis) port with a I2C EEPROM to fool the PC.

Firmware

The algorithm for handling the hotkey is documented here: Snooping ps2 keystrokes for hotkey

Hardware

Files are hosted on github.

08/15/2017 - Phase I of the project has been completed.  This project has the same functionality as my store bought $30 KVM



I connected 3 of my PC to the KVM.  Keyboard and USB mouse is connected to the USB 2.0 Hub.  The HDMI switch I am using is smart enough to only switch between the active computers.

The computers can be switched in sequence by double clicking the Left CTRL key on the keyboard.  Switching video source can be a bit slow as the OS detects the monitor and USB devices each time I switch.

This is why I need to compile on the Computer #1 using a KVM in the demo - C compiler with LMFlex licensing doesn't work on RDP connection.  :(


Future improvements

I am hoping to fool the OS that the monitor is connected to it at all times.  Hopefully this would eliminate the OS rearranging windows/screen contents.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.