Author Topic: Quadrature encoder decoder chip.  (Read 14488 times)

0 Members and 1 Guest are viewing this topic.

Offline baljemmett

  • Supporter
  • ****
  • Posts: 666
  • Country: gb
Re: Quadrature encoder decoder chip.
« Reply #25 on: October 10, 2011, 12:43:30 pm »
for lookup table as bux's method, pic10f will not be able to do, it only has 24 registers, no eeprom.
only require two registers (the state variable and a temporary), 25 words of program space for the lookup table
i know about two registers. but how do you access program space?
let me answer my own question. even though there's no instruction in pic10f to access the program space directly, but maybe its possible using the program space in form of returning function. by manipulating its address or PC register.

Yes, that's how I'd have done it -- seems to be a (or the!) canonical method for non-sparse lookup tables on a PIC.  The lookup table is implemented as:

Code: [Select]
    addwf PC, F
    retlw 0x3    ; ttable[0][0]
    retlw 0x2
    retlw 0x1
    retlw 0x0
    retlw 0x83   ; ttable[1][0]
    retlw 0x0
    retlw 0x1
    retlw 0x0
    [... etc ...]

And then the rotary_process routine is something like:

Code: [Select]
    movf    state, W    ; table index is 4 * (state & 0x0f) + (GPIO & 0x03)
    andlw   0xf
    movwf   temp
    rlf     temp, F     
    rlf     temp, F     ; first term now in temp
    movf    GPIO, W
    andlw   0x3
    addwf   temp, W     ; now W contains the computed table index
    call    ttable      ; do the lookup
    movwf   state       ; and retain new state
    andlw   0xc0
    ; and now W's top two bits indicate direction of turn, if any
    ; a return would be nice but the 10F200 seems only to have retlw!

... the lack of return means you'd want to actually just make that the main loop, with a few lines at the end to set those two bits on the output pins.  But that's no great loss, since the main loop was just going to be a call rotary_process and the same few lines at the end!  (Also, my rotary_process can definitely be optimised by at least one instruction, but I'll leave it as is for the sake of clarity.)

Offline dfnr2

  • Regular Contributor
  • *
  • Posts: 228
  • Country: us
Re: Quadrature encoder decoder chip.
« Reply #26 on: October 11, 2011, 06:54:35 pm »
US Digital sells an LSI logic chip (LS7183) that will do what you want (Here's the link.)  You can also get in in an SMD version, and a version that provides a DIR and PULSE output instead of separate UP and DOWN pulse outputs (LS7184).  These have schmitt triggers and debounce built in.   They also have fancier quadrature decoders.

If you are producing in large volumes and cost is an issue, then as others have said, you can do this in a 8-pin PIC, which you can order pre-programmed from Microchip direct and save time and errors during assembly.  BTW, I personally have learned to steer clear of the Atmel parts for anything other than hobby use, due to their long history of availability issues.


Offline Gall

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: ru
Re: Quadrature encoder decoder chip.
« Reply #27 on: October 12, 2011, 12:12:50 pm »
Well, even a couple of 74s is enough to do that.
The difficult we do today; the impossible takes a little longer.

Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo