Sending TTL pulses during pokes & changes in pellet availability state

125 views
Skip to first unread message

Mason Hardy

unread,
Mar 11, 2025, 3:32:34 PMMar 11
to FEDforum
Hi Lex,

I am working to modify the Fixed Ratio 1 to send TTL pulses during specific epochs:

1) Left poke is registered (100 ms pulse)
2) Right poke is registered (50 ms pulse)
3) Pellet first becomes available in the tray (150 ms pulse)
4) Pellet is removed from the tray (200 ms pulse)

My code is in the attached file. So far, this successfully sends a pulse upon right poke or left poke. However, once the pellet is dispensed into the tray, it does not send a pulse when the pellet arrives, and it will not allow pulses to be sent from left or right pokes until the pellet is removed. When the pellet is removed, it sends the correct 200 ms pulse, and then allows for left and right pokes to be registered until a new pellet arrives in the tray.

Best,
Mason
FR1_TTL_edit.docx

Lex

unread,
Mar 29, 2025, 9:04:46 AMMar 29
to Mason Hardy, FEDforum
Hi Mason,
Sorry for the delay in responding to you on this, you'll need to modify the FED3 library source code to do this.  Once your library code is modified you will have a "forked" version of the library, so keep that in mind if you reflash your FEDs from another computer, or share your code with other lab members.

The issue you're experiencing is caused because the fed3.Feed() function does not complete until the pellet is removed from the well. The Feed function will log pokes while pellets are present, but by default does not send pulses with those pokes.  So you're going to need to modify the fed3.Feed() function to add your pulses to pokes that occur while pellets are present.

Find the FED3.cpp file in the FED3 Arduino library on your computer - it's most likely in \Documents\Arduino\libraries\FED3\src\FED3.cpp, and it's the file Type that's C++
image.png

Open that in any text editor (VS code is great, but the Arduino IDE can open it if you don't have that).  Find the Feed() function in line 141 (for library version 1.16.3)
image.png

On line 168 of this function you'll find the code for logging pokes while a pellet is present in the well.  You'll see two blocks of code that log Left and Right pokes.  That is where you'll insert your BNC function calls.  So put BNC(100,1); on line 171 to send a 100ms pulse with each Left Poke:
image.png
And BNC(50,1); on line 183 to do this for Right Pokes:
image.png

We have to put these BNC calls in again in this function as the Feed() function has different code to handle the first minute after the pellet drop (where FED3 is awake to monitor retreival times) vs. after that (when FED3 stops monitoring retrieval times and sleeps).  The latter condition starts at line 195.  So add the BNC (100,1); call again on line 200:
image.png
And BNC (50,1); on line 212:
image.png

Finally, FED3 also logs pokes during the dispensing action itself, which can take a second or two to drop a pellet.  The motor dispensing is controlled by a function "RotateDisk" on line 332.  So you can make these same edits on lines 338 and 350:
image.png

After you've made these six changes, save the FED3.cpp file and reflash your FED3.  You should now get pulses during dispensing or while a pellet is present!  My modified FED3.cpp with these edits is attached for you as well. 

Two minor caveats to this edit, neither should be deal-breakers - these BNC calls are "blocking" meaning they hold up the code and don't allow other functions to process until they are finished.  This means:
1) If you poke during a dispense it will stop the motor for 50 or 100ms until the BNC call completes.  In practice I don't think this will matter much but you should be able to notice it.
2) FED3 measures "Poke_Time", which is the duration the mouse has its nose in the poke.  After these edits, if a mouse pokes for <100ms on the Left poke the poke duration will not be accurately recorded, as the BNC function will take 100ms to complete so the minimum value it will record for this will be 100.  If you're not worried about the Poke_Time metric I wouldn't worry about this.

Please write back if this works for you!
-Lex




--
You received this message because you are subscribed to the Google Groups "FEDforum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fedforum+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/fedforum/df322bde-1a6c-4e49-847a-5c973ee89886n%40googlegroups.com.
FED3.cpp

Mason Hardy

unread,
Apr 7, 2025, 6:59:16 PMApr 7
to FEDforum
Hi Lex,

I finally got around to testing this, and it's working! The modifications allow me to have the FED3 send pulses to our RWD photometry system at the appropriate times. Thank you so much for your help, I'm looking forward to implementing this in my experiments.

Best,
Mason

Reply all
Reply to author
Forward
0 new messages