When a 1-millisecond-duration TTL pulse is sent to the BNC connector of our
Rowland USB fMRI hand pucks, a back tick (`) keyboard character is generated.
And when that happens, we would like our Matlab program to react as quickly as
possible.
I am trying to figure out which of the following is the better way to have my
Matlab code pause, wait for that TTL pulse, and be the fastest off the bat. I
have read what is out there on the differences between KbCheck and GetChar, but
in this specific application, might GetChar be the better choice? That is, is
it possible that the 1-millisecond-duration TTL pulse might be missed between
successive KbCheck calls in the while-loop below? Or does the back tick
generated by the TTL pulse have an inherent duration that is longer than 1
millisecond?
Thanks for any feedback. Here are the two code bits I am comparing, and let's
assume that these MEX-files have been called and loaded into Matlab
memory previously:
--- KbCheck version ---
noTTLpulse = 1;
while (noTTLpulse)
[keyIsDown,secs,keyCode] = KbCheck;
if (keyIsDown)
if (keyCode(51))
noTTLpulse = 0;
end
end
end
--- GetChar version ---
noTTLpulse = 1;
while (noTTLpulse)
keyPressed = GetChar;
if (keyPressed == '`')
noTTLpulse = 0;
end
end
Rowland USB fMRI hand pucks, a back tick (`) keyboard character is generated.
And when that happens, we would like our Matlab program to react as quickly as
possible.
I am trying to figure out which of the following is the better way to have my
Matlab code pause, wait for that TTL pulse, and be the fastest off the bat. I
have read what is out there on the differences between KbCheck and GetChar, but
in this specific application, might GetChar be the better choice? That is, is
it possible that the 1-millisecond-duration TTL pulse might be missed between
successive KbCheck calls in the while-loop below? Or does the back tick
generated by the TTL pulse have an inherent duration that is longer than 1
millisecond?
Thanks for any feedback. Here are the two code bits I am comparing, and let's
assume that these MEX-files have been called and loaded into Matlab
memory previously:
--- KbCheck version ---
noTTLpulse = 1;
while (noTTLpulse)
[keyIsDown,secs,keyCode] = KbCheck;
if (keyIsDown)
if (keyCode(51))
noTTLpulse = 0;
end
end
end
--- GetChar version ---
noTTLpulse = 1;
while (noTTLpulse)
keyPressed = GetChar;
if (keyPressed == '`')
noTTLpulse = 0;
end
end