R/C USB Joystick Interface - How it works
I delayed tackling this project as I did not have any way to create Windows drivers. And then I found out that I did not need to!
The USB connection is much more than a high speed serial connection. A great deal of thought went into considering what type of devices would likely need to be connected to a PC and what sort of data exchage would be required.
One class of devices is call 'Human Interface Devices' or HID. Within this class are sub-classes including gamepads and Joysticks. The detailed setup recognises that joysticks and gamepads will have such things as X,Y controls, throttle, rudder, hat switches, buttons and so on.
So how does the PC know what a USB device is? This is pretty staightforward - in theory at least! When a USB device is connected a pullup resistor tells the PC what speed it runs at, and the PC then asks the device to say what it is.
When first conected the R/C USB Joystick tells the PC:
- Version of USB spec supported
- Power consumption
- It is a Human Interface Device
- It needs one communication link, with 5 bytes of data to checked at least every 10ms
- It is a Joystick
- with X,Y (aileron/elevator), throttle, rudder and 4 buttons
- and the first 4 bytes of 'report' data describe the 4 axes
- and the last byte of data holds the buttons
Having set up the PC USB link the next task was to collect the data from a transmitter
The transmitter code (PPM) is a series of pulses of length 1-2ms. The length (duration) of each pulse has to be measured to convert it into data for the PC. My first prototype used just one microcontroller (PIC) to both handle the USB requests for data and measure the transmitter code information. This worked moderately well but had two drawbacks. There was an occasional glitch when the pulse measurement could not be taken because the microcontroller was servicing a PC request for data, and this special USB PIC had not non-volatile memory to store information on the transmitter code sequence and each pulse direction. So I moved to using two microcontrollers - one to concentrate on collecting the code information from the transmitter and a second to concentrate on servicing the USB connection. The first PIC has a 4Mhz clock and the second a 24Mhz clock - as fast as my first PC!