1 / 7

Interrupts

Interrupts. Surjo Dutta and David Friedman. 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.

stamper
Télécharger la présentation

Interrupts

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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 Main code Interrupt condition ISR Not triggered

  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

  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/ • http://www.engblaze.com/we-interrupt-this-program-to-bring-you-a-tutorial-on-arduino-interrupts/ • https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/ • https://learn.sparkfun.com/tutorials/processor-interrupts-with-arduino/all

More Related