Arduino Timer Interrupt Example
http://homediyelectronics.com/projects/arduino/arduinotimerinterruptexample/
Don't be afraid to use interrupts in your Arduino sketches. Interrupts enable you to do so much more with your Arduino that it's well worth taking the trouble to learn a few simple rules.
This video demonstrates the use of the timer 1 hardware timer of the Arduino Uno to provide precisely timed processing. Both simple interrupts and reentrant interrupts are covered to show the benefits of allowing your interrupt service routines to interrupt themselves.
Transcript:
If you think that using interrupts on your Arduino is too difficult then think again. In this video I'm going to show you how easy it can be to use interrupt service routines. Find full details of this reentrant interrupt example for the Arduino at http://homediyelectronics.com.
The Arduino Uno has 3 hardware timers that you can use to run tasks at precise intervals. If you call an interrupt service routine when the timer triggers you can achieve accurate timing irrespective of what the other code in your sketch or programme is doing.
I'm going to demonstrate the use of interrupts by using them to trigger 2 LEDs from within the service routine. LED D2 is toggled on each interrupt and LED D1 is toggled after a number of interrupts are counted.
When D1 is toggled the service routine executes a long task to demonstrate the effect that this has on the behaviour of your circuit.
Here's a pseudo-code version of the sketch I used. As you can see it is very simple and it isn't that different to the real code that I used.
This is what happens when you load and run the sketch on your Arduino. D2 flashes quickly when toggled by the interrupt. D1 flashes slower but notice that D2 pauses each time that D1 changes state. This is because the time consuming task takes longer than the time between the timer interrupts. Interrupts are disabled as soon as you go into an interrupt service routine. SO D2 has to wait.
If you want to schedule tasks to run at precise intervals then this isn't going to work because the long routine holds up the timing. So what if you could enable interrupts while the long routine is running and allow it to be interrupted by the fast interrupt?
Well you can. It's called a reentrant interrupt service routine and it's very easy to code. See the additions to the pseudo-code in red. All you have to do is enable interrupts while it is in the long routine and disable them again afterwards. Provided that the long task is not allowed to interrupt itself then all is well.
This is what happens when you make the interrupt service routine reentrant. Now the fast LED D2 is flashing at regular intervals without any pause. The long routine is no longer holding it up.
Get the full details of this Arduino reentrant interrupt at http://homediyelectronics.com.
There's lots of other stuff on the web site too. Go and have a look.
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Arduino Timer Interrupt Example», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.