PropBasic: Quadrature Encoder Help Please
skynugget
Posts: 172
hey all, im trying to decode a standard quadrature encoder, and im soooo close.
the code below seems to only count in a negative direction no matter which way i turn the encoder.
i suspect im not masking the bits right before i check for the direction.
does anyone see the mistake in the following test program? thanks so much!
the code below seems to only count in a negative direction no matter which way i turn the encoder.
i suspect im not masking the bits right before i check for the direction.
does anyone see the mistake in the following test program? thanks so much!
DEVICE P8X32A, XTAL1, PLL16X XIN 5_000_000 Baud CON "T9600" Encoder PIN 10..11 INPUT TX PIN 30 HIGH LOAD "serial.lib" idx var long tmp var long tmp1 var long tmp2 var long encNew var long encOld var long encVal var long ' ====================================================================== PROGRAM Start ' ====================================================================== Start: ' init Main: encNew = Encoder 'get incoder bits tmp = encOld ^ encNew 'did it change? IF tmp = 0 THEN skip 'no so skip encOLD = encOLD << 1 'align encOLD = encOLD ^ encNew 'check direction tmp1 = encOLD & %00000010 'iso bit1 IF tmp1 = 1 THEN 'going up INC encVal 'add to value ELSE 'going down DEC encVal 'subtract from value ENDIF encOLD = encNew 'save last input skip: TX_DEC encVal 'debug value TX_BYTE 1 'debug home GOTO Main END
Comments
Glad you got it working and thanks for posting the working code. So many forget to do this and really helps others out.
Bean
Thanks
@Bean. Its my opinion to: At every time anyone POST (Solved) --- Them can Post how them solved it.
That can help many Beginners to found theirs problems.
And thanks for PBasic.
no worries boss, there are lots of threads to manage . without people posting problems, solutions and snippets, i never would have been able to get started with microcontrollers, i try to post everything i can so that someday i may return the favor.
Thanks skynugget:
'
I just got a Quadrature encoder set-up last night. I planed to write some code for it this evening in PropBasic.Thanks for the code.
'
I hope you post the Quad-code in the OBEX under PropBasic!
'
Thanks again.