



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The solution to homework 5 of the eecs 388: computer systems and assembly language course. It includes calculations for generating a specific delay using real-time interrupts (rti) and measuring the period of a signal using rti and interrupts. The document also includes an example program for measuring the period of a signal.
Typology: Assignments
1 / 6
This page cannot be seen from the preview
Don't miss anything!




Assuming MCLK is at 4 MHz (as stated above), and the pre-scaler is set to 1, this means that the timing frequency is (4 MHz)/(2^1 ) = 2 MHz, or a period of 500 ns. If the two counts (or timestamps) are $1993 and $07C8, then the period of the measured signal (assuming no counter rollovers) is $EE34, which is 60,980 counter ticks in decimal. This period, in real-time, is thus: (($FFFF - $1993) + $07C8) + 1 ๏ 60,981 ticks and 60,981 ticks * (500 ns / 1 tick) = 30.4905 ms.
STAA TCTL4, X LDAA #TIOS_IN ; Select channel 3 STAA TIOS_IN, X LDAA #TSCR_IN ; Enable timer STAA TSCR_IN, X RTS ; return ; ************************************************** ; Function used to measure signal period ; via polling method ; ************************************************** MEASURE LDAA #CLR_CH3 ; Clear channel 3 flag to prepare measurements STAA TFLG1,X ; Grab measurement of first edge WAIT BRCLR TFLG1,X,$08,WAIT1 ; Wait for an edge LDD TCNT,X ; Load in counter value STD edge1 ; Save the measurement LDAA #CLR_CH3 ; Clear channel 3 flag again STAA TFLG1,X ; Grab measurement of second edge WAIT BRCLR TFLG1,X,$08,WAIT2 ; Wait for an edge LDD TCNT,X ; Load in counter value SUBD edge1 ; Calculate the difference between edges STD period ; Store the period result RTS ; return
High counter: = 266.67 microseconds * (1 tick / 0.5 microseconds) = 534 ticks ๏ $ Low counter: = 400 microseconds * (1 tick / 0.5 microseconds) = 800 ticks ๏ $ ; Program Equates for interrupts INTCR EQU $001E INTCR_IN EQU $ ; Program Equates for the timer circuitry TMSK1 EQU $008C TMSK2 EQU $008D TCTL2 EQU $ TIOS EQU $ TC2H EQU $ TSCR EQU $ TFLG1 EQU $008E TMSK1_IN EQU $ TMSK2_IN EQU $ TCTL2_IN EQU $ TIOS_IN EQU $ TSCR_IN EQU $ HIGH_TIME EQU $ LOW_TIME EQU $ ORG $FFEA ; Register interrupt vector for timer channel 2 FDB MY_IRQ ORG $4000 ; Initialize timer channel 2 and interrupts LDS #$8000; Setup the stack MOVB #TMSK1_IN, TMSK1 ; Enable interrupts on channel 2 MOVB #TMSK2_IN, TMSK2 ; Set prescale to 4 MOVB #TCTL2_IN, TCTL2 ; OC2 toggle on compare MOVB #TIOS_IN, TIOS ; Select channel 2 for OC MOVW #HIGH_TIME, TC2H ; Setup initial high time MOVB #TSCR_IN, TSCR ; Enable timer LDAA TFLG ORAA #$04 ; Clear timer flag STAA TFLG MOVB #INTCR_IN, INTCR ; Setup interrupts CLI ; Enable interrupts