Page 1 of 1

Can Analogue value be used to trigger an interrupt?

Posted: Wed Aug 10, 2011 2:36 pm
by daveb0360
Hi,
Just curiosity as I am trying to learn how to use iterrupts for a small project. (Using 16F876 on internal oscillator at 4Mhz)

I need to know if an analogue value into ADC can be used to trigger an interrupt. For example, a mid rail voltage that falls below or above a threshold whilst executing other parts of a program, calls an iterrupt to perform a variable update or something like this.

Is there a way of doing this.

Thanks
Dave

Re: Can Analogue value be used to trigger an interrupt?

Posted: Wed Aug 10, 2011 3:25 pm
by Benj
Hi Dave,

Most PIC microcontrollers with analogue inputs have a comparator peripheral which does the job you have detailed. Flowcode does not support comparators directly though this is planned for the future but you can use C code embedded in a custom interrupt to setup the comparator module. There should be examples on the forum of how to do this but if your struggling then we should be able to help.

Re: Can Analogue value be used to trigger an interrupt?

Posted: Wed Aug 10, 2011 3:35 pm
by daveb0360
Thanks Ben,
I have NO knowledge of C so will be trawling the forum for input.

Hopefully I will find something I can decipher but will probably come back for direct advice &or examples once I establish that this is truly a way to go as I suspect it is.
My circuit will need to react to this analogue level immediately and regardless of anything else it is doing so interrupt / comparator would seem the way to do this.

Thanks

Dave

Re: Can Analogue value be used to trigger an interrupt?

Posted: Sat Aug 13, 2011 8:26 pm
by Spanish_dude
Hi,

An alternative to this would be using a Timer interrupt where you would check the value of the ADC using if statements.
Once the condition is "true", do something, else go back to main loop.

Seems pretty easy to do.

BR,

Nicolas L. F.