For some reason (that I can’t recall) I once had the desire to plug my dance pad on the USB port. I tried to find components that would work out-of-the-box as USB joysticks, but this search was not successful. I decided to use a PIC microcontroller, as the 18F line has a few models with integrated USB support.
Getting the chip to be recognized as a USB joystick turned out to be far from easy, and adding the other features was even worse, but there’s at least one thing in which this circuit is simple: its construction.
My initial plan was mostly to take my v1 circuit and somehow plug it into the PIC, that would then be used as a USB interface. But I found out that all the integrated peripherals of the PIC (and a "clever" programming) made it possible to do the capacitive detection with just the PIC and almost no other components (just a few resistors).
A first version of the program, using the voltage comparators of the PIC, gave four inputs, just enough for one dance pad.
A second version, using instead the ADC of the PIC, gives ten inputs, more than enough for two dance pads ! However this version needs a more elaborate software filtering and was a bit more complicated to design.
As I said, it’s very simple:
This one can support one 4-input pad and one 6-input pad (to play the "solo" mode).
Quickly routed version:
The crystal on this circuit is a 8MHz one. Others values can be used but that would require the program of the PIC to be modified.
RN1 and RN2 are resistors networks. Regular resistors can be used instead, but that will take a bit more space on the circuit. I used 470kohm, but I guess values between 330k and 680k could work as well. Since there is a calibration that will be done afterwards, that should not matter too much.
The only difficulty in building this circuit is probably to program the PIC. That requires access to a PIC programmer. The easiest way is probably to use a regular external programmer, and to program the chip before installing it on the circuit. Since I had to develop the program, I instead used ’In Situ Programming’, and on the layout above you can see the ICSP connector that I use with my home-made programmer. Since it’s not standard in any way, I did not include it in the circuit schematic.
Circuit built on a perfboard:
The pins on the top left are my ICSP connector. As someone noticed, I didn’t put the 22pf capacitors, and it happens to work anyway. But that’s not recommended.
You can find the layout I used for this here.
Basically it works that way: one pad at a time, the corresponding pin of the PIC is set as an output pin, high level. This will ’charge’ the pad. After a few microseconds the pin is set to its high impedance state, and the ADC conversion begins. When the conversion is over, the returned value is compared to a threshold, and that’s it. (Mostly).
I have recently found that on some occasions static discharges from the pad can cause the microcontroller to have some kind of erratic behaviour. This problem has been eliminated by adding a 10k resistor in series on each line from the pad. Since there’s no room left on my circuit board I put them directly inside the connectors that I use to link the pad to the circuit:
Update: There should be a small capacitor between pin Vusb (pin 14) and GND. My own pad works fine without it, but if you find that the USB connection becomes unstable, it can help. The cheapest is probably a small 1uF electrolytic capacitor. The value is not critical, anything between 200nF and 2uF should do it.
The pad is recognized by the computer as a USB joystick. Being a standard HID device, it needs no driver.
Proceed to:
Calibration.
Downloads.