PDA

View Full Version : A/D interrupt



starwick
- 21st May 2011, 08:11
Hi,
can you trigger the interrupt using the analog input?
My project is analog input from a keypad, which is working perfect now but instead of having the software sitting there and reading the the analog input can i use interrupt instead? the AN0 input is 0 unless a key is pressed.I know you gonna ask for the code BUT I THINK this one is easy soo.. i'll ask the question as simple as this: can i use interrupt so the pic is doing something else when the A/D input = 0 ELSE goto interrupt routine?
Many thanks for any help or suggestions.

Best regards,
Joe

HenrikOlsson
- 21st May 2011, 08:46
No, you can't do that as far as I know. On the other hand, most chips with an ADC also have a comparator module which output CAN trip an interrupt. If the chip you're using got one then simply connect the analog signal to the ADC input and to the comparator input and set up a suitable trip level on the "other" comparator input - should do it.

Or, short of an on board comparator, use an external one and wire its output to RB0 - for example.

HankMcSpank
- 21st May 2011, 09:47
Hi,
the AN0 input is 0 unless a key is pressed

If that's the case then why not generate an interrupt when the key (switch?) is pressed & then do an ADC in your interrupt routine.

starwick
- 21st May 2011, 18:59
Thanks for the replay.

HenrikOlsson,
That's what i was think excatelly, but it didn't hurt to ask.

HankMcSpank,
When a key is pressed AN0 go from 0-5v depend on the key pressed(ie; if 0 is pressed 0<AN0<.5V, if 1 is pressed .6<AN0<1.0V......).

Thank you,
Any other ideas or suggestions are appreciated.

HankMcSpank
- 21st May 2011, 19:29
Thanks for the replay.

HenrikOlsson,
That's what i was think excatelly, but it didn't hurt to ask.

HankMcSpank,
When a key is pressed AN0 go from 0-5v depend on the key pressed(ie; if 0 is pressed 0<AN0<.5V, if 1 is pressed .6<AN0<1.0V......).



Oh, now I see.

Then what Henrik said....set a comparator to 'trip' (toggle) at anything higher than 0.4V... use that 'toggling' level to generate a comparator interrupt......do your ADC inside the comparator interrupt routine.

Which PIC are you using? You can likely use the PIC's own internal comparator & DT's CMP_int interrupt....

(http://darreltaylor.com/DT_INTS-14/intro.html )