Lab4

advertisement
EE 333 Laboratory Exercise # 4
Interrupts
J. P. Froehlich
Introduction
A very powerful feature of all micro-controllers is that they can support
interrupts. There are 16 hardware, two software, and 3 reset interrupts. An interrupt
allows the processor to cease its current task, transfer program flow to the service routine,
and after completion of the service return to the task it was performing previous to the
interrupt. It is if, the controller got a telephone call while performing a task. A common
interrupt routine is to keep the time of day current.
Your assignment
In this assignment we will use the hardware interrupt using the maskable interrupt
/IRQ pin. The laboratory is in 2 parts. The first is a variation on the simple interrupt
described on page 267. The interrupt service routine is a modulo counter, the output to
be displayed on the PC monitor screen. I will assign a modulo count from 5 down to 3.
The service routine will update the count displayed on the PC monitor screen each time
an interrupt occurs. The /IRQ pin of the demo board is to be connected to debounced
switch that generates a clean negative pulse of width 2 to 20 microsecond in width.
You are design and build a pulse generator with either a 74121, 74122, 74123, or
555 timer. One of theses is a better choice then the other and that should be obvious when
you complete the design using each device. The 741XX was used in EE 231 lab. The 555
/556 is another popular timer, and data is available on the Web. You are to build this
circuit in the protoboard area on the AXIDE.
Create flow charts and produce code that will display the number of pulsed
generated with key closures on your one-shot device. After 20 decimal closures have
occurred, return to the BUFFALO monitor. To return to BUFFALO monitor use the
software instruction SWI which is a software interrupt.
The second part of this exercise is to write a real time clock, updated every second
on the PC monitor. The instructor will provide a GAL 22v10 that is programmed to
produce an interrupt the processor 3906 1/4 each second. This frequency is derived from
the system clock of 2 megahertz by dividing by 512. The pulse is low for 8 microseconds
and can be used to control the IRQ pin. The service routine is time critical, since you
have only 250 microsecends before the next interrupt. This would make this application
interrupt critical. The cycle counting feature will help you evaluate if this is a feasible
application with the frequency of interrupt. It is only after 3906 interrupts does the time
consuming update routine occurs. The other interrupt is a simple down counter and hasty
return. However, to keep accurate time by using 3906, the clock is slow and the ¼ cycle
must be corrected. To do this every 4th interrupt must be advance by one and 3907 is
loaded in place of the 3906.
To illustrate if the interrupt could occur (which it can not) at 2,000,000 a second a
counter of 3 bytes is needed, at 1,000,000 to 125,000 a second still requires a 3 byte. At a
frequency of 62,500 pulses per second the 16 bit counter can be used. A 7 divider is the
last integer to fit into a 16 bit register, and that is 15625. At tis interrupt rate, there would
only be 64 microseconds to service the interrupt. It takes 24 microseconds to save
registers, restore and return. Little time is left to process. Higher divides no longer fit as
integers. The best the 22v10 can do is to get 3906.25 but the time compensation above
must be used to keep the time accurate.
Your challenge is write the service routine to provide a real time clock update to
the PC monitor. The update of the display on the PC monitor must be in the main
program. After the interrupt procedure is completed, check the number of clocks required
and make sure it can be completed in the allocated time. It is possible to stack interrupts,
that is while an interrupt is being serviced, it is possible to respond to another interrupt.
As part of this report, determine approximately how much time is consumed by
the interrupt and how much time is available for other processing. What should you do to
improve the time for processing, that is reduce interrupt service time.
Download