Using the quadrature encoder to track locomotion

Scanbox allows you to acquire the position of a rotating platform at each frame of the microscope.  To do so, you need a quadrature encoder to be mounted on the axis of your platform.  We use the US Digital HS-360-IE-S, but any quadrature encoder will do as well.

The encoder needs to be wired to an Arduino board that reads keeps track of the encoder position and gets polled by both Scanbox and a stimulus computer.  The ability of the stimulus computer to poll the position of the platform allows us to close the loop and have stimuli depend on the platform motion.  Having an external Arduino board keep track of the platform position means that the stimulus computer does not have to interfere with the image acquisition at all.

The necessary code for the Arduino can be found in yeti/quad/quad_encoder.ino.  We use the Mega 2560, but most of the other boards will do as well.  You need to download this Encoder library and install it in the Arduino/Libraries directory before compiling.

The default connections are as follows:

US Digital, 5V (red)  goes to Arduino, 5V
US Digital, GND (black) to Arduino, GND
US Digital, A (white) to Arduino, pin 2
US Digital, B (brown) to Arduino, pin 3

Once the program is uploaded into the Arduino the board will show up in your Device Manager as a COM port.  Then you can edit the quad_com variable in the scanbox_config.m file to include this information.

Now, when you start Scanbox the encoder is ready to be used.

While focusing and/or grabbing, and if the quadrature encoder checkbox is enabled, you will see the absolute position of the platform displayed within the encoder panel.  The program automatically resets the value to zero at the beginning of imaging. If you are grabbing data, Scanbox will store the resulting measurements in a separate file that appends “_quadrature.mat” to the name of the file.  The variable in stored in the file is called quad_data, which is a vector of the same length as the number of microscope frames collected. A typical run may look like the figure below, with periods of rest interspersed with periods of locomotion.

encoderFinally, to translate absolute count to position along track one needs to know the number of counts per revolution of your encoder (in our case 4*360=1440) and the radius of the platform (in our case 10cm).  The resulting conversion factor would then be 2*pi*radius / #counts per revolution.  You can store this value in the quad_cal variable of the scanbox_config.m file for easy reference.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s