AllTimer: GPS-based timing for analog and USB video cameras, plus PC time synch
Frank Freestar8n
AllTimer is a multi-function timing device for time stamping both analog (NTSC/PAL) video cameras, and digital (USB/Firewire) video cameras. In addition, it allows accurately setting the time of a laptop in the field via USB. Although AllTimer is a work in progress, subject to design changes, this is a summary of the current goals and components.
AllTimer is designed to be easily constructed from modular components, with functionality integrated by a microcontroller. A key design goal is that the OSD (On Screen Display) of timing and video frame counting is separate from the GPS module. The intent is to allow multiple OSD devices to be individually synched to the GPS module and then disconnected, while the video continues to be stamped with the running frame count. This allows a low cost way to have multiple video sources keep time using a single shared GPS module while still keeping explicit track of the frame count in the video.
Another design goal of AllTimer is to leverage USB functionality. The USB port provides a convenient power source, ability to time-synch a laptop in the field, and firmware upgrades.
An overall goal is to automate as much as possible the reading of time and the extraction of events from long video recordings. This avoids clerical errors and possible bias by making the whole process automated and deterministic.
Main components of AllTimer:
PIC18F4550 microcontroller at 48MHz
This is a powerful 8-bit microcontroller with built-in USB functionality. It allows 48MHz internal operation driven by an external 8MHz crystal, and the higher speed is beneficial for critical timing applications. It has flash functionality that allows firmware upgrades via USB booloader, allowing program updates and bug fixes without removing or replacing the chip.
MAX7456 OSD module
This module allows insertion of text in both PAL and NTSC video at high speed, with a high quality font and no added noise in the video. The module offloads the complexity of having the microcontroller actually draw the text onto the streaming video, and transparently handles NTSC and PAL.
Venus634 GPS module with PPS output and battery backup
This is one of many GPS modules available with PPS output. It has an internal battery-backed real time clock (RTC) that allows rapid acquisition of satellites.
2x16 COG LCD display
The LCD allows display of status messages and time info independent of a video display.
12-bit DAC
This drives the LED for optical time-stamping of USB video cameras.
PIC-Ready1 prototype board from mikroElektronika
This board is a good size for the support electronics and microcontroller port connections.
Separate LED projection device contained in T-thread adapter, to project a small spot onto a USB video camera's CCD. The spot changes intensity in a triangle wave synched to GPS time, with a brief blanking interval on each minute.
AllTimer Functionality
AllTimer measures time in 0.1ms increments. Although this level of granularity may be overkill for most timing applications, it allows better integrity checks and a more accurate calculation of the frame rate. The time scale of operations is: 8MHz crystal driving the microcontroller; 8MHz is scaled up by PLL to 48MHz internal to the microcontroller, resulting in 12 million instructions per second, or 0.08us per instruction. The time ticks are every 0.1ms, or 1200 instructions per time tick. The NTSC video rate is about 16.7ms per field, or 167 time ticks per field.
The video display has two lines. The first line shows the current time and frame count – plus the time since the last frame measured to 0.1ms. The second line sequences through several items that are not time critical, including date, longitude, latitude, elevation, frame rate based on prior 10 seconds, operational status, and more.
The LCD display shows status messages as the GPS link is acquired, then switches to a two-line display similar to the on-screen display lines.
AllTimer has three main modes of operation: Video OSD time-stamping, LED-based optical time stamping for USB video cameras, and USB-based time synching of a laptop in the field.
AllTimer is powered by USB connection or 12V supply.
The on-screen text uses a large, clear font that should be easy to read automatically with character recognition code.
A blinking LED allows calibration of the video camera using software that reads an AVI to parse the time stamp and measure the precise on/off times of the LED using interpolation. This should allow estimation of any delays in the video readout relative to the time stamp, in addition to an estimation of the blanking interval, if present.
One intended mode of operation is to allow remote control operation of a video camera after the GPS module has been removed. The operation would be: Set up AllTimer with GPS module and video camera and record for 1-2 minutes to start the frame count and obtain a good estimate of the frame rate. Then remove the GPS module and turn off the video recorder, but keep the camera and AllTimer running and counting frames. Later, the recorder will turn on and record the event with the still-running frame count. When the equipment is recovered, reattach the GPS module and record another minute or two of video to time stamp the still-running frame count and record an updated frame rate. This should allow high integrity interpolation of event times based on frame count even if the GPS module is not present during the event because the frame count is persistent throughout, and you have good estimates of the frame rate before and after the event – plus good time stamps on frames that bracket the event.
AllTimer Implementation
AllTimer is written in C with MikroElektronika's MikroC Pro development environment.
All the components are available as discrete IC's, but to simplify construction I use “breakout boards” that include much of the support circuitry for each module. This increases the cost and makes the assembled device larger, but avoids the need for a custom circuit board and minimizes soldering, particularly of surface mount components, allowing someone with modest skills and equipment to assemble it. The whole thing could be done very compactly, however, with a custom circuit board and discrete surface mount components.
The 0.1ms timing resolution comes from a timer/counter in the PIC18F4550 that is dynamically phase locked to the GPS 1PPS (one pulse per second) signal. This avoids the need for a separate time source, and the continuous phase locking compensates for any temperature drift of the microcontroller crystal oscillator.
The three main periodic signals: Timer ticks at 0.1ms, Video frames at 17 or 20ms, and PPS pulses every second, are all independent interrupts handled with low latency and without polling.
Communication with the OSD and DAC is via high-speed SPI (Serial Peripheral Interface). The speed is essential since the OSD messages must be delivered at the beginning of each new video frame. Communication with the GPS is via RS232 serial. Only the video time (first line of text) is updated on each video frame; the second video status line and LCD text are updated on alternate frames.
In USB video mode, the OSD is not active and instead the LED intensity is set every millisecond by the DAC. This is to allow much higher frame rate with USB video cameras.
Every 10 seconds the frame rate is calculated accurately, to allow extrapolation of times based on frame number if the GPS is disconnected. In 10 seconds with 0.1ms accuracy the resulting frame rate is good to 6 decimals, or an extrapolated error of 10 ms in 2.5 hours. This is likely more accurate than drift due to temperature, which itself can be estimated by the changing rate every ten seconds.
Examples

This is the appearance of video from a PC-164C NTSC video camera timestamped by AllTimer. The numbers are fairly large, which necessitates the use of only two lines for data output. The first line shows the time, followed by the video field count to seven digits, and then the time since the last field. This is an interlaced frame containing two fields. The second line shows the exact frame rate during the last ten seconds – plus additional data. The second line cycles through a number of status messages, each being held for four seconds. Note that this was captured indoors, under a roof, and the Venus634 had no trouble locking onto GPS satellites.

This is the same image as above, but split into separate fields by LiMovie. Note that the digits show clearly and should be readable with very few errors using relatively simple OCR code. The appearance should be nearly identical with PAL instead of NTSC. The time of the second field is consistent with the previous field plus the indicated time delta of 16.7ms. In practice, for NTSC video the time delta is either 16.6 or 16.7ms when things are working properly – and the consistency of the time delta serves as a good diagnostic.

This is an actual graze observation using a USB video camera and LED projected onto the CCD driven by AllTimer. The event times were analyzed by LiMovie and reported directly based on diffraction fits to each D and R, with no consideration or bias of the expected times based on detail in the limb. They were then reported blindly in the graze report form, and the results returned show excellent agreement with the high resolution limb profile. (If you don't see them, note the tiny black dots where the smooth curve crosses the limb. Each dot is a D or R observation reported based on timing with the USB camera and AllTimer).
Additional features and options
Software utility for synching pc clock to AllTimer via USB
Software utility for updating AllTimer firmware via USB
Software utility for reading time stamps from AVI and optionally analyzing blinking LED to calibrate video camera. This also lets users test the device themselves with long video runs where each time stamp is checked.
Software utility to cut a section of video from a long AVI centered around a specified event time. If the GPS time is not available due to removal of the GPS module, extrapolate the frame number based on the previously measured frame rate.
Give each AllTimer unit a unique ID that is displayed in video to help keep track of multiple videos from multiple stations.
Optionally disable display of Lat/Long from video for privacy concerns. Always show it on the LCD display
Optionally include a temperature sensor on the circuit board to display a temperature reading in the video. Even if this is some distance from the camera, it may be a useful guide to the conditions at the site during the measurement.
Status and future
The key components of video and USB time stamping with concurrent LCD display are in place, but integrity checks are needed to confirm it is working properly. I have done some work with the bootloader, needed for firmware upgrades via USB, but that has not been implemented yet in the full application. Currently AllTimer does not allow loss of the GPS 1PPS signal, which needs to be handled gracefully while keeping track of the frame count. I already have code for parsing AVI's and decoding time stamps, but that will need to be modified for this new format in order to make some of the software utilities that rely on reading timestamps. I have done some USB communication with the PIC18F4550 microcontroller, but I do not have the PC synching application in place yet.
Why am I doing this
I am mainly doing this because it is a fun project and the task is much easier with readily available modules to handle some of the dirty work. I plan to use it in a number of astronomical timing projects. I am also interested in seeing the limits of timing accuracy based on video, via model-based fits to the recorded light curves for sub-frame timing accuracy.
I am not aiming at providing a product and am willing to share what I am doing with others involved in similar efforts – but by posting this publicly I hope that anyone who benefits from this write up will kindly cite this work.
Related work
KIWI-OSD has been a standard for occultation timing, but is no longer available. It is microcontroller based, and the microcontroller itself is writing the time stamps onto the video. http://www.pfdsystems.com/kiwiosd.html
PICO OSD is a nice demonstration of how easy it is to use a microcontroller to do video OSD. It does not do GPS timestamping, but just shows a simple version of OSD. I chose to use a dedicated OSD module to reduce the chance of a timing conflict, and to guarantee the video has no noise introduced. http://www.micro-examples.com/public/microex-navig/doc/081-pic-osd-superimposer.html
OSD-GPS is one of several devices for OSD video showing GPS information, but it does not appear to have millisecond resolution. Such devices typically just use the serial stream from the GPS and not the 1PPS signal. http://www.icircuits.com/prod_osdgpsid.html
I have numerous write ups on video timing accuracy at http://www.astrogeeks.com/Bliss/OccultVideo/index.html
I have an early write up of the AllTimer for use with USB video cameras at http://www.asteroidoccultation.com/observations/NA/Meeting/USBTimingTalkFrankFreestar8n.pdf