PDA

View Full Version : Interrupt On Change - question



kevj
- 11th July 2008, 07:55
I'm playing with a 16F677 and have a question about interrupt on change.

I'd like the pic to set a flag in the background when the pin changes, but I don't want to re-direct the program execution at all whenever that pin change happens. I'm afraid of using interrupts because I'm not sure what to predict of them.

The data sheet says on pg. 62; 4.2.3 that the RABIF flag is set as soon as a mis-match happens. That's great, but is it going to interrupt the flow of my program? I don't want it to.

I'm allowing a pin to see a signal spike that may or may not happen over time. I want to just run around and do some other stuff with my program, and when a timer runs out (which my program will check on its own), I want to go manually look at this RABIF flag to see if it got set while I was doing other stuff; then I'll read from the pin to clear the mis-match then clear the flag, and repeat the whole process.

How do I handle this with the whole global interrupts thing? Anything special to code in picbasic?

Thanks!

Darrel Taylor
- 11th July 2008, 10:37
NOT a problem. And no interrupts required.

As long as the Global Interrupt Enable is 0 (INTCON.7=0), the program flow will NOT be redirected on a change to to the IOC pins.

The Interrupt flag (RABIF) will "Latch" on Any change, and the status will be available until the flag is cleared "Manually" in software. So you are free to "Poll" it at your leisure.

If the condition goes away before the program gets around to looking at it, you can't tell which of the pins actually changed. Which could be a problem in itself, but it sounds like you may not need to know that.
<br>

kevj
- 12th July 2008, 11:29
you can't tell which of the pins actually changed. Which could be a problem in itself, but it sounds like you may not need to know that.
<br>

Oooohhh.... okay, well that sounds easy enough. I thought I could turn the interrupt on change on and off for individual pins. Is that only change to other pins on the port, or any pin on the entire pic?

What if I have a pin set to an output and I'm driving it to do other stuff? That's the kind of "other" change that may happen while waiting for the input pin to trip. For example, I have 4 pins driving LED's as outputs, and my one pin set as an input is left to trip the flag?

You've got me pointed in the right direction at least. Thanks!

HenrikOlsson
- 12th July 2008, 12:30
Hi,
Only four pins on PortB have the interrupt on change capability and the interrupt is tripped when either one of those four changes state (if enabled). On the 16F677 you can enable/disable the interrupt on change feature for the four pins individually so if you only want one pin to trip the interrupt you simply enable the interrupt for that pin only. See section 4.4.2 in the datasheet for more info on how you do that.

Older PICs like the 16F877 doesn't allow you to enable the interrupt for indvidual pins like you obviously can on the 16F677 - nice feature.

HTH
/Henrik.

kevj
- 12th July 2008, 23:20
Outstanding. Thanks so much. That makes my job easy.