CP316: Microprocessor Systems and Interfacing
Interrupts
Objectives
Interrupts allow very quick reactions to external
events independent of normal program flow.
Equipment
Procedure
Timer interrupts
- Connect the Arduino board.
- Create a new sketch, and download the
timer interrupt
sketch.
- Connect the oscilloscope to the output pin identified in the
sketch.
- Run the program to see that the square wave appears on the
scope.
- Given the timer mode, should the value in the OCR affect the
period? Change the value and rerun the program to confirm your
prediction.
- Modify the program so that you get direct output from the timer
along with the output from the interrupt. Connect the other
oscilloscope channel to the timer pin, and rerun the program to
confirm the result.
-
Sketch the scope output showing both signals.
Are the two signals tightly synchronized, or is there some
variation in the delay between them? Explain.
(Hint: Trigger on one channel, and see what the other looks like,
and then trigger on the other channel and view the first one.)
Demonstration - demonstrate what you have determined
to the lab instructor.
- Disassemble both the original code and the modified version so
that they can be compared.
Hardware multitasking; timers and interrupts
- Create a new sketch, and download the
timer multitasking
sketch.
- Connect the oscilloscope to the output pins identified in the
sketch.
- Run the program to see that the square waves appear on the
scope.
- Given the timer mode, should the value in the OCR affect the
period? Change the value and rerun the program to confirm your
prediction.
-
Sketch the scope output showing both signals.
Are the two signals tightly synchronized, or is there some
variation in the delay between them? Explain.
(Hint: Trigger on one channel, and see what the other looks like,
and then trigger on the other channel and view the first one.)
Demonstration - demonstrate what you have determined
to the lab instructor.
- Disassemble both the original code and the modified version so
that they can be compared.
What additional code gets added to the ISR beyond what is needed
to toggle the output pin?
Even though the main loop is empty, what code does it still
contain?
3 process program
- Modify the program so that you have an putput pin that can be
toggled in the main loop.
Thus there will be three output pins:
- one controlled directly by a timer;
- one controlled by the ISR;
- one controlled by the main loop.
-
Since you only have two oscilloscope channels, you can only see two
outputs at a time.
Connect the hardware output pin and the ISR pin, as previously, and
observe the output to see that it performs as before.
Sketch the scope output showing both signals.
Are the two signals tightly synchronized, or is there some
variation in the delay between them? Explain.
(Hint: Trigger on one channel, and see what the other looks like,
and then trigger on the other channel and view the first one.)
Demonstration - demonstrate what you have determined
to the lab instructor.
-
Now connect the hardware output pin and the main loop pin
and observe the output to see that it performs as expected.
Sketch the scope output showing both signals.
Are the two signals tightly synchronized, or is there some
variation in the delay between them? Explain.
(Hint: Trigger on one channel, and see what the other looks like,
and then trigger on the other channel and view the first one.)
Demonstration - demonstrate what you have determined
to the lab instructor.
- Disassemble both the original code and the modified version so
that they can be compared.
Now that the main loop is not empty, does the code in it all
make sense?
Wilfrid Laurier University
© 2019 Wilfrid Laurier University