Lab 9Q: Sensing Rotation with Optical Encoder, for use in studying Bimanual Knob Rotation
A-path Lab

Background:  You have completed Lab 9 by sensing knob rotation with potentiometers. Now you will try the same experiment with rotary optical encoders. The optical encoders here have no limit to amount of rotation they can spin in one direction; and the particular Bourns model used has much less rotational friction than a potentiometer (which need to scrap a "brush" along a resistive path to change the contact point of its middle "pot" pin...).

You will want to do Lab 9Q before Lab VT because in Lab VT there is a rotary encoder system detecting how a tooth gear rotates while the bike is pedaled.

A rotary optical encoder has two offset black/white or transparent/opaque circular patterns; as the patterns are rotated around a central axis a light either reflects off white or shines through an opening for two photodetectors to signal one of 4 combinations of HIGH or LOW for any moment in time. See figures below

Time is the horizontal axis for the figure above; for CW it moves to the right, for CCW time moves to the left. Notice above that when rotating CW a rising edge on ch A occurs when B is HIGH; when the rotation in CCW A rises when B is LOW. Taking advantage of that difference could allow you to mark 256 transitions per full rotation, and know the direction of rotation.

Our rotary encoder--the Bourns L00256L model--has 256 black/white changes in 360deg.

Our particular model is ENS1J B28 L00256L .

The color code for the wires on the Lab 9Q frame is
Red: +5v
Black: GND
Brown or Blue: Channel A
Orange or Yellow: Channel B

Actually, the encoding scheme noted above doesn't work properly if the wheel is jittered back and forth. It can be improved/fixed by a "quadrature" algorithm that responds at the 4 edge changes in "period."

Shown below is a snip of code from modified Arduino sample code (HMJ 2011) for quadrature encoding:

void doEncoderA( ) {
A = (digitalRead(2) == HIGH) ? 1 : -1; //switch: if digitalRead high, A = 1. if digitalRead LOW, A = -1.
pastA = A;
encoderPos = encoderPos + (A * -pastB); //handles all 4 recognized cases and all unrecognized in one line.
//A rising, B rising, encoderPos incremented.
//A rising, B falling, encoderPos decremented.

pastB = 0;

void doEncoderB( ) {
B = (digitalRead(3) == HIGH) ? 1 : -1; //see note above
pastB = B;
encoderPos = encoderPos + (B * +pastA);
pastA = 0;

(1) You may want to attach the red and black power/gnd wires coming out of your Lab 9Q frame to appropriate pins on the LabVIEW green connector board (Example: +5 comes from pin 14; what should be "ground"? Connect two analog and digital ground terminals together and make sure to run that ground to your scope...or other device, such as DMM). Run scope probes to (say) yellow and blue leads and spin the appropriate knob around; observe the Ch A, Ch B, offset responses.

(2) Attach yellow, blue, orange, brown to LabVIEW inputs, from which you can create a VI that scans the 4 inputs simultaneously for 10 seconds. Multipoint WaveformS!

(3) Either with a Matlab script (a la Lab 8) or with suitable LabVIEW function icons, have a post-scan analysis of the 10 seconds worth of waveforms that results in positive counts for one rotation direction, and negative counts for the other direction.

(4) Show that a slow rotation of 360 deg results in a count increase of 1024 (10 bit resolution).

(5) Your algorithm will result in 10 seconds worth of time-domain data that you should run into a FFT function (Lab 6) and display a spectrum with a 0.1Hz resolution.

(6) Now, with our "better" knobs, collect data (on a spreadsheet) from at least 5 subjects on the following:
(a) Tremor: Have a subject hold the middle finger of one hand on the top a a knob with the instruction to keep the finger as steady as possible; record the result tremor/noise, or lack thereof. Try with one middle finger on the left knob and one on the right. Is the "noise" on the knobs correlated or not? Correlated in time we mean here...

(b) Have each subject do an "in-phase" vs "alt-phase" test (in phase is both arms/hand using the same muscles at the same time...). Study your time-domain diagrams to make sure a subject doesn't switch form alt to in-phase during the alt-phase test. Do not allow "trembling" of small amplitude on the low friction knobs: Let's say the p-p amplitude of the back and forth rotation should be at least 64 clicks (out of 1024 for 360 deg).

(c) Have each subject do an dominant vs non-dominant hand test, looking again for knob rotation frequency as the result, and p-p amplitude > 64 clicks.

(d) Try a single-finger rotation vs a 3-finger grip rotation; which is faster?

(7) With Excel, use t-test with paired data to find the two-tailed significance of any differences.

NOTE: LabVIEW 7.1 does not have an obvious digital scan; you may want to attach your encoder outputs (Ch A, Ch B) ot analog inputs, scan the 4 inputs, and convert digital. Or the knob rotation frequency may be so slow that a digital-read inside a FOR loop will be sufficient to capture the frequencies we want.