Tray and see if this works:
Al.Code:Wt: W0=0 While fin = 0 W0=W0+1 pause 1 If W0> 500 then goto TimeOut Wend
Tray and see if this works:
Al.Code:Wt: W0=0 While fin = 0 W0=W0+1 pause 1 If W0> 500 then goto TimeOut Wend
All progress began with an idea
If it is a very short Pulse (a few uS), you might miss it's arrival during the 1mS Pause statement.
If you can route your pulse into say RB0, then rather than polling the pin, you can poll the INTF bit (not knowing your PIC I'm using the registers from a 16F628 as an example). This bit will SET and stay SET when your pulse arrives. So if you blink and miss the pulse because you were doing something else, the Flag tells you it's happened.
Don't worry, the software doesn't actually need to vector to any Interrupt routine, once set up (eg INTEDG=1, INTE=1, GIE=0) you can just poll the INTF flag (rather than the pin) as per Al's example.
Don't forget, it's your job to reset the INTF flag ready for the next event.
That sounds perfect, since the pulse could be a short as 2 uS. I am using a PIC12F509 and if you could please give me an example for this one I will really apreciate it...
By the way, what I need is to toggle pin GPIO.2 from 1 to 0 when this pulse arives in GPIO.1 and this should be as fast as possible, since the actual 1 to 0 edge is used to measure distance.
Last edited by aherrera; - 28th November 2009 at 00:50.
Then really neither of the above replies are suitable.
This is because whilst you are away doing something, (for example the PAUSE instruction), you are not looking for the event in order to trigger your Output IMMEDIATELY. Even with my suggested modification, you won't miss the pulse, BUT you'll only do something about it some time later - and that time could be delayed by anything up to 1mS.
You would need something like Darrel's INSTANT INTERRUPTS - but NOT to Poll the input pin, but to give you your Timeout. If setting your Output pin relative to the Input trigger is so critical, then I would even consider if a PIC is the suitable device - you could do it quicker with discrete logic.
Bookmarks