Close

No VSYNC? No problem.

A project log for Light pen support for RetroPie

Can a Raspberry Pi with CRT display support 8-bit era light pen?

maciej-witkowiakMaciej Witkowiak 06/07/2020 at 17:200 Comments

(I'm waiting for delivery of LM1881 chips so this is all just speculation).

Plan B

Since I don't know how to use native VSYNC IRQ from RaspberryPi on Linux, and no timing is really guaranteed, obviously I need extra hardware for the lightpen support.

My plan is to use an Arduino Pro Mini (ATTINY would do but I don't have any) with a specialized LM1881 chip to detect VSYNC out of composite signal delivered from RaspberyPi.

LM1881 is video sync separator. It is able to decode composite video signal and provide sync signals. The datasheet is here.

The Arduino should:

  1. Start internal timer
  2. Reset timer on VSYNC interrupt (just before that store internal timer value for calibration)
  3. Wait for light pen sensor signal interrupt
  4. Read internal timer

Using the timer value between two consecutive VSYNCs and time between last VSYNC and light sensor we should be able (after some calibration) to determine X/Y coordinates of the electron beam with an accuracy at least as good as on C64/128.

There is plenty of time for calculations, as the light pen sensor event happens only 50 (or 60) times per second.

The communication of Arduino with RaspberyPi would happen over I2C. Arduino would provide timer values or calculated coordinates on demand.

There are some Arduino projects with LM1881 already:

https://www.open-electronics.org/a-video-overlay-shield-for-arduino/

Discussions