Questions tagged [interrupt]

Interrupts allow the processor to suspend normal operation temporarily so that a high-priority software or hardware event can be handled instead.

For more information see the tag.

613 questions
22
votes
3 answers

Can a function be called automatically when an input changes?

Currently, my sketch is checking an input pin every time round the main loop. If it detects a change, it calls a custom function to respond to it. Here's the code (trimmed down to the essentials): int pinValue = LOW; void pinChanged() { …
Peter Bloomfield
  • 10,982
  • 9
  • 48
  • 87
21
votes
2 answers

How many interrupt pins can an Uno handle?

I am looking at using a 7 channel RC receiver with the Arduino Uno R3. In the documentation, there are mentions of a maximum of 2 interrupt pins, whereas on certain other blogs I have seen mentions of using upto 20 pins as interrupts, with…
asheeshr
  • 3,847
  • 3
  • 26
  • 61
18
votes
1 answer

How do interrupts work on the Arduino Uno and similar boards?

Please explain how interrupts work on the Arduino Uno and related boards using the ATmega328P processor. Boards such as the: Uno Mini Nano Pro Mini Lilypad In particular please discuss: What to use interrupts for How to write an Interrupt Service…
Nick Gammon
  • 38,901
  • 13
  • 69
  • 125
16
votes
2 answers

How precise can I get Arduino using rotary encoders?

Stepper motors are often pricey for a large motor. However, with a powerful, standard DC motor and a rotary encoder, you can "simulate" a stepper motor. How accurate are rotary encoders with Arduino just with a basic loop and not much other code? Is…
Anonymous Penguin
  • 6,365
  • 10
  • 34
  • 62
14
votes
4 answers

Using millis() and micros() inside an interrupt routine

The documentation for attachInterrupt() says: ... millis() relies on interrupts to count, so it will never increment inside an ISR. Since delay() requires interrupts to work, it will not work if called inside an ISR. micros() works initially, but…
Petr
  • 253
  • 1
  • 2
  • 12
11
votes
2 answers

Are function pointer assignments atomic in Arduino?

The following snippets are from TimerOne library source code: // TimerOne.h: void (*isrCallback)(); // TimerOne.cpp: ISR(TIMER1_OVF_vect) // interrupt service routine that wraps a user defined function supplied by attachInterrupt { …
Joonas Pulakka
  • 350
  • 2
  • 11
10
votes
1 answer

Counting pulses with interrupt

I have been trying to count pulses from a 12,500 Hz square wave to trigger an output. Here's the code I have so far. When the Arduino is reset it prints 315 to the serial over a 25 ms sample. 315 x 40 = 12600. Which seems to me it's working…
Brandon Whosville
  • 103
  • 1
  • 1
  • 5
9
votes
2 answers

How to update a variable in an ISR using Timers

I'm trying to check the frequency of Timer3 using a counter. The value of the counter, declared as volatile, is incremented in the ISR and every second the sum is shown in the main loop and the value reset to zero. The timer has been set up…
UserK
  • 559
  • 1
  • 11
  • 24
9
votes
1 answer

How to generate hardware interrupt in mpu6050 to wakeup arduino from SLEEP_MODE_PWR_DOWN mode?

I am using Arduino UNO and has kept in SLEEP_MODE_PWR_DOWN mode & want it to wakeup using MPU6050 hardware INT pin (which should send a signal when MPU is in motion). I have used the article…
bandejiya
  • 317
  • 1
  • 4
  • 12
9
votes
3 answers

Multiple independent LED patterns

I have an problem, which at first thoughts (and being new to Arduino) I though was a perfect application for an Arduino. However, after trying and failing to implement it I am doubting myself! Simply - I need to control many LEDs independently, many…
Nickos
  • 93
  • 1
  • 3
9
votes
2 answers

Why the need to use the volatile keyword on global variables when handling interrupts in Arduino?

I am familiar with the keyword Volatile being used to declare variables that are shared among multiple threads on a software application (basically on a multithreaded application). But why do I need to declare a variable as Volatile when running the…
T555
9
votes
1 answer

Is volatile needed when variable is accessed from > 1 ISRs, but not shared outside ISRs?

It's clearly documented that when global data is shared with an ISR and the main program, the data needs to be declared volatile in order to guarantee memory visibility (and that only suffices for 1-byte data; anything bigger needs special…
Joonas Pulakka
  • 350
  • 2
  • 11
8
votes
2 answers

When setting hardware timers as interrupts, should I prefer a lower prescaler value or a lower CTC?

I'm currently playing with Arduino's hardware timers, and a question came to my mind. Let me explain it a bit. Let's suppose I want a certain function to execute every 1024 clock ticks. AFAIK, I could achieve this in several ways, playing with the…
Nadia.moe
  • 203
  • 1
  • 5
7
votes
1 answer

Mic input and Speaker output using arduino

I am trying to make a small project. Firstly, I want to record voice using a small microphone(electret) for the time button is pressed and on releasing the button, the speaker of my laptop should output the recorded voice or a speaker attached to…
6
votes
1 answer

Is there a portable timer interrupt library?

I have a need for timer interrupt (for the sake of this exercise - say I need to execute something every second) I found code in many places on the internets that does this using ISR for 328/Uno. (or specifically for other chips) But of course that…
Tim
  • 131
  • 1
  • 1
  • 9
1
2 3
40 41