![]() |
interupts 3-6??
I am currently trying to develope some code for multiple encoders and I need to use interupts 3-6
I have some code from kevin watson's site and it works, but I don't know why How do you differentite between the interupt 3-6 even though it is the same register? thanx |
Re: interupts 3-6??
3-6 are interrupt-on-change, so they interrupt when anything on there changes. Kevin's code determines which pin changed by saving the old state of the port. You XOR the old port state with the current port state to see which bits have flipped and act accordingly. Then you save the current port state as the old port state (that you'll use the next time it interrupts).
|
Re: interupts 3-6??
so what you are saying is that INTCONbits.RBIF (RB Port Change Interrupt Flag bit) is actually a set of bits instead of just a single one?
or are you checking secondary bits to detrmine which pin is flagged after the RBIF is a 1? |
Re: interupts 3-6??
RBIF is a single bit that tells you that some bit in PORTB (the state of all the interrupt 3-6 pins) has flipped. You actually have to read PORTB before RBIF can be cleared. So now that you have the current value of PORTB, you compare it to the value of PORTB the last time something changed, and that tells you what's changed to cause this interrupt.
|
Re: interupts 3-6??
couldn't you just look at the specific pin to see if it is the pin that is activated?
such as Quote:
|
Re: interupts 3-6??
I think you have to read the entire port to be able to clear the flag, but reading a single pin might work. What happens is if you don't clear the mismatch by reading the entire port, or maybe reading one pin, is the flag continues to be set over and over, and you'll keep jumping back into your ISR. So if you try your way and get a red light of death, you'll know why.
Second point. Your method works if you only care about 0 to 1 transitions on the pin. 1 to 0 transitions will still cause interrupts and you'll still have to service them, however. So using interrupts 3-6 when you only care about 0 to 1 transitions is pretty wasteful of your resources and you'll only be able to service half as many interrupts as you'd other wise be able to. |
Re: interupts 3-6??
What if some other pin changed on the port and that pin was already high (it was high before and is continued to be high) that would give a false impression of that pin changing, right?
|
Re: interupts 3-6??
ummmm.. true. a good point. missed that one.
|
Re: interupts 3-6??
John, Kevin, Gustavo, et al,
Look at Kevin Watson's example here. Look at the way he uses the static variable "Old_Port_B" in user_rourtines_fast.c and you will begin to understand... Regards, Mike |
Re: interupts 3-6??
Quote:
-Kevin Code:
|
| All times are GMT -5. The time now is 04:13. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi