View Single Post
  #6   Spotlight this post!  
Unread 09-03-2003, 08:16
dave_l dave_l is offline
Registered User
#1038
 
Join Date: Feb 2003
Location: Lakota East HS
Posts: 10
dave_l is an unknown quantity at this point
For simplicity and cost reasons, we chose to use mechanical rather than optical encoders. These are basically rotary switches in quadrature; common to ground, A and B outputs to two digital inputs.

Timing is something you have to think about. Determine your maximum revolutions per second at the encoder, invert to get time per revolution, then divide by the number of encoder states to get time per state. Each state should last at least 26 milliseconds (longer is better - ours worked out to 55ms).

If you are trying to track absolute position, you will need to establish a reference point.

(In our implimentation, we attached the encoder to an earlier stage on the gearbox, which acts as a multiplier on the encoder - [N encoder states] times [gearing ratio] = #Effective states)

Given the above, the following code works great for us...

'table lookup using current and previous encoder state
temp.bit3 = fng_sensorA
temp.bit2 = fng_sensorB
temp.bit1 = fng_sns_lstA
temp.bit0 = fng_sns_lstB
read graydcd+temp.lownib, temp

'update current position with change in position (mod 256)
fng_sns_pos = fng_sns_pos + temp

'save current encoder bits for next time around
fng_sns_lstA = fng_sensorA
fng_sns_lstB = fng_sensorB

'finger zero established as 6 o'clock, +=ccw
fng_inp = (fng_inp */ fng_inp2sns_m) + fng_inp2sns_b 'scale OI control input to sensor units
if fng_sns_calib then fng_sns_pos = fng_inp 'reset calib
temp = (fng_sns_pos - fng_inp) */ fng_sns2mtr_scl 'to +-127
fng_motor = 254 - (127 + temp)

graydcd data 0,255,1,-0, 1,0,-0,255, 255,-0,0,1, -0,1,255,0 'state table for finger position decode

(The '-0' entries are the cases where somehow you missed an encoder state change)