# synchronize stimulus with MEG by parallel port triggering

**URL:** <https://psychtoolbox.discourse.group/t/synchronize-stimulus-with-meg-by-parallel-port-triggering/1709>\
**Category:** Uncategorized\
**Created:** [March 26, 2008, 3:00pm UTC](https://psychtoolbox.discourse.group/t/synchronize-stimulus-with-meg-by-parallel-port-triggering/1709 "2008-03-26T15:00:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [March 26, 2008, 3:00pm UTC](https://psychtoolbox.discourse.group/t/synchronize-stimulus-with-meg-by-parallel-port-triggering/1709/1 "2008-03-26T15:00:14Z")

</div>

Dear All,  
  
I am trying to send parallel port triggers to MEG immediately after   
visual stimulus presentation. However, we found about +-5 ms   
variability between stimulus onset and trigger onset when measured   
with a light diode. The relevant codes we used to implement our   
purpose are:  
  
  
....% for drawing stimuli in BackBuffer; then  
  
loop={  
 'Screen(''Flip'',workingWindow);' % immediately followed by next line:  
 'F\_HFSP2\_Trigger(trig,Trigger\_Value,Trig\_Signal\_duration,Trigger\_Open\_switch);'  
}  
  
priorityLevel=2;  
RUSH(loop,priorityLevel);  
% actually I also tried a different version of above codes without   
using loop/RUSH things, but it did not have too much difference.  
  
In order to use parallel port, we used following codes to initialize   
parallel port:  
 trig = digitalio('parallel' , 'LPT1');  
 data = addline(trig, 0:7,'out');  
  
The function of sending trigger is:  
  
function [] = F\_HFSP2\_Trigger(trigObject, trigger\_value,duration,   
trigger\_Open\_switch)  
  
if Trigger\_Open\_switch  
  
 putvalue(trigObject, trigger\_value);  
 WaitSecs(duration/1000);  
 putvalue(trigObject, 0);  
end;  
  
Parameters for using trigger sending function are:  
The Trig\_Signal\_duration is 5 ms;  
For behavioural experiment, Trigger\_Open\_switch =0; (i.e. do not need   
trigger.)  
For MEG experiment, Trigger\_Open\_switch =1;  
  
  
The experimental setup we used is Matlab 7.04 (on windows XP) plus PTB   
3 newest version. The CRT display refresh rate is 60 HZ.  
  
Does anyone know a better way to do the triggering and would like to   
point out what is wrong with our codes that might be the possible   
reason for the +-5 ms variability between stimulus onset and trigger   
onset? Any help and suggestion will be greatly appreciated.  
  
  
Thank you very much!  
  
-Zhao  
  
  
  
  
  
  
----------------------------------------------------------------  
This message was sent using IMP, the Internet Messaging Program.  
  
  
--   
Mae'r e-bost yma'n amodol ar delerau ac amodau ymwadiad e-bost Prifysgol  
Bangor. Gellir darllen testun llawn yr ymwadiad yma:  
[http://www.bangor.ac.uk/emaildisclaimer](http://www.bangor.ac.uk/emaildisclaimer)  
This email is subject to the terms and conditions of the Bangor University  
email disclaimer. The full text of the disclaimer can be read here:  
[http://www.bangor.ac.uk/emaildisclaimer](http://www.bangor.ac.uk/emaildisclaimer)

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [March 26, 2008, 10:08pm UTC](https://psychtoolbox.discourse.group/t/synchronize-stimulus-with-meg-by-parallel-port-triggering/1709/2 "2008-03-26T22:08:56Z")

</div>

A few comments:  
  
A simple Priority(MaxPriority(....)); at the beginning of  
your script, and Priority(0) at the end or in error-handling  
are usually sufficient on todays windows boxes, so  
while Rush() still works, the Priority() way of doing things  
makes the code simpler/more readable/easier to debug.  
  
Priority(2) on Windows is usually not recommended,  
because it can interfere with important OS system  
processes, so it can have the opposite effect of what  
you intended.  
  
What graphics card do you use? Latest drivers installed  
from your graphics cards vendor?  
  
If you run "VBLSyncTest" it will give you a few timing  
plots. The last one "Time delta between stimlus onset  
and return of flip in msecs" allows you to see how much  
time passes between visual stimulus onset and the  
end of the Screen('Flip') command.  
  
A GetSecs before, and after your call to your trigger  
function allows to find out how much time is spent  
there.  
  
==\> First step is to find out if its a graphics-related/  
operating system issue, or some problem with the  
trigger submission.  
  
-mario  
  

> --- In [psychtoolbox@yahoogroups.com](mailto:psychtoolbox@yahoogroups.com), pss62e@... wrote:  
> \>  
> \> Dear All,  
> \>   
> \> I am trying to send parallel port triggers to MEG immediately after   
> \> visual stimulus presentation. However, we found about +-5 ms   
> \> variability between stimulus onset and trigger onset when measured   
> \> with a light diode. The relevant codes we used to implement our   
> \> purpose are:  
> \>   
> \>   
> \> ....% for drawing stimuli in BackBuffer; then  
> \>   
> \> loop={  
> \> 'Screen(''Flip'',workingWindow);' % immediately followed by next line:  
> \> 'F\_HFSP2\_Trigger(trig,Trigger\_Value,Trig\_Signal\_duration,Trigger\_Open\_switch);'  
> \> }  
> \>   
> \> priorityLevel=2;  
> \> RUSH(loop,priorityLevel);  
> \> % actually I also tried a different version of above codes without   
> \> using loop/RUSH things, but it did not have too much difference.  
> \>   
> \> In order to use parallel port, we used following codes to initialize   
> \> parallel port:  
> \> trig = digitalio('parallel' , 'LPT1');  
> \> data = addline(trig, 0:7,'out');  
> \>   
> \> The function of sending trigger is:  
> \>   
> \> function [] = F\_HFSP2\_Trigger(trigObject, trigger\_value,duration,   
> \> trigger\_Open\_switch)  
> \>   
> \> if Trigger\_Open\_switch  
> \>   
> \> putvalue(trigObject, trigger\_value);  
> \> WaitSecs(duration/1000);  
> \> putvalue(trigObject, 0);  
> \> end;  
> \>   
> \> Parameters for using trigger sending function are:  
> \> The Trig\_Signal\_duration is 5 ms;  
> \> For behavioural experiment, Trigger\_Open\_switch =0; (i.e. do not need   
> \> trigger.)  
> \> For MEG experiment, Trigger\_Open\_switch =1;  
> \>   
> \>   
> \> The experimental setup we used is Matlab 7.04 (on windows XP) plus PTB   
> \> 3 newest version. The CRT display refresh rate is 60 HZ.  
> \>   
> \> Does anyone know a better way to do the triggering and would like to   
> \> point out what is wrong with our codes that might be the possible   
> \> reason for the +-5 ms variability between stimulus onset and trigger   
> \> onset? Any help and suggestion will be greatly appreciated.  
> \>   
> \>   
> \> Thank you very much!  
> \>   
> \> -Zhao  
> \>   
> \>   
> \>   
> \>   
> \>   
> \>   
> \> ----------------------------------------------------------------  
> \> This message was sent using IMP, the Internet Messaging Program.  
> \>   
> \>   
> \> --   
> \> Mae'r e-bost yma'n amodol ar delerau ac amodau ymwadiad e-bost Prifysgol  
> \> Bangor. Gellir darllen testun llawn yr ymwadiad yma:  
> \> [http://www.bangor.ac.uk/emaildisclaimer](http://www.bangor.ac.uk/emaildisclaimer)  
> \> This email is subject to the terms and conditions of the Bangor University  
> \> email disclaimer. The full text of the disclaimer can be read here:  
> \> [http://www.bangor.ac.uk/emaildisclaimer](http://www.bangor.ac.uk/emaildisclaimer)  
> \>

---

<div class="post-metadata">

**Author:** ![jan.kremlacek](https://avatars.discourse-cdn.com/v4/letter/j/d2c977/32.png) [@jan.kremlacek](https://psychtoolbox.discourse.group/u/jan.kremlacek)\
**Post date:** [March 28, 2008, 7:03am UTC](https://psychtoolbox.discourse.group/t/synchronize-stimulus-with-meg-by-parallel-port-triggering/1709/3 "2008-03-28T07:03:09Z")

</div>

Dear Zhao,  
  
another approach is described here:  
[http://tech.groups.yahoo.com/group/psychtoolbox/message/4825](http://tech.groups.yahoo.com/group/psychtoolbox/message/4825)  
  
Please, let us know what will be the precision of this trigger.  
  
With regards  
Jan  
  
  

> --- In [psychtoolbox@yahoogroups.com](mailto:psychtoolbox@yahoogroups.com), pss62e@... wrote:  
> \>  
> \> Dear All,  
> \>   
> \> I am trying to send parallel port triggers to MEG immediately after   
> \> visual stimulus presentation. However, we found about +-5 ms   
> \> variability between stimulus onset and trigger onset when measured   
> \> with a light diode. The relevant codes we used to implement our   
> \> purpose are:  
> \>   
> \>   
> \> ....% for drawing stimuli in BackBuffer; then  
> \>   
> \> loop={  
> \> 'Screen(''Flip'',workingWindow);' % immediately followed by next line:  
> \>   
> 'F\_HFSP2\_Trigger(trig,Trigger\_Value,Trig\_Signal\_duration,Trigger\_Open\_switch);'  
> \> }  
> \>   
> \> priorityLevel=2;  
> \> RUSH(loop,priorityLevel);  
> \> % actually I also tried a different version of above codes without   
> \> using loop/RUSH things, but it did not have too much difference.  
> \>   
> \> In order to use parallel port, we used following codes to initialize   
> \> parallel port:  
> \> trig = digitalio('parallel' , 'LPT1');  
> \> data = addline(trig, 0:7,'out');  
> \>   
> \> The function of sending trigger is:  
> \>   
> \> function [] = F\_HFSP2\_Trigger(trigObject, trigger\_value,duration,   
> \> trigger\_Open\_switch)  
> \>   
> \> if Trigger\_Open\_switch  
> \>   
> \> putvalue(trigObject, trigger\_value);  
> \> WaitSecs(duration/1000);  
> \> putvalue(trigObject, 0);  
> \> end;  
> \>   
> \> Parameters for using trigger sending function are:  
> \> The Trig\_Signal\_duration is 5 ms;  
> \> For behavioural experiment, Trigger\_Open\_switch =0; (i.e. do not need   
> \> trigger.)  
> \> For MEG experiment, Trigger\_Open\_switch =1;  
> \>   
> \>   
> \> The experimental setup we used is Matlab 7.04 (on windows XP) plus PTB   
> \> 3 newest version. The CRT display refresh rate is 60 HZ.  
> \>   
> \> Does anyone know a better way to do the triggering and would like to   
> \> point out what is wrong with our codes that might be the possible   
> \> reason for the +-5 ms variability between stimulus onset and trigger   
> \> onset? Any help and suggestion will be greatly appreciated.  
> \>   
> \>   
> \> Thank you very much!  
> \>   
> \> -Zhao  
> \>   
> \>   
> \>   
> \>   
> \>   
> \>   
> \> ----------------------------------------------------------------  
> \> This message was sent using IMP, the Internet Messaging Program.  
> \>   
> \>   
> \> --   
> \> Mae'r e-bost yma'n amodol ar delerau ac amodau ymwadiad e-bost Prifysgol  
> \> Bangor. Gellir darllen testun llawn yr ymwadiad yma:  
> \> [http://www.bangor.ac.uk/emaildisclaimer](http://www.bangor.ac.uk/emaildisclaimer)  
> \> This email is subject to the terms and conditions of the Bangor  
> University  
> \> email disclaimer. The full text of the disclaimer can be read here:  
> \> [http://www.bangor.ac.uk/emaildisclaimer](http://www.bangor.ac.uk/emaildisclaimer)  
> \>
