To do this I simply use a 1Hz 'tick' I already have in the code with a counter which increments each time the main loop runs, basically seeing how many times the loop runs per second.
I'm seeing something very unusual - when I enable the interrupt on change module this value drops by a factor of 6 or 7.
Delving deeper, the datasheet (PIC18LF26K22) states that to clear the interrupt I need to do the following:
My code is:Any read or write of PORTB to clear the mismatch condition (except when PORTB is the source or destination of a MOVFF instruction).
Execute at least one instruction after reading or writing PORTB, then clear the flag bit, RBIF.
Code: Select all
EncoderPos = EncoderPort
ProcessEncoder = true
RBIF = false
Code: Select all
?I001241_F000_000253_P000261 ; L#MK ENCODERPOS = ENCODERPORT
MOVFF PORTB,M2023_S08
?I001242_F000_000254_P000261 ; L#MK PROCESSENCODER = TRUE
MOVLB 8
BSF M2009_U01,2
?I001243_F000_000256_P000261 ; L#MK RBIF = FALSE
BCF INTCON,0,0
Also, I note that the IoC example in the Wiki doesn't follow the second point in the datasheet, clearing the flag immediately after reading the port. Is this one instruction wait something that only applies to certain processors? Is it worth updating the wiki to reflect this?
I should say that I don't know for sure that this is the cause of the massive increase in processor load, however what the loop is doing is not massively different between 'idle' and 'active' modes - it is basically just testing a series of flags - so I can't see any other reason for such a large change.