|
Re: Ultrasonic sensors on digital ports 3-6 problems
Clearing and setting RBIE around critical regions of code is good practice. You are implementing mutual exclusion between the interrupt service context and normal context. But you should not have to do this in the ISR since all the interrupt sources result in the same ISR running.
Double check what clears the interrupts, reading the status registers can cause problems. I think 1-2 are edge triggered and have individual IE and IF bits. But remember that the RBIF and RBIE flags apply to all of port B thus to inputs 3, 4, 5 & 6 on the robot controller.
"Four of the PORTB pins (RB7:RB4) have an
interrupt-on-change feature. Only pins configured as
inputs can cause this interrupt to occur (i.e., any
RB7:RB4 pin configured as an output is excluded from
the interrupt-on-change comparison). The input pins (of
RB7:RB4) are compared with the old value latched on
the last read of PORTB. The “mismatch” outputs of
RB7:RB4 are ORed together to generate the RB Port
Change Interrupt with Flag bit, RBIF (INTCON<0>)."
This is the multiple read phenomena mentioned in this post. It is the difference between the last and current read of port B that creates the interrupt condition. So if you read port B anywhere you must process all possible bit changes at that time. So keep it simple, read port B in one place only (in the ISR) and process the changes for each bit just afterwards. If you need to know the state of port B, save the value in a variable for use in other places.
HTH
|