I've written code to read quadrature encoders before. I connected A & B channels to pins that could be set up for interrupt on change. At each interrupt, I Exclusive OR'd the New A value with the previous B value, getting a 1 for one direction and a 0 for the other.
So, for this project I would have A, B, & STEP on "interrupt on change" pins. The interrupt code would do something like:
If A XOR PREV_B = 1 INC COUNT else DEC COUNT, PREV_B = B.
If PREV_STEP = 0 and STEP = 1 then If DIR =1 INC DEST else DEC DEST, PREV_STEP = STEP.
Return from interrupt
Main loop: ERROR = DEST - COUNT. ANALOG_OUT = ERROR X GAIN (DIP Switches or jumpers for gain?)
Are there PIC's with analog outputs?
For the Step and Direction output option, perhaps set up an interrupt with a rate based on the error X gain. Or have a constant interrupt rate and step every so many interrupts.
Any thoughts on this? I think it would be awesome to be able to position accurately with linear encoders even with less accurate lead screws. Depending on how many steps it takes to change your encoder 1 count, you would set up your gain to get to the exact position ASAP without overshoot or oscillation.
Other I/O Perhaps an input from the control when it is disabled. Then set the DEST and COUNT both to zero, we don't want the axis moving when we first enable them. I would like to have maybe and output or green & red LED indicating ERROR = 0 or ERROR != 0.