interrupts with threshold values

Using arduino pro mini: Is there a way to trigger an interrupt when a value returned by an analog function crosses above or below some threshold value. I use reflective IR sensors and wheels with encoding on the sidewall of the wheel to tell me now far it has turned. In this case I have found that the IR sensor output crossing a threshold of 500 indicates a change in the encoder value, so I count each time the sensor value crosses the 500 threshold value ether up or down. It works great, but that means I have to be in that routine to keep checking the value. It would be great if somehow I could trigger an interrupt every time that value returned by the IR sensor crossed that 500 threshold. Can anyone think of a way I could do this?

You could trigger interrupt at any pre-define voltage level using analog comparator. I' don't know why there is no arduino library function to communicate easily with Analog Comparator, so you have to dig into data sheet to set control registers properly.

Certainly more than I knew before. Thank you very much...now it's off to the atmega328 data sheet.

Triggering an interrupt at a value certainly interests me, particularly if it can be accomplished solely with the Arduino and perhaps one or two discrete components. Looking forward to replies. - Scotty

I think to use the internal comparator your limited to certain pins. You could also do this with a few simple external components to create a schmitt trigger Schmitt trigger - Wikipedia

Well, so far the search of the data sheet on the 328 has proven fruitless. There is very little mention of interrupts, and what there is does not seem to give me enough info to be able to do what I am trying to do.

I will look at the Schmitt trigger suggestion, but I am still pretty interested in keeping this within the capabilities of the mP.

Another alternative I am looking at using external components is to offload the whole process to an Attiny85 using I2C and the Servo8Bit library. This one is more or less just a "can I do it" option (as does the Schmitt trigger option).

There are lots of IC chips that are Schmitt triggers of some type (either banks of basic triggers or variations on the theme), using one of them could keep your external parts to a minimum.

Far-seeker:
There are lots of IC chips that are Schmitt triggers of some type (either banks of basic triggers or variations on the theme), using one of them could keep your external parts to a minimum.

74HC14s cost about a quarter each.

crchisholm:
Well, so far the search of the data sheet on the 328 has proven fruitless. There is very little mention of interrupts, and what there is does not seem to give me enough info to be able to do what I am trying to do.

There are 2 versions of the atmega328 datasheet, the short one and the full one. Make sure you have downloaded the full one, which is about 560 pages long. The analog comparator and associated interrupt is described on pages 248 to 251.

Taking a look at the analog comparator, the AIN1 is used as the TXD on the USART serial bus. Not entirely sure what would be required to use it as the interrupt analog comparator, but it may not be possible given how the serial is integrated to the Arduino boot loader. More obsessive combing of the 500 page data sheet would be required to get a definitive answer.

The analog comparator will do it.