My own B-Pod System using FPGA and MATLAB

Working with rodents in Jeffrey Erlich’s lab last summer, I found that rodent decision-making is so amazing. So, In the electronic design class in this semester, I tried to make a B-Pod system using FPGA and MATLAB by my own. However, I successful bulit up a trainning system, and tested on the real rodents. So I can use that to carry out my own rodent experiment in the future.

I open-accessed all my code on Github, here is the LINK.

About the BPOD

The B-Pod system is developed by Joshua Sanders in his initial open research instruments (The BPOD r0.5) while completing his PhD in Kepecs Lab at Cold Spring Harbor Laboratory.

Why BPOD

Traditional rodent behavior experiments such as water maze have many limitations.Althrough learning is involved in that task, however, we can not isolate the different level of cognitive process in that task, such as sensory processing, working memory retention or the formation of dicision making. The learning of such a traditional task is also simple. Also, we cannot study how the brain dealing with uncertainty in decision-making.

To study different level of cognitive process in the rodent (Guo et al., 2014), the neural mechanism of learning the complex task (Liu et al., 2016), and to study how the brain dealing with stochastic (Tervo et al., 2014). We need a more powerful tools to generate sensory cue, and detect the animals’ behavior. That’s why we need the B-Pod system.

More detailed examples

If we want to study the working memory(WM) and the WM related decision making process in the rodent, the major method is to design a delay resonse task for the rodent. Such as auditory based(Erlich et al., 2011),whisker based(Guo et al., 2014), or visual based delay response task(Goard et al., 2016).

In such a traditional delay response task, each trial contains about 3 phases. In the first phase, we give the subject a sensory cue (Such as a sound beep in a specific frequency, or a visual stimulus of a given directions or colors). Then there will be a delay period(Phase 2), the subject need to retent the information they got, and then(in phase 3), based on such information, make a specific behavior output(Such as poke to a specific port, lick/no lick or lick left/right) to gain water reward.

Traditional working memory task for the rodent

Fig 1. Traditional working memory task for the rodent

To study how the brain dealing with stochastic, we can give then uncertaint reward, and observe how the animals adjust their behaivour policy to maxinum the profit. And study the source to generate stochastic(ACC) and to dealing with uncertainty(OFC). (Tervo et al., 2014)

how the brain dealing with stochastic

Fig 2. How the brain dealing with stochastic

Based on that, we need more powerful tools to train the animals to perform a decision-making involved complex task. That’s why I designed and made that device.

Bacis idea of the BPOD system

The basic idea of the bpod is to interact with the rodent using light or sound cue, and give them reward when they perform well. So the core problem is to detect rodents’ activity.

The animal poke in and block the IR

Fig 3. We have several LEDs around the ports and the sound in the mouse box to ‘tell’ the animal ‘what to do’

To do so, we are using an IR emitter paired with an IR collector for each port. So everytime when the animal ‘poke’ into the port. The light from IR emitter will be block, so we can detect voltage change from the IR collector.

The animal poke in and block the IR

Fig 4. We are using IR to detect animals’ behavior

Using FPGA to control and monitering the devices.

In my project, I’m using a FPGA(Field-Programmable Gate Array) to control the LEDs and water valve in the three mouse ports. Meanwhile, The FPGA is also used for monitering the IR collector of the three ports.
B-Pod-FPGA-PC-connection

Fig 5. The connection diagram of the firmware

The FPGA is connected to the MAC computer via a serial-USB convert line. And the MATLAB is able to talk with the FPGA via this serial port.

Once the IR system detect the mouse’s activity, the IR collector will sent signals to the FPGA. Then the FPGA will send an 8-bits information contains that information.

The FPGA keeps contraling the LEDs and water valve. When the MATLAB want to change a state(For example, turn on/off the light, open the water). It will sent a 8-bits information via serial port to re-write the state vector in FPGA. FPGA then change the target voltage in it’s ports.

Because the voltage of the IR system is 5V and the voltage of the FPGA is 3.3v, I passed the IR output to a voltage convertor and a 74HC14 to reverse the voltage. The it will be sent to the FPGA, 3.3v means a ‘block’ is there, and 0v means this port is clear.

FPGA-connection

Fig 6. The connection diagram of the FPGA

Connected all these firmware things. The FPGA, the LEDs, the IR ports, the 74HC14 chips and the computer, It looks like this. But it works pretty well.

The-connected-sys

Fig 7. The testing firmware

Using MATLAB to control the FPGA using FSM

In the computer, the MATLAB will generate a FSM(Finate State Meachine) based on the design of the experiment protocol to control the FPGA. The animals’ behavioul will trigger the stage switching.

We define a class to describe the experiment protocol. The simplist version is called the ‘Operant’, in ‘Protocols/Operant’ path. It contains several sub-functions.

  • init Section: Initialze the protocol, creating Sounds etc.
  • useSetting Section: do some basic settings to the session. and load some old settings from previous experiment.
  • PreparNextTrial Section: set the paramenters of the next trial based on prob. or history performance.
  • RunTrial Section: Generate the FSM and run the trial.
  • TrialComplete Section: do dome basic computation and analyze to this trial’s data.
  • saveTrial section: save this trials data to the table.

The dispatch.m in the modules path will call different parts of that class again and again. It also have many try-catch sentences, so that it will isolate bugs within each section and not affect running of the experiment.

Also, I designed a subject management system there. We we input the subject’s id when starting the experiment, the program will record the stage and the information. So everthing will go automatically.

Making the Rig Box

The box was made by laser cutted Plexiglass. I drwan the sketch using AutoCAD.
The sketch of the Rig Box

Fig 8. The sketch of the Rig Box

And then we manufact the mouse poke port using 3D priting technique.
the 3D model of the mouse port

Fig 9. the 3D model of the mouse port

The hole is reserved for the IR LEDs and for the water tubes.

Here is the fianl results after assembling.
Fianl Rig box

Fig 10. Assembled Rig box - front view

Final Rig Box - Back view

Fig 11. Assembled Rig box - back view

Before each run, we should manully test the rig system by calling rig_test function.

In the future, I will make up a PCB version of the poke-wall system. To get more stable performance.

The Basic Trainning Protocol

My system contains a basic Protocol named ‘Operant’. It’s a very general protocol that can be used to train animals to associate lights or sounds with reward.

To train the animals, we need to follow up a stage-to-stage procedure. The basic idea is shown below. In ‘Operant’, we have three stages.

Stage_1

Fig 12. State diagram of the stage 1

First stage: ‘reward_train’. We will give them unconditional reward, just let them learn to drink. When they learnt how to drink, we will jump to the stage 2.

Stage_2

Fig 13. State diagram of the stage 2

Secound stage: ‘single_poke’. In this stage, we will turn the light of a port randomly, and wait for the animal to poke into that port. If they do well, they will get water reward, otherwise, they will hear about a short violation sound and no reward. When they got >75% performance in the past 30 trials, they will go to the stage 3.

# Running on Real Rodent
Runninng test on real mouse
Fig 14. Runninng test on real mouse

After complete the whole things, I luckily found some mouse to conduct some real test. To make sure that my devices can detect real mouse’s behaviour and delivery reward water.

the mouse can drink!

Fig 15. The mouse is drinking on the BotC port after a successful trial

When the mouse do poke during ITI peroid, they will recieve violation sound.

poke during ITI

Fig 16. The mouse went to TopL port during ITI

The testing results reveal that our devices can robustly capture rodent’s poking behavior, give the cue and delivery reward water.

The Next Step

Currerently, I’ve completed the trainning system. I’ll try to train several mouse and rats shortly after.

References

  • Tervo, D. G. R., Proskurin, M., Manakov, M., Kabra, M., Vollmer, A., Branson, K., & Karpova, A. Y. (2014). Behavioral variability through stochastic choice and its gating by anterior cingulate cortex. Cell, 159(1), 21-32. doi:10.1016/j.cell.2014.08.037
  • Erlich, J. C., Bialek, M., & Brody, C. D. (2011). A cortical substrate for memory-guided orienting in the rat. Neuron, 72(2), 330-343. doi:10.1016/j.neuron.2011.07.010
  • Liu, D., Gu, X., Zhu, J., Zhang, X., Han, Z., Yan, W., . . . Li, C. T. (2014). Medial prefrontal activity during delay period contributes to learning of a working memory task. Science, 346(6208), 458-463. doi:10.1126/science.1256573
  • Guo, Zengcai V., Li, N., Huber, D., Ophir, E., Gutnisky, D., Ting, Jonathan T., . . . Svoboda, K. (2014). Flow of Cortical Activity Underlying a Tactile Decision in Mice. Neuron, 81(1), 179-194. doi:10.1016/j.neuron.2013.10.020
  • Guo, Z. V., Inagaki, H. K., Daie, K., Druckmann, S., Gerfen, C. R., & Svoboda, K. (2017). Maintenance of persistent activity in a frontal thalamocortical loop. Nature, 545(7653), 181-186. doi:10.1038/nature22324
  • Hanks, T. D., Kopec, C. D., Brunton, B. W., Duan, C. A., Erlich, J. C., & Brody, C. D. (2015). Distinct relationships of parietal and prefrontal cortices to evidence accumulation. Nature, 520(7546), 220-223. doi:10.1038/nature14066
  • Goard, M. J., Pho, G. N., Woodson, J., & Sur, M. (2016). Distinct roles of visual, parietal, and frontal motor cortices in memory-guided sensorimotor decisions. eLife, 5. doi:10.7554/eLife.13764