Page 1 of 1

Interrupt on change

PostPosted: Tue Aug 09, 2016 7:38 pm
by jtemples
I've been working with interrupt on change on the PIC16F1777. The data sheet says, "In order to ensure that no detected edge is lost while clearing flags, only AND operations masking out known changed bits should be performed." Does that mean there's actually special silicon related to the AND instruction that avoids the race condition when clearing flags? The data sheet doesn't say that explicitly, and in the general case, an AND isn't going to do anything special to avoid clearing flags that shouldn't be cleared.

Re: Interrupt on change

PostPosted: Wed Aug 10, 2016 3:49 am
by NorthGuy
I don't understand this. I always thought that all the operations are implemented as RMW, in which case it is absolutely impossible to clear other bits without any risk, but may be AND is different. It is possible to test.

Re: Interrupt on change

PostPosted: Wed Aug 10, 2016 4:27 am
by ric
Looking at Figure 13-1
The latches top left are reset on Q2 if the matching IOCAF bit is already set.

The IOCAFx latch only gets set on Q1 or Q4.
I would guess the AND operation is taking place on Q3, avoiding the race condition.

ioc.gif
ioc.gif (22.54 KiB) Viewed 5647 times

Re: Interrupt on change

PostPosted: Wed Aug 10, 2016 8:08 am
by jtemples
That makes sense, since Q3 is the "modify" cycle.

The example code for clearing is also a bit puzzling:

Code: Select all
MOVLW 0xFF
XORWF IOCAF, W
ANDWF IOCAF, F

Wouldn't COMF IOCAF, W accomplish the same function as the first two instructions?

Re: Interrupt on change

PostPosted: Wed Aug 10, 2016 2:41 pm
by ric
jtemples wrote:Wouldn't COMF IOCAF, W accomplish the same function as the first two instructions?

I think you're most likely right. :)

Re: Interrupt on change

PostPosted: Wed Aug 10, 2016 4:24 pm
by NorthGuy
If it works as ric described, then everything is taken care of in hardware, and it does make perfect sense. I don't see any reason why AND or any other particular instruction should be used. BCF should work just as well.