# globalClock.getTime() produces inaccurate results in EEG trials but core.monotonicClock.getTime() works

**URL:** https://discourse.psychopy.org/t/globalclock-gettime-produces-inaccurate-results-in-eeg-trials-but-core-monotonicclock-gettime-works/33091
**Category:** Coding
**Tags:** timing, eeg
**Created:** [February 2, 2023, 10:55pm UTC](https://discourse.psychopy.org/t/globalclock-gettime-produces-inaccurate-results-in-eeg-trials-but-core-monotonicclock-gettime-works/33091 "2023-02-02T22:55:34Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![gleisner-robot](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/gleisner-robot/32/35231_2.png) [@gleisner-robot](https://discourse.psychopy.org/u/gleisner-robot)
#### Post date: [February 2, 2023, 10:55pm UTC](https://discourse.psychopy.org/t/globalclock-gettime-produces-inaccurate-results-in-eeg-trials-but-core-monotonicclock-gettime-works/33091/1 "2023-02-02T22:55:34Z")

</div>

Hi all, I apologize for my noob question. I am running my first EEG study with Biosemi using Psychopy. The serial\_out component was a giant mess so I used code, and it seemingly works great (all the tiggers are sent where they are supposed to be sent, nothing is duplicated, etc.). The problem is: I first used the code suggested on the official website using the globalClock function ([here](https://psychopy.org/hardware/serialPortInstr.html)):

EACH FRAME

```auto
if target_words.status == STARTED and not pulse_started:
    win.callOnFlip(port.write, str.encode(chr(trigger)))
    pulse_start_time = globalClock.getTime()
    thisExp.addData('trigger started', pulse_start_time)
    pulse_started = True
    pulse_ended = False

if pulse_started and not pulse_ended:
        if globalClock.getTime() - pulse_start_time >= 0.005:
            win.callOnFlip(port.write, b'\x00')
            pulse_ended = True

```

I added “thisExp.addData(‘trigger started’, pulse\_start\_time)” so that I could test whether the trigger is sent exactly when the target\_words routine starts (it’s not at the beggining of a trial but 250 ms later). That’s how I noticed that globalClock.getTime() records a comletely diferent time compared to when the target\_words routine starts, and the difference could be anything from 60 to 300 ms. When I replaced it with core.monotonicClock.getTime(), it works like charm, showing that the trigger is sent 0.017 ms after the target\_words routine starts, and it’s very consistent.

Can somebody please explain the difference between the clocks to me and why the official website suggests we use globalClock.getTime() instead? I don’t have the photodiode to test the time, and I know it’s not ideal, but it’s something anyway.
