Waveplayer TTL pulses

Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Waveplayer TTL pulses
#1
Hi all,

I would like to use the waveplayer on the analog output module to send TTL pulses (5V) throughout the duration of particular states.
What would be the best way to go about this?

Thanks in advance!

Cheers
Reply
#2
Hi Mike,

You'd solve this by playing a waveform that is longer than your state will ever be, and gating it on and off with the state changes.
Here's some code to get started (disclaimer: haven't tested it! Also see this)

W = BpodWavePlayer(MyCOMPort); % Where MyCOMPort is the correct USB serial port for the WavePlayer
W.SamplingRate = 1000; % Set the sampling rate to 1kHz
MyWave = ones(1,100000)*5; % Vector to play back, with 5V at every sample for 100s total play-time at 1kHz
W.loadWaveform(1, MyWave); % Load the waveform to the device as waveform 1


Then, you'll need the state machine to send some bytes to WavePlayer when you enter the state (to start playback) and when you leave the state (to end playback as per the serial interface):

['P' 1 0] to start playing the pulse, and
'X' to end playback

You'd send these bytes in the OutputActions section of the state description:

{'WavePlayer1', 'X'} % Sends 'X' from the state machine to the WavePlayer module, on entering the state

For the first message, since there are multiple bytes, you'll need to program it into a slot in the state machine's serial message library, and trigger it by referencing the slot:

For instance,

LoadSerialMessages('WavePlayer1', ['P' 1 0], 1)

and in the OutputActions section,

{'WavePlayer1', 1}

FYI, the 'develop' branch of the Bpod_Gen2 repository currently has the ability to program the library implicitly, so 

{'WavePlayer1', ['P' 1 0]}

will be valid syntax. This will be released to the main branch as soon as we can verify that it is stable.

I hope this helps,
-Josh
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)