Learn to use Hardware, Pin Change and Timer Interrupts with the Arduino Uno.
Article with code: https://dronebotworkshop.com/interrupts
Today we are working with a fundamental programming concept, the use of Interrupts.
Now, this certainly isn't the first time we have worked with interrupts, we have used Hardware Interrupts in several previous videos. But we have never taken a deep dive into the subject, and as it is a very important concept, I feel it's time that we did!
Plus, Hardware Interrupts are just one of three types of interrupts supported by the Arduino. So we also should take a look at Pin Change and Timer Interrupts as well.
We are working with an Arduino Uno today, but the concepts we are discussing are applicable to just about any microcontroller.
Interrupts can help you make more responsive user interfaces, perform timed operations, or just write better and more efficient code.
Here is the Table of Contents for today's video:
00:00 - Introduction
01:51 - No Interrupt Demo
07:02 - Hardware Interrupts
19:51 - Pin Change Interrupts
37:22 - Timer Interrupts
46:21 - Conclusion
Hopefully the video and its associated article will prove to be a good resource as you work to improve your code with interrupts.
😎
Bill
"Never trust a computer you can’t throw out a window." — Steve Wozniak
Great video and article, it's helped my understanding of interrupts. One thing confuses me - the Atmega328p datasheet has a clock bit selection table for Timer2 saying that you can have 128, 256 and 1024 prescalers. The table in the article does not have these. Is there a reason for the mismatch?
Bill,
Really enjoyed the video, which deals with several subjects many find tricky and fiddly. The three topics build very nicely one to the next but equally stand alone.
An excellent primer for anyone starting to get to grip with these subjects and techniques.
I would say that the most difficult topic to get heads around is Timer Interrupts. I came across a very useful resource some time ago I always use when configuring timer interrupts on Arduino which readers may find equally helpful.
The site can be found here.
Many thanks
Ron B
Ron Bentley
Creativity is an input to innovation and change is the output from innovation. Braden Kelley
A computer is a machine for constructing mappings from input to output. Michael Kirby
Through great input you get great output. RZA
Gauss is great but Euler rocks!!
Great and simple explanation about all Arduino interrupts types but I have two questions about timer interrupts sketch.
In setup and ISR functions TCNT1 value is set to timer1_compare_match. Timer1 works in normal mode so if I good understand it counts from 31249 to 65535 then overflow and start again from 0 to 250 (OCR1A vlue) then compare match interrupt occurs. That mean it's take 34536 ticks before interrupt occurs and based on equation from video interrupts frequency should be 1.8Hz
Is there any reason why in this sketch TCNT1 not OCR1A register is set to counted ticks value?
And second question: Why OCR1A is 250 when we don't set its value anywhere in sketch? ATmega's datasheets says all OCRnx bits are set to 0 by default.
If I misunderstand something please correct me.
Thanks
gorek