if statement

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
if statement
#1
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
Reply
#2
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
Reply
#3
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
ProgramPulsePal(ParameterMatrix); % Sends the default parameter matrix to Pulse Pal

%TTL on Output channel 1 to send TTL to Solenoid driver
ProgramPulsePalParam(1, 'Phase1Voltage', 5); % Set output channel 1 to produce 1V pulses
ProgramPulsePalParam(1, 'Phase1Duration', 0.001); % Set output channel 1 to produce 12ms pulses
ProgramPulsePalParam(1, 'InterPulseInterval', 9.999); % Set pulse interval to produce 0.1 Hz pulses
ProgramPulsePalParam(1, 'PulseTrainDuration', 200); % Set pulse train to last 200 seconds
ProgramPulsePalParam(1, 'PulseTrainDelay', 5); % onset latency prior to pulse train is 10 seconds
ProgramPulsePalParam(1, 'LinkTriggerChannel1', 1); % Set output channel 1 to respond to trigger channel 1
ProgramPulsePalParam(1, 'TriggerMode', 1); % Set trigger channel 1 to toggle mode

%TTL on Output channel 2 to Smartbox
ProgramPulsePalParam(2, 'Phase1Voltage', 5); % Set output channel 1 to produce 1V pulses
ProgramPulsePalParam(2, 'Phase1Duration', 0.001); % Set output channel 1 to produce 12ms pulses
ProgramPulsePalParam(2, 'InterPulseInterval', 9.999); % Set pulse interval to produce 0.1 Hz pulses
ProgramPulsePalParam(2, 'PulseTrainDuration', 200); % Set pulse train to last 200 seconds
ProgramPulsePalParam(2, 'PulseTrainDelay', 5); % onset latency prior to pulse train is 10 seconds
ProgramPulsePalParam(2, 'LinkTriggerChannel1', 1); % Set output channel 2 to respond to trigger channel 1
ProgramPulsePalParam(1, 'TriggerMode', 1); % Set trigger channel 2 to toggle mode


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
ProgramPulsePalParam(2, 'TriggerMode', 3); % Set trigger channel 2 to stop mode
I guess I'm confused about how to communicate this to the PulsePal.

Please let me know if I'm on the right track.

Thanks,
Ilja
Reply
#4
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++) {
     byte KillChannel = 0;
      // If trigger channels are in toggle mode and a trigger arrived, or in gated mode and line is low, shut down any governed channels that are playing a pulse train
      if (((StimulusStatus[x] == 1) || (PreStimulusStatus[x] == 1))) {
         for (int y = 0; y < 2; y++) {
           if (TriggerAddress[y][x]) {
               if ((TriggerMode[y] == 1) && (LineTriggerEvent[y] == 1)) {
                    KillChannel = 1;
               }
               if ((TriggerMode[y] == 2) && (LineTriggerEvent[y] == 2)) {
                   if ((TriggerMode[1-y] == 2) && (TriggerAddress[1-y][x])) {
                     if (InputValues[1-y] == DefaultInputLevel) {
                       KillChannel = 1;
                     }
                   } else {
                     KillChannel = 1;
                   }
               }
        if (TriggerMode[y] == 3) {
                KillChannel = 1;
            }
           }
         }  
         if (KillChannel) {
            killChannel(x);
         }
Ilja
Reply
#5
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++) {
     byte KillChannel = 0;
      // If trigger channels are in toggle mode and a trigger arrived, or in gated mode and line is low, shut down any governed channels that are playing a pulse train
      if (((StimulusStatus[x] == 1) || (PreStimulusStatus[x] == 1))) {
         for (int y = 0; y < 2; y++) {
           if (TriggerAddress[y][x]) {
               if ((TriggerMode[y] == 1) && (LineTriggerEvent[y] == 1)) {
                    KillChannel = 1;
               }
               if ((TriggerMode[y] == 2) && (LineTriggerEvent[y] == 2)) {
                   if ((TriggerMode[1-y] == 2) && (TriggerAddress[1-y][x])) {
                     if (InputValues[1-y] == DefaultInputLevel) {
                       KillChannel = 1;
                     }
                   } else {
                     KillChannel = 1;
                   }
               }
               if ((TriggerMode[y] == 3) && (LineTriggerEvent[y] == 1)){
                  KillChannel = 1;
               }
           }
         }  
         if (KillChannel) {
            killChannel(x);
         }
       
     } else {
Lines 668-669 were added,


Code:
if ((TriggerMode[y] == 3) && (LineTriggerEvent[y] == 1)){
  KillChannel = 1;
Now by linking Chan1 to TriggerChannel1 and this trigger channel receiving a TTL it will start my pulse and by linking Chan1 also to TriggerChannel2 and this trigger channel receiving also a TTL is will stop my pulse and so on until I manually stop this.

Maybe this will be helpful to others.

Ilja
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)