Close

Design and theory of operation

A project log for Lightpen to USB HID interface

Bring CRT displays and light pens into 21st century

Maciej WitkowiakMaciej Witkowiak 05/24/2021 at 18:510 Comments

Circuit

Video input comes from composite video source and works as a passthrough. I have used one male and two female connectors to make it easy to connect as a passthrough no matter what cables are available.

The LM1881N video decoder chip is an interface between video and Arduino. The signal changes on VSYNC (pin 3) and COMPOSITE SYNC (pin 1) are timed by Arduino and used to prepare HID report for host. The decoder is wired exactly like in the datasheet application example schematic, using two 0.1uF capacitors and one 680K resistor.

The male DE9 connector is a socket for lightpen. Pin 3 is the push button (active low) and pin 6 is the light pen signal from phototransistor (also active low) whenever electron beam passes in front of light pen lens. You need to provide power to light pen, so pins 7 and 8 must be connected to common 5V bus and GND (respectively).

Operation

Timer1 is setup to count without prescaler (so 16MHz) and with interrupt on capture (change on pin 4, ICP1, connected to pin 6 on light pen cable).

Another interrupt is triggered by high to low transition on pin 7, connected to VSYNC.

After every low to high transition on COMPOSITE SYNC (pin 9 on Arduino) row counter is increased, Timer1 is reset to 0 and starts counting time for the current row.

If there is ICP interrupt the current row numbe and current Timer1 value are saved for later use.

After every VSYNC interrupt a HID report is prepared if there was ICP interrupt event:

  1. row number is our Y position
  2. Timer1 value saved in ICP is our X position
  3. button state is compared with last state
  4. x/y values are smoothed and rescaled
  5. HID report is sent to USB host

Relevant events are cleared. The row counter is set to zero, a new image frame starts.

Discussions