Presentation is loading. Please wait.

Presentation is loading. Please wait.

Surjo Dutta and David Friedman

Similar presentations


Presentation on theme: "Surjo Dutta and David Friedman"— Presentation transcript:

1 Surjo Dutta and David Friedman
Interrupts Surjo Dutta and David Friedman

2 What are interrupts? A signal which indicates to the microprocessor to pause one task, and perform another task Generally, there are two sources of interrupts Hardware/other devices in communication with the microprocessor Software triggers

3 Interrupts on the Arduino Mega
The Arduino Mega has specific ‘interrupt pins’ which are directly read by hardware. Interrupt pins (Digital): 2,3,18,19,20,21 There are several ‘modes’ specifying interrupt conditions LOW: triggers when pin is low HIGH: triggers when pin is high CHANGE: trigger when pin changes at all RISING: trigger when pin goes from low -> high FALLING: trigger when pin goes from high -> low Can run a special function called an interrupt service routine (ISR) Can only run one ISR at a time, and queues incoming interrupts in a First Come First Serve queue, ie, no way to prioritize interrupts But reset gets priority over other interrupts

4 Interrupt service routines (ISR)
A function that executes when an interrupt is triggered An ISR cannot have any parameters and cannot return anything Associate an ISR with an interrupt pin with the ‘attachInterrupt’ function Triggered Not triggered ISR Main code Interrupt condition

5 How do you use them? attachInterrupt (digitalPinToInterrupt(intPin), ISR, INT_MODE); intPin: Digital pin to use as interrupt pin ISR: The interrupt handler, takes no arguments and returns nothing INT_MODE: LOW, HIGH, CHANGE, RISING, FALLING Delay() depends on interrupts and hence can’t be used inside an ISR Keypad-LCD device was also a rudimentary form of an interrupt Remember to explain INPUT_PULLUP if required

6 Software Interrupts Arduinos do not natively support software interrupts External libraries like TimerThree.h can be used They use one of the three built in hardware timers which were initially meant to set PWM periods Now also used for timer overflow interrupt handling, and other features Enables the microcontroller to be interrupted at even time intervals Useful for two to four actions to be performed at different, indivisible frequencies

7 Sources https://www.teachmemicro.com/arduino-interrupt-tutorial/


Download ppt "Surjo Dutta and David Friedman"

Similar presentations


Ads by Google