Photodiode Tuner

This tool tests the response characteristics of a monitor connected to NIMH ML and adjusts the timing of screen flips so that stimuli can be presented immediately during the next frame. Try this tool, if you have a large monitor, like 4K, or the result of the latency test does not look normal.

1. Background

A frame is drawn by rasters scanning the screen (or scanlines; blue arrows in the figure below) from top left to bottom right. Some scanlines are not shown on the screen but used to fill in the vertical blank time (VBLANK; red arrows) between frames. It is a very common technique to replace screen contents during VBLANK, so that graphics may not be split into two frames. (Failure to avoid splits causes "tearing".) To use this technique, a memory buffer for new screen contents should be submitted sufficiently early before VBLANK occurs (green arrow). If the submission time is late and too close to VBLANK, the contents may be delayed and displayed one frame later.

However, it does not necessarily mean that earlier buffer submission is always better. After the buffer submission, NIMH ML has to wait until the first scanline (scanline 8 in the above figure) begins, to record the exact time of the new frame. This waiting takes away time for graphics and data processing. Therefore, we measure the optimal timing for buffer sumission to maximize the performance of NIMH ML.

2. Photodiode (PD) setup

To use the PD tuner, connect the PD input to a DAQ analog input channel and assign the channel to "PhotoDiode" on the I/O menu.

Then choose a screen location for the PD trigger (a white square) in the Video menu as shown below.

Note: 1. The scanlines are always drawn from the upper left corner of the monitor and the eventcode for a new frame is recorded when the first scanline begins. If the location of the PD is not upper left, there will be a time difference between the eventmarker and the PD response. 2. A flipped screen can also introduce such a time difference between the eventmarker and the PD response, because flippinig the screen in the Windows display settings changes the location of the PD trigger but the directon of scanlines stays the same.

Click the activated [Tune] button and the tuner window will pop up.

  • Photodiode response: Voltage changes in the PD input around the time when the PD trigger was presented.
    • Vertical dotted line: Start time of a new frame after buffer submission (i.e., the time of the eventmarker, if ever stamped)
    • Blue line: Trace of the PD signal
    • Horizontal dotted line: Voltage threshold to detect the rise or fall of the PD signal
    • Black bar: Length of one frame measured
  • [Help] button: Open this document.
  • Scanline: The first and last scanline numbers of the subject screen.
  • Default threshold: By default, NIMH ML submits the screen buffer, if less than 10% of the total scanlines remain before VBLANK. This value is a good starting point for the [New thresold].
  • Old threshold: Scanline threshold when this tool was opened
  • New threshold: If this value is increased too much, the buffer submission time gets closer to VBLANK and new contents may not be presented in the immediate next frame. If this value is set too low, new graphics are likely to be presented in the immediate next frame but NIMH ML may not receive enough time to complete other tasks.
  • Voltage range: The voltage range of the PD signal. Determined automatically.
  • Voltage threshold: Move the voltage threshold (horizontal dotted line) up (max: 100) and down (min: 0)
  • One-shot test: Present the PD trigger and record the response once.
  • # of triggers and Multi-shot test: Repeat the one-shot test multiple times

3. Tuning

The results shown here are examples tested with a 3840x2160 monitor at 60 Hz. Each system is likely to have a different scanline range and a different threshold number.

In the figure below, the new threshold was set to 2160, which was closer to the last scanline (=2218), compared to the previous threshold (=2002). This number was too close to VBLANK so the PD trigger was pushed back by another frame, as shown by the estimated latencies (17.0 ms) and voltage traces in the figure below. Note that the peaks occurred outside the black bar. Therefore, the value of 2160 would be a poor choice.

When the threshold was set to 2130, the PD trigger was presented in the frame drawn immediately after buffer submission, but sometimes it was delayed by another frame. This value would still not be a safe threshold.

With a threshold value of 2100, the PD trigger was presented in the immediate next frame every single time. This new threshold can be safely used. Click the [Save] button to keep the new threshold value.

4. If you fail to find a good threshold

Although the reason is not clear, it has been reported that the timing of the PD response cannot be changed in this way in some systems. If none of the tested values gives you the stable PD response (i.e., a unimodal distribution of PD response peaks), try 0 as the new threshold. It may not make the frame presented immediately but may help with the stable presentation at least.

The National Institute of Mental Health (NIMH) is part of the National Institutes of Health (NIH), a component of the U.S. Department of Health and Human Services.