# Display update

**URL:** <https://mworks.discourse.group/t/display-update/534>\
**Category:** Support\
**Created:** [September 22, 2014, 2:07pm UTC](https://mworks.discourse.group/t/display-update/534 "2014-09-22T14:07:16Z")\
**Posts on this page:** 6\
**Page:** 1

<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:** [September 22, 2014, 2:07pm UTC](https://mworks.discourse.group/t/display-update/534/1 "2014-09-22T14:07:16Z")

</div>

Hello Chris.  
I have realized that nextFrameTime() - now() gives about 0.2ms jitter. I assume this is about the error of next frame time estimate. Is there a function giving the actual time of updated display?  
Thanks!

-Jing

---

<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:** [September 22, 2014, 5:10pm UTC](https://mworks.discourse.group/t/display-update/534/2 "2014-09-22T17:10:56Z")

</div>

Hi Jing,

The `now` function just returns the current time. It isn’t tied to the display refresh cycle, so there’s no reason to expect a constant delta between the values returned by it and `nextFrameTime`.

Are you trying to determine when the _current_ frame was displayed? If so, the best available estimate would be

```
nextFrameTime() - 10e6 / refreshRate()

```

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:** [September 22, 2014, 7:36pm UTC](https://mworks.discourse.group/t/display-update/534/3 "2014-09-22T19:36:47Z")

</div>

I try to copy a digital output while updating the stimulus on display (by put a DO channel to high before the action “update display”). I want to know exact time delay between the DO assigned and next frame shown. I found they are 15.5ms with 0.2ms jitter. I guess my question should be What’s the best way to have output synchronized with monitor refresh? we’d like to register/ trigger some events in physiology which requires ms resolution.

Thanks!

---

<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:** [September 25, 2014, 2:20pm UTC](https://mworks.discourse.group/t/display-update/534/4 "2014-09-25T14:20:47Z")

</div>

Hi Jing,

> What’s the best way to have output synchronized with monitor refresh?

At present, I think your best option is the following:

1. Invoke “update\_stimulus\_display”
2. Store the current value returned by `nextFrameTime`
3. Wait until `now() >= stored_next_frame_time`
4. Set the DO line high

This isn’t ideal, because it’s possible (though not likely) that there will be sufficient delay between steps 1 and 2 that `nextFrameTime` will return the time of the frame _after_ the one you want to synchronize with. To make this more robust, we could modify “update\_stimulus\_display” to store the correct next frame time in a variable.

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:** [March 4, 2015, 2:24pm UTC](https://mworks.discourse.group/t/display-update/534/5 "2015-03-04T14:24:22Z")

</div>

Hi Jing & Evan,

> To make this more robust, we could modify “update\_stimulus\_display” to store the correct next frame time in a variable.

This is done and in the MWorks nightly build. The “update\_stimulus\_display” action now accepts a new (optional) parameter, `predicted_output_time`. If the value of this parameter is set to the name of a variable, then “update\_stimulus\_display” will store in that variable the predicted output time of the frame in which the update will take effect.

Here’s my new recommended method for synchronizing a digital output with a display refresh:

1. Invoke “update\_stimulus\_display” with `predicted_output_time` set to `some_var`
2. Wait until `now() >= some_var`
3. Set the DO line

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:** [July 19, 2022, 10:41pm UTC](https://mworks.discourse.group/t/display-update/534/6 "2022-07-19T22:41:41Z")

</div>


