Hi there.
I am trying to figure out how to adjust my PulsePal code in order to deliver four pulse trains of the same length but of different frequencies, each at different time points. Is this possible to do on one channel to dynamically update the code such that the frequency of the pulse train delivered is contingent upon the time point? I read in the Sanders (2014) publication that "Since the same microcontroller controls pulse timing and USB communication, Pulse Pal cannot be updated while a pulse train is being delivered." But the article goes on to describe that "updates can be achieved rapidly between experimental trials." Is it possible to achieve this with tic and toc in MATLAB during the same run? For instance, would the below code work for what I am proposing? What modifications should I make? Or is this not logistically feasible with one channel?
%%
PulsePal
%%
load ParameterMatrix_Example; % Loads the default parameter matrix
ProgramPulsePal(ParameterMatrix); % Sends the default parameter matrix to Pulse Pal
% Start time tracking
startTime = tic; % Start timer to track elapsed time
Voltages = [5 5 5 5 5 1];
% Target times in seconds (15 min, 25 min, etc.)
PulseTimes = [15, 25, 35, 45, 59]*60;
while true
elapsedTime = toc(startTime); % Check elapsed time in seconds
% Train 1: 0.5 Hz at 15 minutes for 90 seconds
if elapsedTime >= 0
ProgramPulsePalParam(1, 'Phase1Voltage', 5);
ProgramPulsePalParam(1, 'Phase1Duration', 0.1); % On duration: 0.1 ms
ProgramPulsePalParam(1, 'InterPulseInterval', 1.9); % Off duration: 1.9 ms (0.5 Hz)
ProgramPulsePalParam(1, 'BurstDuration', 90); % Burst duration: 90 seconds
ConfirmBit = TriggerPulsePal(1);
% Train 2: 1 Hz at 25 minutes for 90 seconds
elseif elapsedTime >= 20
ProgramPulsePalParam(1, 'Phase1Voltage', 5);
ProgramPulsePalParam(1, 'Phase1Duration', 0.1); % On duration: 0.1 ms
ProgramPulsePalParam(1, 'InterPulseInterval', 0.9); % Off duration: 0.9 ms (1 Hz)
ProgramPulsePalParam(1, 'BurstDuration', 90);
ConfirmBit = TriggerPulsePal(1);
%% send custom train 1 to channel 1
ProgramPulsePalParam(1, 'CustomTrainID', 1);
ProgramPulsePalParam(1, 15, 1);
% Train 3: 2 Hz at 35 minutes for 90 seconds
elseif elapsedTime >= 30
ProgramPulsePalParam(1, 'Phase1Voltage', 5);
ProgramPulsePalParam(1, 'Phase1Duration', 0.25); % On duration: 0.25 ms
ProgramPulsePalParam(1, 'InterPulseInterval', 0.25);% Off duration: 0.25 ms (2 Hz)
ProgramPulsePalParam(1, 'BurstDuration', 90);
ConfirmBit = TriggerPulsePal(1);
%% send custom train 1 to channel 1
ProgramPulsePalParam(1, 'CustomTrainID', 1);
ProgramPulsePalParam(1, 15, 1);
% Train 4: 3 Hz at 45 minutes for 90 seconds
elseif elapsedTime >= 40
ProgramPulsePalParam(1, 'Phase1Voltage', 5);
ProgramPulsePalParam(1, 'Phase1Duration', 0.15); % On duration: 0.15 ms
ProgramPulsePalParam(1, 'InterPulseInterval', 0.15);% Off duration: 0.15 ms (3 Hz)
ProgramPulsePalParam(1, 'BurstDuration', 90);
ConfirmBit = TriggerPulsePal(1);
%% send custom train 1 to channel 1
ProgramPulsePalParam(1, 'CustomTrainID', 1);
ProgramPulsePalParam(1, 15, 1);
end
%%
TriggerPulsePal(1)
%%
% AbortPulsePal
% %%