I'm having problems with psychtoolbox and accurate timing. I wrote my code following the tutorial on the website and the PTBTutorial-ECVP2013.pdf in PsychDocumentation. But it somehow still doesn't work right. It takes way longer than it should (1 or 2 s) to flip (more than 20 s). So I guess I'm making a critical mistake somewhere, but I can't find it. Could you help me with my code?
In any case this is how my code looks like.
%Number of seconds to wait (ns)
nsS = 2; %sentences
nsW = 1; %words
nsDot = 7;
nsWait= 3;
%Number of frames to wait (wf) before flipping
wfS = round(nsS/ifi);
wfW = round(nsW/ifi);
wfDot = round(nsDot/ifi);
wfWait = round(nsWait/ifi);
vbl=Screen('Flip', window);
for i = 1:10 %1:exp.ntrials
sentence = ...; %load sentences
word = ...% load words;
for iframe = 1:300
%draw fixation cross
if iframe <= 60
DrawFormattedText(window, '+','center','center', white);
vbl =Screen('Flip', window, vbl + (wfW-0.5)*ifi);
%draw sentence
elseif iframe <= 180
DrawFormattedText(window, sentence,'center','center', white);
vbl = Screen('Flip', window, vbl + (wfS-0.5)*ifi);
%blank screen
elseif iframe <= 240
Screen('FillRect', window, black);
vbl = Screen('Flip', window, vbl + (wfW-0.5)*ifi);
%Draw word
elseif iframe <=300
DrawFormattedText(window, word,'center','center', white);
vbl = Screen('Flip', window,vbl + (wfW-0.5)*ifi);
end
end
%Draw dot
for frames = 1:wfDot
Screen('DrawDots', window, [xCenter yCenter], 10, white, [], 2);
vbl=Screen('Flip', window, vbl+(wfDot-0.5)*ifi);%, vbl+(wfDot-0.5)*ifi);
%WaitSecs(7);
end
...
end