TTL pulses via BNC port to sync with neurophotometrics fiber photometry recordings

117 views
Skip to first unread message

Cayla Murphy

unread,
Jan 12, 2023, 2:18:32 PM1/12/23
to FEDforum
Hi everyone,

I am trying to send a TTL pulse via the BNC port when a pellet is taken by a mouse during fiber photometry recordings in order to sync the recordings to the pellet retrieval. I am using the v1.16.3 free feeding timeout fix code update posted here in the forum, however the TTL pulses do not send with this code.

I am new to the FED3 system and C++ code but I dug around in the FED3.cpp file and found this:

void FED3::BNC(int DELAY_MS, int loops) {
  for (int i = 0; i < loops; i++)  {
    digitalWrite(BNC_OUT, HIGH);
    digitalWrite(GREEN_LED, HIGH);
    delay(DELAY_MS);
    digitalWrite(BNC_OUT, LOW);
    digitalWrite(GREEN_LED, LOW);
    delay(DELAY_MS);

so I inserted it in the free feeding timeout fix code here (in bold):

void loop() {
controlSleep(); //For free-feeding task, only sleep when pellet is in the well
fed3.run(); //Call fed.run at least once per loop
fed3.Feed(); //Drop pellet
fed3.BNC(0, 1); //FED3::BNC(int DELAY_MS, int loops)
fed3.Timeout(2); //2s timeout
}

setting int DELAY_MS to 0 and int loops to 1, which I think sets the delay between pulses to 0 ms and sends only 1 pulse. However, there is still a slight delay between when I take a pellet from the hopper and when the pulse shows up on the fiber photometry visualizer as a square wave, about 500 ms to 1 second. This delay does not occur with FEDs that I have with an older version of the code (v1.1.44, which I cannot find on the github to compare). The square wave in the visualizer occurs instantaneously for these FEDs.

I want to get rid of this delay because I don't want the syncing to the fiber photometry recordings to be off. I am not sure if I am using the right code, or what the Hz or ms should be for the pulse (i.e., what the default settings are for one square wave pulse). Does anyone know how to do this?

Thanks in advance!

Best,
Cayla Murphy

Lex Kravitz

unread,
Jan 12, 2023, 6:02:16 PM1/12/23
to FEDforum
Hi Cayla!
You can find the FED3 functions here.  The Feed() function was updated since v1.1.44 to include an argument for sending a pulse or not - this pulse will occur immediately when the pellet is removed. The usage for this function is to put an integer argument for how long you want the pulse to be.  ie:

fed3.Feed(100); will send a 100ms pulse when the pellet is taken.
fed3.Feed(500); will send a 500ms pulse when the pellet is taken.
fed3.Feed(); still works, and will not send a pulse.

Here's a video of it in action, let me know if this works for you!
-Lex
Reply all
Reply to author
Forward
0 new messages