Interrupt if value bigger than a threshold

Hello,
I would like to know if it possible to set up the value to activate the interrupt function.
I know we can use RISING FALLING and so on but I receive a lot of data so I think my Arduino pin will stay up.
I want to set up the interrupt like this :
If the value I read on the pin if superior to my threshold I want to do something. I don't want to use the simple loop function because I need to measure the frequency so I need to measure the time between to value superior to my threshold.
Do you have an idea to proceed maybe I should use analog pin ?
Thank you

An interrupt pin can only have one of two values HIGH or LOW, 1 or 0. If you read the Atmel datasheet I'm sure it will explain exactly what voltage, between 0v and 5v, causes the transition.

Analog pins when used with analogRead() cannot do interrupts. And, compared to interrupts analogRead(0 is very slow.

...R

check opamp comparator - http://www.electronics-tutorials.ws/opamp/op-amp-comparator.html

place the IRQ at the Vout


img from above website

Delta_G:
There is an analog comparator on the chip and it can generate an interrupt.

Oops. I had forgotten about that. And I have recommended it in the past :o

...R

azfboom:
If the value I read on the pin if superior to my threshold I want to do something. I don't want to use the simple loop function because I need to measure the frequency so I need to measure the time between to value superior to my threshold.

Sorry, you clearly do not understand what an interrupt is!

That said, if you can simply forget about interrupts and explain your actual problem - in detail - we might be able to help you.

Thank you for you answers I will look for the amp op but my signal is already amplified that my problem. I am afraid that my pin state will stay HIGH.

@Paul__B : Ok, my problem is that I have a signal which came from a muscle sensor (Analogue signal rectified smooth and amplify) but I need to detect when the signal amplitude cross a threshold which can change from one time to another.
When the threshold is reach I calculate some data and the mean frequency. If I only use the loop function, my mean frequency will depend of the loop frequency and that not what I want.
I think analog comparator can be usefull.
BTW my signal come on a analogue input.

Does the "threshold which can change" depend on the Arduino setting the threshold in real time or is it a knob that you set external to the Arduino?

The onboard comparator can do the first job and it may also be useful to do the second. It's not used very often by Arduino people, so there's not a whole lot of experience out there to help you. It is one of the jobs that the chip was built specifically to do, so you are not asking a difficult question.

If it's only the second option, then yes, you need another opamp (preferably one optimised to be a comparator, but any opamp will do the job) then you can set up the threshold control on that.

For info on the built in analogue comparator see Nick Gammons excellent write-up here.

@MorganS : I set it at the begin of my code. I read value an my analog pin and use the average value.

I find an intressting library but I have difficulties to use it. http://www.leonardomiliani.com/en/2012/analogcomp-una-libreria-per-gestire-il-comparatore-analogico/

This line give me problem :
int pin = 8;
analogComparator.setOn([pin, AIN0]);

@Riva : Your link is exactly what I want to do but I don't know how to modify it for my purpose.
I don't get how could you specify which pin use for the comparison and how change the event (RISING) and how does it change the boolean value ?

Looking at Nick Gammon's example, it appears you can't change the pin. It only works on that pin.

For the instructions on how to set it for rising instead of falling, search the datasheet for the name of the register (ACSR) and read what it says.

Ah ok thank you. I will look at it.

azfboom:
Ok, my problem is that I have a signal which came from a muscle sensor (Analogue signal rectified smooth and amplify) but I need to detect when the signal amplitude cross a threshold which can change from one time to another.
When the threshold is reach I calculate some data and the mean frequency. If I only use the loop function, my mean frequency will depend of the loop frequency and that not what I want.

It seems you are still talking about interrupts, but not really knowing what you want to do and I very much doubt it has anything to do with interrupts.

You need to know - so you can explain to us - what you mean by "some data" and "mean frequency". What frequency are you talking about? It has nothing to do with any "loop frequency" you may imagine. You need to know what sort of "frequency" you expect. Please try again.

The analog comparator requires an external reference - or a fixed one - to operate. That means it has nothing to do with the ADC; you can use one thing or the other.

Maybe I do not express clearly but I understand than I will use analogue comparison and not interrupt.

I have a signal which one I want to store the period between two peak, I also want to store the value of the peak.

I use analogue comparison to know when the value I receive is superior to the threshold. To simulate the threshold I will use a analogue output from the arduino to send voltage on the A0 analogue input.

Here is a diagram of my program :

I don't see anything in that diagram that would require the use of an interrupt?
Just use analogRead() repeatedly and compare the result to the threshold.

The alternative is to use the Analog Comparator to trigger an interrupt when the voltage exceeds the threshold.

You have already been asked (and have not told us) what is the frequency of the signal you want to sample and how many samples per second are necessary?

...R

Yeah of thought of this but I was afraid that the frequency of the loop will be not short enough but after reading more about this I think it will still the best solution.
My signal has a range between 50Hz and 450Hz.
Thank for your help.

450 Hz is very slow for an Arduino.

...R