*12345678901234567890123456789012345678901234567890123456789 #INCLUDE 'A:\VAR_DEF.ASM' * LAB4-EX3.ASM * This exercise captures the times T1 and T2 required * in the tachometer program. * T1 is the first time when a falling edge transition is * encountered on pin IC1. * T2 is the second time when a falling edge transition * is encountered on the same pin IC1. This corresponds to * the time between two consecutive passages trough the * emitter-detector sensor of the hole in the rotating disk. * The difference between T2 and T1, plus the time taken * by the overflows, will represent the period of rotation * of the disk. Hence, using LAB4-EX2 and LAB4-EX1, one can * calculate the rotation speed. * To run the program, open Timer register window, * PortA window, and memory window. Toggle pin IC1 to 1. * Start the program. The program stays in a loop waiting * for a falling edge transition on pin IC1. * Toggle pin IC1 to 0. The value of TCNT should appear * in TIC1. The program should enter the second loop. * Let the program run and watch the timer count, TCNT, * to overflow at least one time. The NOF counter * should increase by one every time TCNT overflows. * Toggle IC1 back to 1. Nothing should happen since only * falling edges should be detected. Toggle IC1 to 0 again. * The value of TIC1 should be updated. * After the second toggle, the program should go back at * the begining. After returning to the beginning, the * program zeros the NOF counter and goes through the * two-step process again. *12345678901234567890123456789012345678901234567890123456789 * Define variables ORG DATA NOF RMB 1 ; number of overflows T1 RMB 2 ; time of 1st capture T2 RMB 2 ; time of 2nd capture IC1_MSK EQU %00000100 ; mask for IC1F TOF_MSK EQU %10000000 ; mask for TOF * Start main program ORG PROGRAM START LDY #REGBAS ; set index Y LDAA #%00100000 ; set EDG1B=1, falling edge transition STAA TCTL2,Y ; LABEL0 NOP LDAA #IC1_MSK ; reset IC1F by writing 1 to it STAA TFLG1,Y ; LABEL1 LDAA TFLG1,Y ; check for 1st input capture ANDA #IC1_MSK ; IC1F=0 ? BEQ LABEL1 ; go back if IC1F=0 * We have input capture on IC1 LDAA #IC1_MSK ; reset IC1F STAA TFLG1,Y LDD TIC1,Y STD T1 ; store time of 1st input capture LDAA #TOF_MSK ; clear TOF by writing 1 to it STAA TFLG2,Y ; LDAA #$00 ; reset overflow counter NOF STAA NOF ; LABEL2 LDAA TFLG2,Y ; check TOF in TFLG2 & jump over if not set ANDA #TOF_MSK BEQ LABEL3 *We have overflow INC NOF ; increment overflow counter LDAA #TOF_MSK ; reset TOF STAA TFLG2,Y LABEL3 LDAA TFLG1,Y ; check for 2nd input capture ANDA #IC1_MSK ; BEQ LABEL2 ; go back and check again TOF & IC1F * We have second capture on IC1 LDD TIC1,Y STD T2 ; store time of 2nd input capture * loop back to begining BRA LABEL0 SWI ORG RESET ; reset vector FDB START ; set to start of program