Hi,
I've never actually used the comparators but I'm looking at its section in the 18F25K22 datasheet and it says that the interrupt flag is set each time the output changes state - in other words you'll get an interrupt on rising and falling edge of comparator output.
However, as far as I can see, you need to read (or write) the CMxCON0 register in the ISR in order to clear the mismatch condition, much like you commonly need to do with the interrupt on change feature. It looks like you're not doing that.
You might want to actually read the output of the comparator in order to know - for sure - if you're over or under you threshold. The comparator output is available as bit6 in the CM1CON0 register (for comparator 1).
One way to "toggle" a bit is Above_Threshold = !Above_Threshold where the exclamation mark means "not".
/Henrik.




Bookmarks