using interrupt only inside a function

Hi there!
I'm starting to put together a Nano_v3 with a BTS7960 DC motor controller and an IR emitter and receiver for RPM count, and many other sensors not related to my question...
at this point I think I got the principles of how to measure RPM's attaching the IR receiver to an interrupt, however, the IR sensor is constantly being excited by the reflecting mark on my spinning "wheel" meaning that my MCU ins constantly being "interrupted" and * I only want to measure the RPM's on demand * i.e. when a button is pushed.

What would you recommend for this?
the options, the way I see things:
a) leaving the interrupt and "turning off" the IR emitter (1 extra pin needed)
b) using some kind of noInterrupts()/interrupts() // attachInterrupt()/detachInterrupt() (I read it might affect time sensitive operations....)
c) live with it, arduino being constantly interrupted
d) measure RPM without interrupts "polling" the IRreceiver pin on demand (not the best for RPM measure since it might loose the count... but read bellow)

A detail I forgot to mention, I should be measuring RPM's between 10 and 100 RPM

So, I wonder, what would be the most adapted/elegant/clean solution fro my application?

thank for your answers!

I should be measuring RPM's between 10 and 100 RPM

10 rpm is 0.166 Hz.
100 rpm is 1.66Hz.

These are not processor-troubling frequencies.

I'd say a and b or c

a because it's good from a power consumption perspective to not power stuff you don't need, esp. if this is powered from battery

b with attachInterrupt() and then remove it - don't stop the interrupt system.

or c because as AWOL states, interrupting your processor 1,66 times per second - assuming you just do an addition to a volatile counter in the ISR then you probably loose 0,0005% of your raw processing power...

AWOL:
10 rpm is 0.166 Hz.
100 rpm is 1.66Hz.

These are not processor-troubling frequencies.

In case the implication isn't clear, AWOL is recommending D.

I do as well. 100 RPM is less that 2 rotations per second. 600 ms between events is an eternity for a microcontroller.

Use option D if reading the other sensors, of which you have given no details, do not block the execution of the loop() function.

AWOL:
10 rpm is 0.166 Hz.
100 rpm is 1.66Hz.

But how do we know that the hardware does not generate e.g. 60 interrupts per rotation (e.g. 60 holes in a disc)?

sterretje:
But how do we know that the hardware does not generate e.g. 60 interrupts per rotation (e.g. 60 holes in a disc)?

10 Hz and 100Hz are not processor-troubling frequencies either.

I think if this was my project I would allow the interrupts to happen and just ignore them - unless it is clear that they are interfering with the performance of something else.

Make sure that the ISR is very short - maybe just

void myISR() {
   irCount ++;
}

...R

Good points everybody! Thank you all for your answers...
Some points about your answers:

  • I plan to get only one event per rotation (I say "plan")
  • the ISR, if used, will be short... like 2 lines short. Probably just a rev++ as robin2 said
  • I guess there is no good answer / all the answers are good enough to worth the trying.
  • the other sensors are a temperature sensor, and current measurement module... and maybe a limit sensor (end of course). The target is to have a read those sensors, if the values are over the limits it will shut down the whole thing through a relay and turn on a buzzer. Plus every ten seconds an log entry will be created (I don't plan to log rpm, I just want them there to set the speed), I'm planning in a first time to log with a pc and coolterm, later on it might be done in a SD card.
  • the whole thing is kind of a rock tumbler and I want to monitor it, and get sone security since the working cycles are of about 24h.
  • I guess I'll try a) with probably b). Is there any problem/drawbacks of attaching and deattaching interrupts?

Is there any problem/drawbacks of attaching and deattaching interrupts?

no. blocking all interrupts can be a pb.

given what you want to do i'd say you don't need interrupts at all. your loop will run fast enough to capture info. Just ensure your temperature reading is not blocking some sensors are pretty slow.