Hi Josh, below is the code we wrote to trigger a signal simultaneously from output channel 1 and 2. The signal from output channel 1 is a TTL signal, which occurs at 1Hz for 1 sec long, with pulse duration at 1 sec. The signal from out put channel 2 is a laser trigger signal, which occurs at 20hz for 15 sec long, with pulse duration at 20ms. The problem with this code is that it works well for output channel 2 but it does not for output channel 1. Some signal is sent to output channel 1, the blue light comes on but does not go off. Also, there is no TTL signal from output channel 1. I can't find the bug. Can you help us with this issue?
% Define parameters
pulseDuration1 = 1; % 1 sec pulse duration for data acquisition (output channel 1)
pulseFrequency1 = 1; % 1 Hz frequency for data acquisition pulse (output channel 1)
totalDuration1 = 1; % Total pulse train duration for output channel 1 (seconds)
pulseDuration2 = 0.02; % 20 ms pulse duration for laser (output channel 2)
pulseFrequency2 = 20; % 20 Hz frequency for laser pulses (output channel 2)
totalDuration2 = 15; % Total pulse train duration for laser (output channel 2, seconds)
nIntervals = 10; % Number of pulse trains (triggers)
% Total time for the experiment in seconds (20 minutes)
totalTime = 1200; % 20 minutes in seconds
minInterval = 30; % Minimum interval between pulse trains (seconds)
% Calculate the maximum remaining time available for random intervals
remainingTime = totalTime - (minInterval * nIntervals); % Ensure total time constraint
% Generate random intervals that sum to the remaining time
randomIntervals = rand(nIntervals, 1); % Generate random fractions
randomIntervals = randomIntervals / sum(randomIntervals); % Normalize to sum to 1
randomIntervals = randomIntervals * remainingTime; % Scale by remaining time
% Add the minimum interval to each random interval
myIntervals = randomIntervals + minInterval;
% Calculate the pulse times for output channel 1 (data acquisition)
pulseTimes1 = 0:(1/pulseFrequency1):(totalDuration1 - 1/pulseFrequency1);
% Voltages for channel 1 pulse train (data acquisition)
voltages1 = 5 * ones(1, length(pulseTimes1)); % 5V for each pulse
% Upload the custom pulse train for output channel 1 (data acquisition)
SendCustomPulseTrain(1, pulseTimes1, voltages1); % Uploads train to slot 1
% Set output channel 1 to use custom train 1 and configure trigger parameters
ProgramPulsePalParam(1, 14, 1); % Set output channel 1 to use custom train 1
ProgramPulsePalParam(1, 4, pulseDuration1); % Set output channel 1 pulse duration to 1 sec
ProgramPulsePalParam(1, 13, 1); % Set output channel 1 to respond to triggers on trigger channel 2
% Calculate the pulse times for output channel 2 (laser)
pulseTimes2 = 0:(1/pulseFrequency2):(totalDuration2 - 1/pulseFrequency2);
% Voltages for channel 2 pulse train (laser)
voltages2 = 5 * ones(1, length(pulseTimes2)); % 5V for each pulse
% Upload the custom pulse train for output channel 2 (laser)
SendCustomPulseTrain(2, pulseTimes2, voltages2); % Uploads train to slot 2
% Set output channel 2 to use custom train 2 and configure trigger parameters
ProgramPulsePalParam(2, 14, 2); % Set output channel 2 to use custom train 2
ProgramPulsePalParam(2, 4, pulseDuration2); % Set output channel 2 pulse duration to 20 ms
ProgramPulsePalParam(2, 13, 1); % Set output channel 2 to respond to triggers on trigger channel 2
% Ensure the total intervals sum to the total time
totalIntervalSum = sum(myIntervals);
if totalIntervalSum > totalTime
warning('Intervals exceed the total time');
else
% Trigger pulse trains at adjusted intervals
for idx = 1:nIntervals
pause(myIntervals(idx)); % Pause for the random interval before triggering
% Trigger both channels simultaneously
TriggerPulsePal(1); % Trigger output channel 1 (data acquisition)
TriggerPulsePal(2); % Trigger output channel 2 (laser)
end
end