| ??? 12/04/00 21:01 Read: times |
#6963 - RE: Digital encoder |
Hello John (and others reading this message)
Here you have a routine I made myself some time ago. I use an encoder ("digipot") with feelable "clicks". At rest, both port lines to which it is connected are "1". I made the routine in a way that it MUST see the expected sequence of the greycode. If the sequence is not right (what means we have not moved to the next click but moved back) the routine resets itself and the softwarecounter representing the value is not updated. This will work reliable as long as the timer interrupt interval is not to long. Maybe you can get some ideas by studying my code. Comments from others are welcome as well :) There are more ways to gain your object. I mention for example using the hardware methode: take an UP/DOWN-counter, connect one lead of the encoder to the UP/DOWN input, the other lead to the CLOCK input. Connect the counter outputs to an I/O port of your microcontroller. You can read the counter from the I/O port. If nessesary you can even connect the resetline of the couter to your controller. Sure it uses a few I/O lines, but you have less software- overhead. please see here my software solution: FLAGS EQU 20H DIGIPOTFLAGS EQU 21H FASE_1 DBIT DIGIPOTFLAGS.1 FASE_2 DBIT DIGIPOTFLAGS.2 FASE_3 DBIT DIGIPOTFLAGS.3 DIGIPOTMEM EQU 22H ;temporary variable for digipotroutine POTCOUNTER EQU 23H ;softwarecounter for digipot ; ORG 0000H LJMP INIT ;(RESET (power on)) ; INIT: MOV DIGIPOTFLAGS,#0 MOV DIGIPOTMEM,#0 MOV POTCOUNTER,#0 ; ; Put here some code to initialise a counter to be a timer generating ; interrupts at certain intervals. The routine DIGIPOT is the interrupt routine ; being served. ; LJMP MAIN ; *************************************************************************************** DIGIPOT: MOV A,P1 ;digipot connected to P1.3 & P1.4 ANL A,#18H ;maskeer digipotbits JNZ NOT_ZERO ;jump if digipot is not at rest ZERO: JNB PHASE_1,RESET_DIGIPOT ;reset all if we did not store phase 1 situation SETB PHASE_2 ;we are into phase 2 now (both lines LOW) LJMP EXIT_DIGIPOT ; NOT_ZERO: CPL A ANL A,#18H JZ BOTH_1 ONE_IS_ONE: CPL A ANL A,#18H JB PHASE_2,PHASE_3 JB PHASE_1,COMPARE_1 SETB PHASE_1 MOV DIGIPOTMEM,A LJMP EXIT_DIGIPOT ; COMPARE_1: CJNE A,DIGIPOTMEM,RESET_DIGIPOT LJMP EXIT_DIGIPOT ; PHASE_3: CJNE A,DIGIPOTMEM,VALID LJMP RESET_DIGIPOT ; VALID: SETB PHASE_3 LJMP EXIT_DIGIPOT ; BOTH_1: CPL A ANL A,#18H JNB PHASE_3,EXIT_DIGIPOT JB DIGIPOTMEM.4,TURNING_LEFT INC POTCOUNTER SJMP RESET_DIGIPOT TURNING_LEFT: DEC POTCOUNTER ; RESET_DIGIPOT: MOV DIGIPOTFLAGS,#0 MOV DIGIPOTMEM,#0 ; EXIT_DIGIPOT: RETI MAIN: "your main program starts here.... " ******************************* sincerely, Henk |
| Topic | Author | Date |
| Digital encoder | 01/01/70 00:00 | |
| RE: Digital encoder | 01/01/70 00:00 | |
| RE: Digital encoder | 01/01/70 00:00 | |
| RE: Digital encoder | 01/01/70 00:00 | |
| RE: Digital encoder | 01/01/70 00:00 | |
| RE: Digital encoder | 01/01/70 00:00 | |
| RE: Digital encoder | 01/01/70 00:00 | |
| RE: Digital encoder | 01/01/70 00:00 | |
| RE: Digital encoder | 01/01/70 00:00 | |
| RE: Digital encoder | 01/01/70 00:00 | |
| RE: Digital encoder | 01/01/70 00:00 | |
| RE: Digital encoder | 01/01/70 00:00 | |
| RE: Digital encoder | 01/01/70 00:00 | |
| Wrong counts, Debouncing | 01/01/70 00:00 | |
| RE: Digital encoder | 01/01/70 00:00 | |
| RE: Digital encoder | 01/01/70 00:00 | |
RE: Digital encoder | 01/01/70 00:00 |



