Solution to EECS 388 Homework 5: Measuring Signals with Real-Time Interrupts, Assignments of Electrical and Electronics Engineering

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

Pre 2010

Uploaded on 03/11/2009

koofers-user-0gn
koofers-user-0gn ๐Ÿ‡บ๐Ÿ‡ธ

9 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
EECS 388: Computer Systems and Assembly
Language
Homework 5 Solution
1. (20) How many RTI interrupt events must occur to generate
a 15 minute delay assuming the MCLK is operating at
2MHz and the RTR[2:0] bits are set for โ€œ110โ€? How do
you set up the Realโ€Time Interrupt Control Register (RTICTL)
(i.e., enable RTI and set RTI pre-scale) for this purpose?
According to the table on page 229 of your textbook, the period of a
RTI interrupt is set by the MCLK frequency divided by a divisor stored in
RTR[2:0]. Therefore:
RTR[2:0] = โ€œ110โ€ implies a clock divider of 218.
MCLK = 2 MHz and a divider of 218 implies that the frequency of
RTI interrupts is 7.6294 Hz (2 MHz / 218).
The time delay, or period, between RTI events is thus 1/7.6294
Hz = 0.1311 seconds (because period = 1 / frequency).
Now, if we want a delay of 15 minutes:
15 minutes = 900 seconds.
Number of RTI events for 15 minutes =
o(900 seconds)/(0.1311 seconds per delay) = 6,867.
oThus, it will require about 6,867 RTI events
One must write the appropriate values into the RTICTL in order to
enable interrupts and to set the RTI frequency. The RTICTL register is a
memory-mapped location located at address $0014. The RTIE bit is the
MSB (bit 7), while the RTR[2:0] bits are the least-significant 3 bits (bits
2 through 0).
RTICTL EQU $0014 ; Equate for the address of the RTICTL register
LDAA %10000110 ; RTICTL mask (RTIE =โ€™1โ€™, RTR[2:0]
= โ€œ110โ€)
STAA RTICTL ; Store the value into RTICTL
2. (15) Textbook, page 291. Advanced problem #4. Change
MCLK to 4 MHz.
pf3
pf4
pf5

Partial preview of the text

Download Solution to EECS 388 Homework 5: Measuring Signals with Real-Time Interrupts and more Assignments Electrical and Electronics Engineering in PDF only on Docsity!

EECS 388: Computer Systems and Assembly

Language

Homework 5 Solution

  1. (20) How many RTI interrupt events must occur to generate a 15 minute delay assuming the MCLK is operating at 2MHz and the RTR[2:0] bits are set for โ€œ110โ€? How do you set up the Realโ€Time Interrupt Control Register (RTICTL) (i.e., enable RTI and set RTI pre-scale) for this purpose? According to the table on page 229 of your textbook, the period of a RTI interrupt is set by the MCLK frequency divided by a divisor stored in RTR[2:0]. Therefore: RTR[2:0] = โ€œ110โ€ implies a clock divider of 2^18. MCLK = 2 MHz and a divider of 2^18 implies that the frequency of RTI interrupts is 7.6294 Hz (2 MHz / 2^18 ). The time delay, or period, between RTI events is thus 1/7. Hz = 0.1311 seconds (because period = 1 / frequency). Now, if we want a delay of 15 minutes: 15 minutes = 900 seconds. Number of RTI events for 15 minutes = o (900 seconds)/(0.1311 seconds per delay) = 6,867. o Thus, it will require about 6,867 RTI events One must write the appropriate values into the RTICTL in order to enable interrupts and to set the RTI frequency. The RTICTL register is a memory-mapped location located at address $0014. The RTIE bit is the MSB (bit 7), while the RTR[2:0] bits are the least-significant 3 bits (bits 2 through 0). RTICTL EQU $0014 ; Equate for the address of the RTICTL register LDAA %10000110 ; RTICTL mask (RTIE =โ€™1โ€™, RTR[2:0] = โ€œ110โ€) STAA RTICTL ; Store the value into RTICTL
  2. (15) Textbook, page 291. Advanced problem #4. Change MCLK to 4 MHz.

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.

  1. (15) Textbook, page 291. Advanced problem #5. If the period of the pulse being measured is greater than the rollover time for the counter, then one must make sure to detect counter rollovers in order to accurately measure the signal of interest. Think of this process as noting every New Years Eve from when you were born until the present time in order to figure out how old you are. This requires one to modify the program to log every counter rollover (pulse-accumulator overflow bit, or PAOVF). Given the numbers from above (problem #2), we know that counter is adjusted by 1 every 500 ns, and that the counter will rollover when it reaches 2^16 , or 65,536. This means that pulse length of interest can be found by counting counter rollovers: Period= # rollovers + # of extra ticks = (500 ns / 1 tick) [(# of rollovers)(65,536 ticks/ 1 rollover)+ (current ticks)]
  2. (25) Write a program to measure the period of a periodic signal connected to input channel 3 by measuring the count difference between two falling edges. Set PR2:PR0 =
    1. Use polling method.

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

  1. (25) Generate a 1500Hz square wave with a 40% duty cycle (ON/PERIOD) on output compare channel 2 (OC2). MCLK = 8MHz. Set the pre-scaler to divide by 4. Use interrupt. This program is very much like the example program found on pg. 275 of the textbook except that it uses interrupts. If the MCLK runs at 8 MHz and the pre-scaler is set to 4, then the counter will adjust at a rate of (8 MHz)/4 = 2 Mhz, or with a period of 500 ns. A 1500 Hz signal has a period of 666.67 microseconds, and a 40% duty cycle means that it will be high for 0.4*666.67 microseconds or 266.67 microseconds, and low for 400 microseconds. This translates to counter value of:

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