# 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:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yasmine\_El-Shamayleh](https://avatars.discourse-cdn.com/v4/letter/y/258eb7/32.png) [@Yasmine\_El-Shamayleh](https://mworks.discourse.group/u/Yasmine_El-Shamayleh)\
**Post date:** [January 23, 2023, 9:18pm UTC](https://mworks.discourse.group/t/laser-plug-in/870/1 "2023-01-23T21:18:56Z")

</div>

Hi Chris -

Briefly - we’re having three key issues:

(1) It seems that the plug-in is taking about ~80ms to activate the laser

(2) It seems that changing the “gain” (or amplitude) term in the plug-in works for square wave modulation but not sine wave modulation.

(3) When we use a photodiode to detect a square stimulus drawn to the screen BEFORE we activate the plug-in, we notice that this photodiode detection event occurs ~20ms AFTER the laser is turned on.

Im attaching two things:

- The MWEL protocol we use to drive the laser (the relevant lines are 230-337)  
\* We are sending 3 codes to mark the beginning and end of the laser stimulation  
\* One code is related to drawing the photodiode square  
\* A random code (called “distractor color” or “distractor id”) flanks the start/stop of the laser plugin  
\* Another code is related to activating the laser plug-in
- A figure showing our reconstruction of these event times relative to the light sensor coming out of our laser box.

Thanks,  
Yasmine

[protocol\_Laser.mwel](https://mworks.discourse.group/uploads/short-url/qgtKuugHi1EQrSwxJUBjWKqAMOS.mwel) (18.2 KB)

[[//cdck-file-uploads-canada1.s3.dualstack.ca-central-1.amazonaws.com/flex031/uploads/mworks/original/1X/7349ac241512df017a1f4ad54aef15b9892e8547.jpeg](https://canada1.discourse-cdn.com/flex031/uploads/mworks/original/1X/7349ac241512df017a1f4ad54aef15b9892e8547.jpeg)]

---

<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, 2:32pm UTC](https://mworks.discourse.group/t/laser-plug-in/870/2 "2023-01-24T14:32:19Z")

</div>



---

<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, 2:32pm UTC](https://mworks.discourse.group/t/laser-plug-in/870/3 "2023-01-24T14:32:19Z")

</div>



---

<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, 4:24pm UTC](https://mworks.discourse.group/t/laser-plug-in/870/4 "2023-01-24T16:24:25Z")

</div>

Hi Yasmine,

I’m missing some details in your experiment. For one, I see there’s a macro named `photodiode_pixel_on`, but I don’t have a definition for it. Can you share the other MWEL files used with the code you sent? Also, I don’t see any code that looks like it’s sending a “distractor id”. Where exactly does that happen?

> (1) It seems that the plug-in is taking about ~80ms to activate the laser

In the plot, is this 80ms the gap between “DistR (EC)” and “LaserOn (EC)”? If so, it’s hard to say what’s happening without knowing how and when “DistR (EC)” is sent to the Blackrock.

> (2) It seems that changing the “gain” (or amplitude) term in the plug-in works for square wave modulation but not sine wave modulation.

I don’t see any attempt to change the amplitude in the code you sent. Can you share the experiment code that produced this issue (or otherwise explain how you observed it)?

> (3) When we use a photodiode to detect a square stimulus drawn to the screen BEFORE we activate the plug-in, we notice that this photodiode detection event occurs ~20ms AFTER the laser is turned on.

Again, I can’t see the details of how you’re presenting the photodiode stimulus.

That said, we already discussed (in June 2022; the email thread subject was “Disparity in stimulus on/off times?”) a very similar issue, and I made specific recommendations for how to address it. Maybe your `photodiode_pixel_on` macro makes use of these, but if not, that’s probably the issue.

Cheers,  
Chris

---

<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

---

<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 26, 2023, 6:30pm UTC](https://mworks.discourse.group/t/laser-plug-in/870/6 "2023-01-26T18:30:26Z")

</div>



---

<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:** [March 14, 2023, 2:00pm UTC](https://mworks.discourse.group/t/laser-plug-in/870/7 "2023-03-14T14:00:53Z")

</div>


