Measure Screen Latency With Raspberry PI and Oscilloscope
by arpruss in Circuits > Raspberry Pi
553 Views, 0 Favorites, 0 Comments
Measure Screen Latency With Raspberry PI and Oscilloscope
Measuring screen latency is simple. You just draw something on the screen and measure the delay between drawing and display. If you have a Raspberry PI, there is a device for doing this, or you can use a camera. But I felt that for me the simplest way of doing it would be a photodiode and an oscilloscope. The PI writes to a GPIO pin hooked up to one oscilloscope channel which you trigger on, the PI then flips the screen between black and white, a photodiode connected to a second oscilloscope picks that up, and you can see the lag.
Supplies
- Raspberry PI
- oscilloscope
- photodiode
- 10k resistor
- power supply for photodiode
The Photodiode Circuit
I just breadboarded this simple circuit. I used an on-breadboard power supply. If you don't have one, you can use the Raspberry PI's 3.3v output (or the 5v output if you like).
Software Setup
1. Install pigpio on your PI:
sudo apt-get install pigpio
2. Download lagtest.c to your PI.
3. Compile with:
gcc -O99 -o lagtest lagtest.c -lpigpio
4. Reboot to a commandline by running
sudo raspi-config
and selecting Boot Options, Desktop, Console and rebooting with
sudo reboot
5. Log in and test with
./lagtest
You should your screen flash every two seconds between black and white. Press ctrl-c to stop.
Measurement
1. Attach one oscilloscope channel to the photodiode circuit
2. Attach the other one to GPIO 21 and ground on the PI (see diagram here).
3. Put your photodiode against the screen, pointing towards it.
4. Run
./lagtest
5. Set your oscilloscope time scale so you can see about 100 ms (you may need to zoom in later for greater precision) and the transitions on both the GPIO and the photodiode channels.
6. Set the oscilloscope to trigger on GPIO 21. I will assume rising edge, as I measured black-to-white transition latency, but you can use falling edge to measure white-to-black latency.
7. Your lag is the offset between the rising edge of the square wave on the GPIO and the start of the rise of the photodiode. The lag will be lower higher up on the screen. On my screenshot, the photodiode signal is really noisy. Later it became much less noisy.
(By the way, I usually use the PI via ssh from my laptop, though you could also just have a keyboard hooked up to it.)
Vertical Sync Issues
You will notice some variation between cycles of about 1/60 seconds in size, because by default the lagtest program draws to the screen buffer on the PI at fairly random times, while the PI is sending data to the monitor at its framerate, typically 60Hz. Sometimes the frame comes right after the program drew to the screen buffer and sometimes it comes 1/60th of a second later.
If you want a more consistent measurement, you can uncomment the two
ioctl(handle, FBIO_WAITFORVSYNC, &dummy);
lines in the lagtest.c code and recompile. This will do the drawing right after a vertical sync event, so at the beginning of a cycle. As a result the measurement will be consistent and bigger by one cycle, because there will be a one-cycle delay between drawing to the framebuffer and when the new data is sent.
I am not 100% sure how people define screen latency numbers given that the numbers depend on when in the cycle one draws to the screen. If you define it as the minimum possible value, then you can get that by measuring at the top of the screen, using vertical sync, and subtracting 1/60 seconds to take into account the delay before the data is sent.