Edge Detection and Interrupts
RonW
Posts: 39
I need to detect transitions on RB7 and RB6.
I need to syncronize the RTCC to the falling edge of RB.7, so RB.7 transitions are set to cause an interrupt. The ISR clears the WKPND_B register.
RB.6 is a short input pulse, but response time is not critical, so RB.6 is checked in the main loop using:
Temp = 0
WKPND_B = Temp
IF Temp.6 = 1
PulseDetected = 1
ENDIF
Here's my question: Am I guaranteed that every falling edge on RB.7 will cause an interrupt and that the ISR will always see WKPND_B bit 7 set?
My concern is that if a transition occurs on RB.7 just before the main loop writes to WKPND_B, then WKPND_B bit 7 may be cleared before the interrupt is initiated. Not only does the interrupt need to occur, but the ISR needs to be able to read that WKPND_B bit 7 is set. If it works as I hope, the main loop woud never read a 1 in WKPND_B bit 7 as long as the interrupt is enabled.
Incidently, I realize that the ISR is also clearing WKPND_B bit 6 and I've handled that.
Thanks for your help.
RonW
I need to syncronize the RTCC to the falling edge of RB.7, so RB.7 transitions are set to cause an interrupt. The ISR clears the WKPND_B register.
RB.6 is a short input pulse, but response time is not critical, so RB.6 is checked in the main loop using:
Temp = 0
WKPND_B = Temp
IF Temp.6 = 1
PulseDetected = 1
ENDIF
Here's my question: Am I guaranteed that every falling edge on RB.7 will cause an interrupt and that the ISR will always see WKPND_B bit 7 set?
My concern is that if a transition occurs on RB.7 just before the main loop writes to WKPND_B, then WKPND_B bit 7 may be cleared before the interrupt is initiated. Not only does the interrupt need to occur, but the ISR needs to be able to read that WKPND_B bit 7 is set. If it works as I hope, the main loop woud never read a 1 in WKPND_B bit 7 as long as the interrupt is enabled.
Incidently, I realize that the ISR is also clearing WKPND_B bit 6 and I've handled that.
Thanks for your help.
RonW
Comments
It appears that you are attempting to synchronize the RTCC with an external device. Recently some code was share on how to do this without using the edge detect interrupt, I believe it was Peter (pjv) that shared it with us. I will look for it and post the link to the thread when I find it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
it started off as a discussion of matching resonators, when it became more clear what the aim was, Peter gave the algorithm on how to do it on the second page towards the top. Hope this helps.
Man I love the new search engine, just searched "forums.parallax.com pjv synchronize" and bam the very first hit .
Oh and he has master and slave code in his last post.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 11/11/2005 7:51:47 PM GMT
Thanks for the help. I'm not actually using async and sync interrupts at the same time. Once I've sync'ed with the edge, I turn the edge interrupt off and turn the RTCC interrupt on. When the input goes idle, I switch back to edge detection to sync with the next incoming pulse train. This is working fine.
Thanks for the reference to the other thread. Since I don't have any control over the input, I can't implement that syncronizing scheme in this project, but it's good information. My rates are slow enough that I could use periodic polling if necessary.
There are other ways to accomplish what I need, but if I could count on not missing an interrupt, this solution is very simple.
Thanks,
RonW
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10