![]() |
if statement - Printable Version +- Forums (https://sanworks.io/forum) +-- Forum: Pulse Pal (https://sanworks.io/forum/forumdisplay.php?fid=3) +--- Forum: Software (https://sanworks.io/forum/forumdisplay.php?fid=8) +--- Thread: if statement (/showthread.php?tid=731) |
if statement - Ilja - 02-13-2020 Hi, I need to program an "if statement" into my PulsePal script and I'm not really sure how to do this. Basically, I need the following: A TTL detected on Trigger channel 1, then the programed stimulus should start, however, a TTL detected on Trigger channel 2 and the programed stimulus should stop. It sounds pretty straight forward but I simply do not know how to communicate this to the PulsePal. Any advice would be greatly appreciated. Thanks a bunch, Ilja RE: if statement - Josh - 02-16-2020 Hi Ilja, Pulse Pal's trigger channels can be configured to interpret incoming TTL signals in a few ways, described here. Unfortunately there isn't an option to have the incoming signal stop ongoing stimulation in all cases. The closest thing is 'toggle mode'. If you put channels 1 and 2 into 'toggle mode', either channel will start stimulation if stimulation is off, and end stimulation if it is ongoing. However, this solution has the caveat that after an incoming pulse to ch1 starts stimulation, a subsequent pulse on ch1 can stop it before ch2 has a chance to - and in that case, the next incoming pulse on ch2 would start it again. To make the trigger channels have a universal 'stop' mode, you'd have to modify the firmware. You'd have to add an 'if' statement after line 667, where if triggerMode[y] == 3, KillChannel = 1. Then you'd have to modify the MATLAB or Python-side software to send triggerMode = 3 if you set the channel to 'stop' mode. I hope this helps, -Josh RE: if statement - Ilja - 02-18-2020 Hi Josh, so I added the three lines of code after line 667 in the firmware. I assume it adds a fourth option to the Trigger parameters. I understand in theory what I need to do but I simply do not know how to communicate this via Matlab to the PulsePal. I have the following Matlab code: Code: load PulsePalProgram_Template; % Loads the default parameter matrix So the PulsePal receives a TTL on TriggerChannel 1 and this starts the above pulse sequence. It simply sends out two TTLs, one to our solenoid activating an air puff and the second to my acquisition program to indicate the air puff time point in my recordings. I want the program to continue this pulse sequence up until 200 s is reached or another TTL is received on TriggerChannel 2. At this time I want the pulse sequence to stop. Basically, TTL on TriggerChannel 1 starts the pulse sequence, while TTL on TriggerChannel 2 stops the pulse sequence, indefinitely. By using the function ProgramPulsePalParams, I simply define all the needed variables, these are saved and recalled once a signal is received on TriggerChannel 1. Do I link both channel 1 and 2 to TriggerChannel 1 and 2 and thus add the following lines to each of the above TTL pulses: Code: ProgramPulsePalParam(1, 'LinkTriggerChannel2', 2); % Set output channel 1 to respond to trigger channel 2 Please let me know if I'm on the right track. Thanks, Ilja RE: if statement - Ilja - 02-19-2020 Hi again, I tried the changed Matlab code as shown in the previous post but that did not seem to work. Could it be that the changes that I made to the firmware code have not been added when I call the PulsePal in Matlab, do I need to update something? By the way here are the changes that I made which I hope are correct. Shown are lines 650 through 672 of the firmware. Code: for (int x = 0; x < 4; x++) { RE: if statement - Ilja - 02-27-2020 Hi, finally I was able to get the PulsePal to work the way I wanted it to. It did require one change to the firmware as seen below (Lines 650-677): Code: for (int x = 0; x < 4; x++) { Code: if ((TriggerMode[y] == 3) && (LineTriggerEvent[y] == 1)){ Maybe this will be helpful to others. Ilja |