How to send triggers using the parPulse function?

Hi,

I tried my best to understand how to use the parPulse function sending triggers as the official website explained https://display-corner.epfl.ch/index.php?title=ParPulse&oldid=845, but failed. The main issue result from the different Syntax between the io64 function and the parPulse function.

This is a sample code of io64.

%trialstart marker using the io64 function
if measureEEG == 1
    data_out = startmark;
    io64(ioObj,address,data_out);
    WaitSecs(0.01);
    io64(ioObj,address,0); %reset to zero
end

Should the afterVal of parPulse be reset to the zero value after the trigger sending, as the io64 function?

The main syntax of parPulse is

parPulse([portAddr,] pulseVal, afterVal, valMask, pulseTi);

The sample code of parPulse is

  parPulse(hex2dec('d030')); % Initialize port
  parPulse(0,0,255,0);       % Set all data lines to 0
  parPulse(0,1,255,0);       % Set all data lines to 0, except for line 0 which is set to 1
  for i=1:50
      parPulse(2,1,3,1e-3);  % 1ms pulse on data line 0 (negative pulse)
                               % and line 1 (positive pulse)
      pause(100e-3);            % Pause for roughly 100ms
  end

In my understanding, the afterVal is the EEG mark in experiments (If not, please correct me). But I cannot get the meaning of pulseVal and valMask.

For the pulseVal
I cannot understand:

  1. why there needs a output value during pulse, what is the function of this value?
  2. In an EEG experiment, what value should be set to the pulseVal, is it varied as different stimuli presented?

For the valMask
The official web said that the valMask indicats which output lines of the parallel port will actually be affected by pulseVal and afterVal.
My question is:

  1. Which output lines of the parallel port should be set in normal EEG experiments? Is the valMask a constant value during the whole experiment?

  2. What is the meaning when the valMask was set as “255” as the line 2 of sample code “parPulse(0,0,255,0)” illustrated? Does it mean that there are 255 lines in the parallel port? Or, does “255” mean all data lines? (I guess this is the case.) If so, again, whilch line should be programmed by pulseVal and afterVal in a normal EEG experiment.

Other specific questions for the sample code of parPulse:

parPulse(0,1,255,0);       % Set all data lines to 0, except for line 0 which is set to 1

The first one is which position of the four value in the aboved code indicating the line 0 is set to 1, which value indicates all the other lines is set to 0.
In my understanding, the code means all lines (the third value: 255) is set to 1 (the second value which means afterVal: 1). But this is not matched with the comment.

  for i=1:50
      parPulse(2,1,3,1e-3);  % 1ms pulse on data line 0 (negative pulse)
                               % and line 1 (positive pulse)
      pause(100e-3);            % Pause for roughly 100ms
  end

The last question: which value means the line 0 and which means the line 1 in the above code “parPulse(2,1,3,1e-3)” ? How could I figure out whether the pulse is a negative pulse or a positive pulse as the comment said.

That’s all.
This is the last part of my first EEG experiment, and very appreciate to anyone who can explain these questions clearly.

Thanks again,
Huizhong

Well, I cannot tell which kind of trigger signal your EEG recording system and/or analysis software expects. But for mimicking your io64() code snipped, you would use [EDIT: swapped the first 2 parameters - ouch]:

parPulse(data_out, 0, 255, 10e-3);

Or using the isTrigger version, which makes the call non-blocking - at the expense of a less accurate pulse time:

parPulse(portAddr, data_out, 0, 255, 10e-3, 1);

When using the isTrigger version, the portAddress parameter has to be provided just for making the parameter interpretation unambiguous to other use cases of parPulse(). It does not mean that the I/O port is initialized from scratch in each call. It is ugly, but, originally, parPulse() was implemented for getting accurate pulse times in the sub-millisecond range; isTrigger was implemented later.

Note that your io64() code uses a 10ms pulse width, whereas your parPulse() code in the loop uses 1ms, which - depending on the EEG system -, might be too short to be captured reliably.

Regarding the logic behind pulseVal, afterVal, and valMask, maybe these formulas make it clearer:

outVal_DuringPulse = (outVal_BeforeTheCall & ~valMask)  |  (pulseVal & valMask);
outVal_AfterPulse =  (outVal_BeforeTheCall & ~valMask)  |  (afterVal & valMask);
outVal_BeforeTheCall = outVal_AfterPulse;
1 Like

Words cannot express my appreciation for your help for many times.

Now, the synax is clear for me. The pulseVal is actually the trigger mark, not the afterVal.

The first two lines make sense why the pulseVal and afterVal only worked to valMask.
For the third formula, does it mean that the outVal have been resetted to afterVal, and that’s the reason why afterVal should be set to zero.
If it’s ture, it is so beatiful and clever to complish the two steps in io64 into one step in parPulse.

Hope my understanding is correct this time.

Thanks again.

outVal_BeforeTheCall = outVal_AfterPulse;

was just supposed to mean that parPulse() will leave the output state at outVal_AfterPulse, which will become the outVal_BeforeTheCall for the next call to parPulse().

Yes, I know :wink:

I try to express the same meaning

as yours.