# Laser plug-in

**URL:** <https://mworks.discourse.group/t/laser-plug-in/870>\
**Category:** Support\
**Created:** [January 23, 2023, 9:18pm UTC](https://mworks.discourse.group/t/laser-plug-in/870 "2023-01-23T21:18:56Z")\
**Posts on this page:** 1\
**Showing post:** 5

<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:** [January 24, 2023, 5:15pm UTC](https://mworks.discourse.group/t/laser-plug-in/870/5 "2023-01-24T17:15:26Z")

</div>

Hi Yasmine,

Regarding display update timing, here’s what I said last June:

> On the MWorks side, your experiment is deciding when to send the digital code signaling on/off. Most likely, you’re sending it immediately after an [update\_stimulus\_display](https://mworks.github.io/documentation/latest/components/update_stimulus_display.html) action. As noted in the docs, completion of this action indicates that the display update has been submitted, but _not_ that it has completed. MWorks can’t know, via software means alone, when the display update has completed — that’s why you have a photodiode on your display. If you want your experiment to wait until when the OS _expects_ the display update to complete, you can use the [predicted\_output\_time](https://mworks.github.io/documentation/latest/components/update_stimulus_display.html#predicted-output-time) parameter and explicitly wait until that time.

Also:

> If you want there to be _any_ consistent correlation between when you send an on/off signal to Blackrock and when a display update appears on screen, then you _must_ use predicted\_output\_time. If you don’t, then your signals will be sent at arbitrary points in the display update cycle.

I recommended replacing all instances of `update_display` with invocations of the macro `update_display_and_wait` (included below), which executes `update_display` then waits until the predicted output time:

```auto
var predicted_display_update_time = 0

%define update_display_and_wait ()
    update_display (predicted_output_time = predicted_display_update_time)
    assert (
        condition = predicted_display_update_time > now()
        message = 'Predicted display update time is in the past'
        )
    wait (duration = predicted_display_update_time - now())
%end

```

In your current experiment, if the goal is for the photodiode stimulus to appear on screen as close as possible to the time when the laser turns on, then you should turn the laser on immediately after executing `update_display_and_wait`, e.g.

```auto
update_display_and_wait ()
vpixx_dout_laser_gate = true

```

Cheers,  
Chris

---

_[View the full topic](https://mworks.discourse.group/t/laser-plug-in/870)._
