# Sync stimuli display with output pulse (electrical stimulation)

**URL:** <https://mworks.discourse.group/t/sync-stimuli-display-with-output-pulse-electrical-stimulation/851>\
**Category:** Support\
**Created:** [November 24, 2022, 10:48am UTC](https://mworks.discourse.group/t/sync-stimuli-display-with-output-pulse-electrical-stimulation/851 "2022-11-24T10:48:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcadena](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@jcadena](https://mworks.discourse.group/u/jcadena)\
**Post date:** [November 24, 2022, 10:48am UTC](https://mworks.discourse.group/t/sync-stimuli-display-with-output-pulse-electrical-stimulation/851/1 "2022-11-24T10:48:57Z")

</div>

Hi Chris

I am setting up an experiment where two response objects appear in the screen while at the same time delivering electrical stimulation. The stimulation and the stimuli should appear at the same time or as close in time as possible

If I implement this:

live\_queue\_stimulus (stim1)  
live\_queue\_stimulus (stim2)  
update\_stimulus\_display()  
pulse(variable = EP\_Stimulation\_flag; duration = 3 \* 1000)

The pulse will likely be delivered before the screen will get refreshed. I did a quick test and the pulse is arriving 50 ms before the refresh the screen.

Then my question is: do you have any sugestions?

Have a nice day

Jaime

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [November 28, 2022, 2:31pm UTC](https://mworks.discourse.group/t/sync-stimuli-display-with-output-pulse-electrical-stimulation/851/2 "2022-11-28T14:31:19Z")

</div>

Hi Jaime,

Try waiting until the [predicted output time](https://mworks.github.io/documentation/latest/components/update_stimulus_display.html#predicted-output-time) of the display update:

```auto
var pulse_start_time = 0
...
live_queue_stimulus (stim1)
live_queue_stimulus (stim2)
update_stimulus_display (predicted_output_time = pulse_start_time)
wait (pulse_start_time - now())
pulse (variable = EP_Stimulation_flag; duration = 3 * 1000)

```

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![jcadena](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@jcadena](https://mworks.discourse.group/u/jcadena)\
**Post date:** [November 28, 2022, 3:47pm UTC](https://mworks.discourse.group/t/sync-stimuli-display-with-output-pulse-electrical-stimulation/851/3 "2022-11-28T15:47:04Z")

</div>

Thanks a lot

Jaime

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [December 12, 2022, 3:48pm UTC](https://mworks.discourse.group/t/sync-stimuli-display-with-output-pulse-electrical-stimulation/851/4 "2022-12-12T15:48:54Z")

</div>


