Timing between NI card and visual stim

Hello Chris,
I need help with ensuring consistent timing between two events; the first would be to pulse a digital output on a NI card and the second would be to produce a visual stimulus on the screen. I tried scheduling them with the time difference i want, but there is a jitter of around +/- 10 ms around the desired delay. Any idea how i can improve this?
Cheers,
Beshoy

Hi Beshoy,

This is tricky. What is the desired interval between the pulse and the stimulus?

Chris

Hi Chris,

I want the visual stimulus to be followed by a pulse after 30ms. Initially, I scheduled the two events so that they are 30ms apart. So far, I found that the time required to execute the NI command is pretty consistent (1-3 ms) while the time for updating the display can be anything between 10-24 ms.

Here is what I did to improve this; I got the time when the last display update occurred and try to ensure that the next display update is scheduled at a multiple of a frame time. This reduced the variability a bit to around +/-5 ms from the desired delay. The rationale was to have the display update command to happen at the beginning of a monitor refresh.

Cheers,
Beshoy

Hi Beshoy,

I want the visual stimulus to be followed by a pulse after 30ms.

Ok, great, that’s much easier than making the stimulus follow the pulse.

The best approach would be to get the predicted output time from update_stimulus_display and schedule the pulse to occur at that time plus 30ms. Assuming you have a stimulus named stim and a variable called stim_onset_time, here’s how this would look in MWEL:

queue_stimulus (stim)
update_stimulus_display (predicted_output_time = stim_onset_time)
wait (stim_onset_time - now() + 30ms)
// Send the pulse now

Of course, you could use a timer and timer-expired transition instead of a wait, or you could create a scheduled action, if that fits better with your experiment design.

Cheers,
Chris

Hello Chris,

I tried this and it works much better now. Whether i use wait or schedule, i get most of my delays within 4 ms of what i want; that works for me.
Thanks,
Cheers,
Beshoy