synchronize stimulus with MEG by parallel port triggering

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
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
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, 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
> 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
>
Dear Zhao,

another approach is described here:
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, 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
> 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
>