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
Can Analogue value be used to trigger an interrupt?
Moderator: Benj
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Can Analogue value be used to trigger an interrupt?
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
daveb0360
- Posts: 139
- Joined: Mon Sep 21, 2009 10:17 am
- Location: Leicester
- Has thanked: 35 times
- Been thanked: 12 times
Re: Can Analogue value be used to trigger an interrupt?
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
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
-
Spanish_dude
- Posts: 594
- Joined: Thu Sep 17, 2009 7:52 am
- Location: Belgium
- Has thanked: 63 times
- Been thanked: 102 times
Re: Can Analogue value be used to trigger an interrupt?
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.
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.