An input/output controller for virtual pinball machines, with plunger position tracking, accelerometer-based nudge sensing, button input encoding, and feedback device control.

Dependencies:   USBDevice mbed FastAnalogIn FastIO FastPWM SimpleDMA

You are viewing an older revision! See the latest version

Homepage

This project turns a KL25Z into a USB peripheral device for virtual pinball cabinets. It looks to the host computer like a USB joystick, so it's plug-and-play with Visual Pinball on Windows - the built-in Windows HID driver recognizes the joystick configuration, so no driver software is needed on the PC. Visual Pinball is set up to take plunger and nudge input from a joystick natively, so the only configuration required is to turn on joystick input in the VP keyboard preferences.

Hardware build guide (PDF)

Functions:

- Plunger position sensing, using a TAOS TSL 1410R CCD linear array sensor. This sensor is a 1280 x 1 pixel array at 400 dpi, which makes it about 3" long - almost exactly the travel distance of a standard pinball plunger. The idea is that you install the sensor just above (within a few mm of) the shooter rod on the inside of the cabinet, with the CCD window facing down, aligned with and centered on the long axis of the shooter rod, and positioned so that the rest position of the tip is about 1/2" from one end of the window. As you pull back the plunger, the tip will travel down the length of the window, and the maximum retraction point will put the tip just about at the far end of the window. Put a light source below, facing the sensor - I'm using two typical 20 mA blue LEDs about 8" away (near the floor of the cabinet) with good results. The principle of operation is that the shooter rod casts a shadow on the CCD, so pixels behind the rod will register lower brightness than pixels that aren't in the shadow. We scan down the length of the sensor for the edge between darker and brighter, and this tells us how far back the rod has been pulled. We can read the CCD at about 25-30 ms intervals, so we can get rapid updates. We pass the readings reports to VP via our USB joystick reports.

I'll publish schematics showing how to wire the CCD to the KL25Z. It's very straightforward - five wires between the two devices, no external components needed. I use two GPIO ports for digital outs to send signals to the device and one as an ADC in to read the pixel voltage levels (== brightness).

- Nudge sensing via the KL25Z's on-board accelerometer. We operate the device in its 2g (-1g..+1g) mode at 800 Hz, and pass the acceleration readings to the PC via our USB joystick reports.

- LedWiz emulation (limited). The device emulates the LedWiz USB interface, so controllers on the PC side such as DirectOutput Framework can recognize it and send it commands to turn lights, solenoids, and other feedback devices on and off. We assign 32 of the KL25Z's GPIO ports for this purpose. This part is still experimental, and it's somewhat limited. The KL25Z only has 10 PWM channels, so we can only provide 10 outputs with intensitiy control - in our default mapping, LedWiz ports 1-10 are PWM capable, and the rest are not. Intensity level settings to other ports will be ignored, but they can still be switched on and off. We also don't implement any of the LedWiz flashing modes; we only implement on/off (on all ports) plus intensity (only on the PWM ports). (I don't think the lack of flashing modes matters for DOF, because I think DOF handles all such effects itself using the on/off primitives.)

To use the LedWiz emulation to control physical devices, external hardware is obviously required. The KL25Z ports are limited to 4 mA, so they can't even drive most optocouplers directly. I'll publish a reference circuit design for how to hook up an output to a real device, but here's the outline: each KL25Z GPIO port must be connected to the base of a suitable NPN transistor, whose collector drives an optocoupler input. The optocoupler output should in turn drive a MOSFET gate (N-channel, enhancement mode), and actual feedback device can then be connected between power (+ supply voltage) and the MOSFET drain. A flyback diode should be placed across the feedback device's +/- terminals if it's any sort of inductive load (solenoid, coil, contactor, relay, motor, etc). For smaller loads, a suitable high-power Darlington transistor connected directly to the GPIO port could be used to drive the load directly (so the optocoupler and MOSFET can be omitted), but I'd prefer to spend the extra $1.50 per channel and make sure the KL25Z is fully isolated (via the optocoupler) and that ample output current is available (via the MOSFET). Inexpensive MOSFETs are available that will drive gigantic (by virtual pinball standards) current loads, and I feel better if there's lots and lots of headroom in the power limits.


All wikipages