Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Analog output module protocols

I am trying to figure out how to incorporate the Bpod Analog Output module into my current protocol with a Bpod state machine (r2). Essentially, I want to use the output module channels to deliver TTL pulses that sync multiple devices in my rig, which means I will need to call the output module within each state loop of my protocol. Unfortunately, I cannot seem to find any support on how to control this device using my primary bpod. The WavePlayer instuctions on the wiki are the closest I've come, but this seems to suggest that I operate the output module independent of the Bpod. Is it even possible to run both the output module and the bpod from the same protocol state for loop? 

Launching the bpod software, I don't see the output module channels on the control panel, so even running the output module alone at the moment remains elusive.

Thank you for the assistance

Kate Feller
Hi Kate,

On the wiki there's a page documenting the serial interfaces of the state machine and its modules, including WavePlayer.
The serial interface's 'State Machine' section explains which bytes to send from the state machine to the WavePlayer module to trigger, stop playback, etc.

Here's how you'd do what you're describing:

In your protocol (MATLAB), before your main loop:

%% Create waveplayer object
if (isfield(BpodSystem.ModuleUSB, 'WavePlayer1'))
   W = BpodSystem.ModuleUSB.WavePlayer1;
   error('Error: To run this protocol, you must first pair the WavePlayer1 module with its USB port on the Bpod console.')

%% Set up waveplayer
W.SamplingRate = 1000;
W.loadWaveform(1, 5); % Loads a single 5V sample as waveform#1

In your protocol (MATLAB), in the state where you want to trigger the waveform:

'OutputActions', {'WavePlayer1', ['P' 3 0]} % Play waveform#1 on channels 1 and 2.

'P' is the serial interface byte code for playback. 
3 in binary is '11', indicating to play on channels 1 and 2. 
0 is waveform#1 (using zero-indexing since it's an Arduino board)
Since you're sampling at 1kHz, a single sample will play 5V on channels 1+2 for 1ms.

FYI, the analog output module isn't really necessary to send out TTL pulses - BNC output channels 1+2 on the state machine are a simpler option - and they're galvanically isolated, reducing noise and the potential for ground loops on your rig. To set BNC output Ch1+2 high for the duration of a state, use:

'OutputActions', {'BNC1', 1, 'BNC2', 1} % Set BNC output channels 1 and 2 to high (5V).

If you need to run a more complicated sync waveform on those channels in parallel with the flow of states, consider linking them to a looping global timer as in this example.

I hope this helps,

Hi Josh,

All this is very helpful. I will play around and see 

 I am actually using Channels 1 and 2 on the main state machine to send TTL pulses at one frequency to sync four different devices. I would like to use the output module to send TTL pulses at a different frequency. I realize that I could probably just load up channels 1 and 2 with a whole mess of T-splitters to support the 6 different apparatuses that need to receive TTL pulses, but I was hoping to avoid that by using the output module instead. Making a sound is not necessary, only making a TTL pulse. Is the output module able to do this? If not, I am afraid I will have to return it.

Thank you so much for you help!

Hi Kate,

In my previous post, I explained how to make TTL pulses with the analog output module, and trigger them from the state machine.

Please let me know if you run into any problems implementing it.



Forum Jump: