Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pulse gap
#1
I was measuring some signal delay between TTL and PWM sent from the same state matrix (basically a BNC + PWM pulse) with our new fancy oscilloscope (a PicoScope one), but I had some strange signals.
 Basically, if I use the protocol 

for currentTrial = 1:100; 
   
sma = NewStateMatrix();

sma = AddState(sma, 'Name', 'On2', ... 
    'Timer', .001,...
    'StateChangeConditions', {'Tup', 'exit'},...
    'OutputActions', {'BNCState', 1, 'PWM1', 255}); 

things works normally (see attached 001.jpg), but if i set the  'Timer' to .01 the train of signals has a huge gap after it starts (see attached 01.jpg). Note: gap position is not constant, in a few cases there were two of them. All 100 pulses are sent in every case.
 The same happened if I used two sma like

 sma = AddState(sma, 'Name', 'On2', ... 
    'Timer', .01,...
    'StateChangeConditions', {'Tup', 'pause'},...
    'OutputActions', {'BNCState', 1, 'PWM1', 255}); 

 sma = AddState(sma, 'Name', 'pause', ... 
     'Timer', .01,...
     'StateChangeConditions', {'Tup', 'exit'},...
     'OutputActions', {});

The same kind of gap was present also using Time values of .009, .005, .02, .03, .05 but not .002.
I also tried to send a single .001 pulse and then a .01 train but I had always the gap. Oddly, sending a first train of one hundred 0.1 pulse and then another equal ( the code was with a for currentTrial = 1:100 followed by a for currentTrial = 101:201), the gap was present only in the first chunk of signals.
 I updated the Bpod firmware to the last version (the Bpod_MainModule_0_6 from Github) but the situation was the same.
 Currently using Win10.
 Any idea about whats the issue?
 Thanks

Nicola

Nicola


Attached Files Image(s)
       
Reply
#2
Hi Nicola


If my understanding is correct, you assembled a state matrix to send a single pulse on BNC+PWM, and ran it in a loop where MATLAB controls the inter-pulse timing (with the pause() function?). 

When MATLAB sends data to serial port hardware, it actually sends data to the OS (Windows/Ubuntu), which decides when to send to the serial port. Hundreds of milliseconds of jitter and latency are not uncommon. The point of Bpod is that once a state matrix is running (i.e. once a trial starts), the trial's events and state transitions will be measured and executed by the microcontroller's clock, so they will have precise timing. The inter-trial interval is still controlled by MATLAB, so it has some randomness that the OS controls. Take-home message - when the interval between two events is time-critical, you'll have to make them part of the same state matrix.

Below is a code example derived from your setup, where all of the pulse timing takes place on the state machine. Please let me know how it looks!


Code:
% Params
nTrials = 50;
pulseDuration = 0.01;
pulseInterval = 0.1;
currentState = 0;

sma = NewStateMatrix();
for currentTrial = 1:nTrials;  
   currentState = currentState + 1;
   sma = AddState(sma, 'Name', num2str(currentState), ...
       'Timer', pulseDuration,...
       'StateChangeConditions', {'Tup', num2str(currentState+1)},...
       'OutputActions', {'BNCState', 2, 'PWM1', 255});
   currentState = currentState + 1;
   sma = AddState(sma, 'Name', num2str(currentState), ...
       'Timer', pulseInterval,...
       'StateChangeConditions', {'Tup', num2str(currentState+1)},...
       'OutputActions', {});
end
currentState = currentState + 1;
sma = AddState(sma, 'Name', num2str(currentState), ...
   'Timer', pulseDuration,...
   'StateChangeConditions', {'Tup', 'exit'},...
   'OutputActions', {});
SendStateMatrix(sma);
RawEvents = RunStateMatrix;
Reply


Forum Jump: