Interrupt and Output Compare Systems

Interrupt and Output Compare Systems

EE-3306 HC6811 Lab #3

Interrupt and Output Compare Systems

Objectives:

The purpose of this lab is to become familiar with the 68HC11 real time interrupt system and the output compare functions. In this lab, you will program the Real Time Interrupt systemand the output compare system to generate four different square waves to form a 4-bit counter.

Prelab Questions:

1. What are maskable and unmaskable interrupts? Give two examples of each.

2. Where are the vector addresses for the following interrupts:

(a) Real Time Interrupt

(b) Timer Output Compare 2

(c) Pulse Accumulator Overflow

(d) Software Interrupts

List them according to increasing priority (i.e. the lowest priority interrupt first and the highest priority interrupt last).

3. Define duty cycle.

References

1. Motorola, Inc, M68HC11 E Series Programming Reference Guide, (MC68HC11ERG/AD.

2. Motorola, Inc, MC68HC11E Family Technical Data, MC6811E/D-Rev 3, 2000.

3. Motorola, Inc, Buffalo Monitor for HC11 Development Boards.

4. Axiom Manufacturing, CME11E9-EVBU Development Board, 1999.

Equipment for this lab:

• 68HC11 trainer kit, to include 68HC11 EVBU and prototyping strips.

• IBM compatible PC to connect to the trainer kit via an RS-232 serial cable.

• Agilent 54621D oscilloscope.

• Floppy disk provided by student.

Laboratory Exercise

Notes:

• Make sure your development EVBU board is connected to power (green LED on board ON)

and the serial port of the EVBU is connected to the serial port of your development PC containing

the AXIDE software, configured to the correct port at the correct baud rate, etc.

• Be sure to bring your control.RTF file from 68HC11 lab #2.

• The lab TA has a copy of the .s19 files for each part of the lab. The TA will demonstrate the waveforms to you at the beginning of the class.

Part 1

In this part, you will program the Real Time Interrupt (RTI) system to generate interrupts at a known rate, and use the interrupts to generate square waveforms of known frequency.When the interrupt is enabled in the program, the control jumps to the interrupt vector subroutine which has the code to generate the square wave that we need. Once the control jumps to this subroutine, a flag gets indicating that an interrupt has occurred. When this flag is set, another interrupt does not occur again. So, to keep the waveforms continuous, it is important to clear this flag.

Please read pages 382 - 385 of the 68HC11 reference manual for a detailed description of the RTI system. There are mainly two registers which are used to control the RTI system: PACTL and TMSK2 as shown below. The bits “RTR1” and “RTR0” in register “PACTL” determine the pre-scalar for the clock input. These bits can be changed to get different RTI rates, meaning, generate interrupts at different time rates. The following table shows the different rates obtained by changing the bits. These rates are for a crystal frequency of 8MHz at which the Axiom board operates.

RTR1 / RTR0 / Rates / Period / Frequency
0 / 0 / 4.10ms / 8.2ms / 122 Hz
0 / 1 / 8.19ms / 16.35ms / 61.2Hz
1 / 0 / 16.38ms / 32.75ms / 30.53Hz
1 / 1 / 32.77ms / 65.4ms / 15.29Hz

The bit “RTII” in register “TMSK2” enables the RTI interrupts. The bit “RTIF” in register “TFLG2” indicates that a RTI has occurred. In order to clear the flag RTIF, a ‘1’ should be written in this bit at the end of the interrupt vector subroutine.

A program has been provided to generate real timeinterrupts at all the rates given in the table and create 4different square wavesof 50% duty cycle. RTI_prog1.RTF The output is obtained from bits 2,3,4,5 of PORTD. It has to be configured to act as output port using the data direction register. By writing a 1 into bits 2,3,4,5 of this register, the pins 2,3,4,5 of PORTD are made output pins.These bits are used for the 4-bit counter. The frequencies given in the table apply to the bit 0 of the counter (which is bit 2 of PORTD) in this case.

Program:

  • The first step in the program is to label all the control registers that are needed in this program.
  • The main program and the interrupt subroutine are stored in separate memory locations and hence they should be indexed in the beginning. The interrupt vector address of the RTI is located at $00EB-$00ED in the Axiom Board.
  • The main program starts with disabling interrupts, initializing all the stack locations and PORTD.
  • The registers PACTL and TMSK2 are then configured to enable the interrupts.
  • The instruction ‘cli’ is necessary because it is the global interrupt enable.
  • Once the interrupt is enabled, the control jumps to the interrupt vector subroutine int_RTI.
  • The subroutine int_RTI is meant to generate a counter.
  • The value in PORTD which is already initialized to 0 (init_PORTD) is incremented every time an interrupt occurs. Thus we get a 4 bit counter with the LSB having the frequency that the RTI generates.
  • The RTIF is reset at the end of the subroutine.

Part 2

In this part you will learn how to use different output-compare function of the 68HC11 to generate waveforms of a known duty cycle. There are as many as 5 output compare functions for this microcontroller. So, there are 5 different counters (TOCx) to control these functions. An output compare is generated when the free running counter of the 68HC11 matches the value of “TOCx” counter.This signal can be used to generate an interrupt if the corresponding interrupt enable bit in the register “TMSK1” is set. The “OMx” and “OLx” bits in register “TCTL1” determine the state of output pin “OCx” when the free running counter matches the “TOCx” counter. Refer to Table 10-6 on page 413 of the 68HC11 reference manual for details.

You will be learning how to program the output-compare channels to generate a 4-bit counter. The duty cycle of the waveforms is 50%. You can also try changing the duty cycle of the waveforms. Start with the program stud_oc_prog1.RTF

You need to program the “TMSK1” and “TCTL1” registers with the appropriate values to generate the waveform. The program given to you shows how to use the output compares 2,3,4,5 to generate the counter. The Output Compare Interrupts OC 2,3,4,5are enabled in the “TMSK1” register. ‘OMx’ and ‘OLx’ bits in the “TCTL1” register should be programmed to generate the required waveform at the relevant pins. When ‘OMx’ is 1 and ‘OLx’ bit is 1, the output at the pins ‘OCx’ will toggle every time the interrupt is enabled thus generating a square wave.

TCTL1 $1020

OM2 / OL2 / OM3 / OL3 / OM4 / OL4 / OM5 / OL5

TMSK1 $1022

OC1I / OC2I / OC3I / OC4I / OC5I / IC1I / IC2I / IC3I

tHIGH and tLOWof the square wave depends on the value that is given to the counter TOCx.

Separate variables say ‘high’ and ‘low’ are used to store the values of the counters to determine tHIGH and tLOW. These values should be alternately loaded into TOCx registers in order to generate the complete square wave. The duty cycle depends on the ratio of the values in these variables. Another variable, say x, will determine which variable (high or low) is loaded into the TOCx when an interrupt is generated each time. Depending on

Once the interrupt is enabled the interrupt flag gets set. For continuous enabling of these interrupts, this flag should be cleared at the end of the interrupt vector subroutine.

The program provided to the students shows how to generate one waveform. The students are required to generate the other three waveforms on similar lines.

Program:

  • All the registers that are needed for the program are assigned with labels in the beginning.
  • The main program and the interrupt service subroutine for the output compare are to be indexed. The vector addresses for these interrupts are provided to you in Table 4 of the document at the following link.
  • Memory is assigned for variables ‘high’ and ‘low’.
  • The main program starts with configuring the registers TCTL1, TMSK1 and TFLG1.
  • It is configured for OC2 function. The students are required to do it for the other OC functions.
  • The global interrupt enable enables the interrupt. The control jumps to the interrupt subroutine (in this case int_TOC2).
  • The interrupt subroutine generates the square wave. The value ‘high’ and ‘low’ are alternately loaded into the TOC2 register depending on the value of the variable ‘which’. When this value compares with that of TCNT, a signal is obtained at OC2 pin.
  • The flag is reset at the end of the subroutine through the TFLG1 register.

Follow the program and include code to generate other waveforms. TOC3,4,5 can be used. More variables are needed to determine the value of tHIGH and tLOWfor each waveform. Select the values of these variables such that frequency of one is half of the other waveform.

Assemble the code and show the waveforms to the TA.

T.A.Initials:______