Hi, Josh @Josh
I have another question regarding global timer in Bpod. In my current experiment design, I'm using a global timer to control the maximum duration of a block, but I'm having issues getting the GlobalTimer1_End event to properly trigger state transitions as expected. In my other code implementations, when I use a global timer, the GlobalTimer1_End event correctly triggers the next state transition when the timer expires. However, in this specific code, it doesn't seem to work as expected.
For testing purposes, I've added an "Error" state in multiple places. Logically, the GlobalTimer1_End should trigger much earlier (when the global timer reaches S.GUI.MaxBlockTime), rather than waiting for the state's own timer to expire and falling into the Error state.
Here's my code:
% Define lick port used in states based on S.GUI.LickPort
PortIn=strcat('Port',num2str(S.GUI.LickPort), 'In');
PortOut=strcat('Port',num2str(S.GUI.LickPort), 'Out');
%%
sma = SetGlobalCounter(sma, 1, PortIn, S.GUI.LickTimes); % Arguments: (sma, CounterNumber, TargetEvent, Threshold)
sma = SetGlobalCounter(sma, 2, 'BNC1High', S.GUI.liquid_1st_num_each_block); % Arguments: (sma, CounterNumber, TargetEvent, Threshold)
sma = SetGlobalTimer(sma, 1, S.GUI.MaxBlockTime); %This legacy syntax is supported. Arguments: (sma, GlobalTimerNumber, Duration(s))
sma = AddState(sma,'Name','SessionStart', ...
'Timer', S.GUI.TimeBeforeStart,...
'StateChangeConditions', {'Tup','GoSound'},...
'OutputActions', {'HiFi1','*'});
sma = AddState(sma,'Name','GoSound', ...
'Timer', S.GUI.SoundGoDuration,...
'StateChangeConditions', {'Tup','WaitForLick_TimeTrig'},...
'OutputActions', {'HiFi1', ['P' 0]});
sma = AddState(sma,'Name','WaitForLick_TimeTrig', ...
'Timer', 0,...
'StateChangeConditions', {'Tup','WaitForLick_ResetCounter'},...
'OutputActions', {'GlobalTimerTrig',1});
sma = AddState(sma,'Name','WaitForLick_ResetCounter', ...
'Timer', 0,...
'StateChangeConditions', {'Tup','WaitForLick'},...
'OutputActions', {'GlobalCounterReset',1});
sma = AddState(sma, 'Name', 'WaitForLick', ...
'Timer', S.GUI.MaxBlockTime,...
'StateChangeConditions', {'GlobalCounter1_End','Hit','GlobalCounter2_End','WaitNextBlock','GlobalTimer1_End','Finish','Tup', 'Error'},...
'OutputActions', {});
sma = AddState(sma, 'Name', 'Hit', ...
'Timer', 0,...
'StateChangeConditions', {'Tup', 'GiveReward'},...
'OutputActions', {'BNCState', 1});
sma = AddState(sma,'Name','GiveReward', ...
'Timer', S.ValveTime,...
'StateChangeConditions', {'Tup','ITI'},...
'OutputActions', {'ValveState', S.Valve_InputDecimal,'BNCState', 3});
sma = AddState(sma,'Name','ITI', ...
'Timer', S.GUI.ITI,...
'StateChangeConditions', {'Tup','WaitForLick_ResetCounter'},...
'OutputActions', {});
sma = AddState(sma, 'Name', 'WaitNextBlock', ...
'Timer', S.GUI.MaxBlockTime,...
'StateChangeConditions', {'GlobalTimer1_End','Finish','Tup', 'Error'},...
'OutputActions', {});
sma = AddState(sma, 'Name', 'Finish', ...
'Timer', 0,...
'StateChangeConditions', {'Tup', '>exit'},...
'OutputActions', {});
sma = AddState(sma, 'Name', 'Error', ...
'Timer', 0,...
'StateChangeConditions', {'Tup', '>exit'},...
'OutputActions', {});
In my previous working implementations, the global timer worked perfectly, so I'm confused about why it's not functioning correctly in this specific code. (In addition, global counter 2 also doesn't work)
Any insights or suggestions would be greatly appreciated! If you could help me identify what might be going wrong, I would be very grateful.
Thank you in advance for your help!
Best regards,
Oly