Timing start of FED3 program with BNC input

243 views
Skip to first unread message

Eric Mitten

unread,
Apr 18, 2022, 1:05:46 PM4/18/22
to FEDforum
Hi all!

I have written some code that blocks the program from starting until a BNC input is received so that I can time the beginning of port availability with a fiber photometry recording. I also wanted to do this so that it would work as a "timeout" until the session starts. Before receiving BNC input, the FED3 is unresponsive. However, a poke will be counted in a given port if it is poked during this "timeout" period. Once a BNC input is received, it acts as if the poke occurred immediately. (active port poked during timeout --> BNC input --> conditioned stimulus immediately occurs, pellet is delivered, and count is updated). I haven't been able to write code that stops this from happening, so wanted to see if I could gain some insight here! Considering this seems specific to the port being activated (if I only hit the inactive port, it will only run the inactive port code) and is sequential (if I hit the inactive and then the active, it will run the inactive code --> active code and count both pokes), I think it might have to do with a value on the corresponding pins that is being carried over between this "timeout" period to the actual session. Any help would be greatly appreciated! Attached below will be the edited pieces that are required to run this. I updated the sketch, the .h, and .cpp files so all will be needed in the right places to run the program.

Thanks,
Eric Mitten

** If any one is interested in using this code, there are a couple of extra tweaks I've added. (1) This code turns on a "house light" for the duration of the session and turns them off at session end. (2) It also blocks the program from counting pokes following session end. (3) I have included a "Time of Event" column in the datasheet that allows me to sync up FED3 events with times during the fiber photometry recording to look at Ca2+ dynamics. It calculates the time by comparing the timing of events in relation to the time BNC input was received, so this is integral to this column. (4) There is a startup screen that displays "waiting for BNC input" and an end menu screen that displays "session has ended!." I'm currently writing code to allow for an internal reset 5 minutes after session end so that I don't have to manually reset after each run. 
FED3.cpp
FED3.h
FR1_BNC.ino

Eric Mitten

unread,
Apr 20, 2022, 11:28:02 AM4/20/22
to FEDforum
I actually just found out how to do this! The left/right variable that is returned as true once a poke occurs was carrying over once the initial "timeout" period ended, so just resetting that variable before the start of the session blocks this from happening.

Lex Kravitz

unread,
Apr 21, 2022, 11:38:34 AM4/21/22
to FEDforum
Hi Eric!  Super cool to see you digging into the code and changing what it's logging and displaying on the screen!  If your changes can be compartmentalized and integrated into the FED3 library we can discuss how to include them so your changes can propagate into future library updates.  Please reach out to me by email if you're interested.

Also glad you figured out the issue you were having.  Yes, the FED3 code uses two boolean variables called "Left" and "Right" which are set to true when the pokes are activated, and must be set back to false in the code.  The "logLeftPoke" and "logRightPoke" functions set these back to false so normally you don't have to worry about it, but if you don't call these logging functions (or if you delay them as you did) the Left and Right variables can be left as true
Reply all
Reply to author
Forward
0 new messages