* icb file: "sencdr27.asm" * 6.270 V2.1 board shaft encoders * samples at 250 Hz. rate * updates velocities every 128 ms. * operates off of system interrupt * Fred Martin * Wed Jan 15 00:53:55 1992 * Updated by Brian Van Mondfrans * Tue Apr 5 22:27:00 1994 * int aar[8]={0,0x0400,0x0200,0x0600,0x0100,0x0500,0x0300,0x0700}; * Table for Analog port selection * analog port MUX ANLG_PORT * 12 0 4 * 13 1 4 * 14 2 4 * 15 3 4 * 16 4 4 * 17 5 4 * 18 6 4 * 19 7 4 * 20 0 5 * 21 1 5 * 22 2 5 * 23 3 5 * 24 4 5 * 25 5 5 * 26 6 5 * 27 7 5 MUX EQU 6 ANLG_PORT EQU 5 #include "6811regs.asm" #include "pcode_eq.asm" ORG MAIN_START * schmitt trigger thresholds, states for counting pulses variable_encoder19_low_threshold: FDB 190 variable_encoder19_high_threshold: FDB 220 encoder_state: FCB 0 * tick and velocity counts variable_encoder19_counts: FDB 0 variable_encoder19_velocity: FDB 0 last_counts: FDB 0 subroutine_initialize_module: #include "ldxibase.asm" * install ourselves onto system interrupt * get current vector; poke such that when we finish, we go there LDD TOC4INT,X ; SystemInt on TOC4 STD interrupt_code_exit+1 * install ourself as new vector LDD #interrupt_code_start STD TOC4INT,X * reset encoder variables LDD #0 STAA encoder_state STD variable_encoder19_counts STD variable_encoder19_velocity STD last_counts RTS ********************************************************************** * * System Interrupt code: * * interrupt_code_start: LDAA system_time_lo+1 ; lowest byte ANDA #%00000011 BNE interrupt_code_exit LDX #BASE * take encoder reading; set multiplexer BCLR PORTD,X MUX*8 BSET PORTD,X MUX*8 * BSET PORTD,X 0-MUX*8+%00111000 * set analog LDAA #ANLG_PORT STAA ADCTL BRCLR ADCTL,X $80 * LDAA ADR1 TST encoder_state * if zero, look for rising edge BNE test_falling CMPA variable_encoder19_high_threshold+1 BLO encdr_done * got it! increment got_click: LDY variable_encoder19_counts INY STY variable_encoder19_counts LDAA encoder_state EORA #$FF STAA encoder_state * frob the beeper test code! * #include BRA encdr_done test_falling: CMPA variable_encoder19_low_threshold+1 BLO got_click encdr_done: * calc velocities every 128 calls LDAA system_time_lo+1 ; lowest byte ANDA #%011111111 BNE interrupt_code_exit * velocities are ticks since last interrupt LDD variable_encoder19_counts SUBD last_counts STD variable_encoder19_velocity LDD variable_encoder19_counts STD last_counts interrupt_code_exit: JMP $0000 /* this value poked in by init routine */