Timing between NI card and visual stim

beshoy.agayby's Avatar

beshoy.agayby

15 Sep, 2018 03:37 PM

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

  1. Support Staff 1 Posted by Christopher Sta... on 17 Sep, 2018 01:43 PM

    Christopher Stawarz's Avatar

    Hi Beshoy,

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

    Chris

  2. 2 Posted by beshoy.agayby on 17 Sep, 2018 01:54 PM

    beshoy.agayby's Avatar

    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

  3. Support Staff 3 Posted by Christopher Sta... on 17 Sep, 2018 02:14 PM

    Christopher Stawarz's Avatar

    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

  4. 4 Posted by beshoy.agayby on 19 Sep, 2018 08:28 PM

    beshoy.agayby's Avatar

    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

  5. Christopher Stawarz closed this discussion on 20 Sep, 2018 01:53 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac