PDA

View Full Version : Overlook a short pulse???



Sam
- 22nd March 2004, 02:00
Hi,

I've been trying to figure out the correct code to overlook a short pulse (~50ms) and only activate the program when it senses a longer pulse (500 ms).

It doesn't look like Pulsin will work. I've tried the following in various forms:

If PortB.1=1>500 then
High PortB.2
Endif

This may be completely wrong,but I had to try and it does compile without errors.

I haven't figured out "count" yet,I thought some version of that might work.

If someone could just "steer" me in the right direction,I think I could get it. Still learning.

Thanks

Melanie
- 22nd March 2004, 11:02
Pulsin should work, but you need to specify if your pulse is a high or a low... let's it's assume it's a positive-going 'High'. Pulsin measures in 10uS increments (at 4MHz PIC clock), and we'll set our threshold at 450mS (that's a count of 45,000 ticks at 10us)

PulsePin var PortB.2
PulseData var WORD

PulseLoop:
Pulsin PulsePin,1,PulseData
If PulseData<45000 then goto Pulseloop

If your code is trapped in the loop then you have either a Pulse that's too short, or greater than 655.35mS (WORD limit for Pulsin). So you can see that Pulsin will give you a 'window' to work within. It won't catch very long pulses that exceed it's max limit.

Now let's rehash this giving us an unlimited upper Pulse width window...

PulseLoop:
PulseData=0 ' zero count
While PulsePin=0:Wend ' wait here for a pulse to start
While PulsePin=1 ' Loop here counting Pulse Length in 1mS steps
Pause 1
PulseData=PulseData+1
If PulseData>450 then goto GotLongPulse
Wend
Goto PulseLoop

Now, in this example, if your Pulse LOW is less than 1mS you may not catch the start of the next pulse if it follows on too fast, so just change Pause1 to PauseUS 100 and increase >450 to >4500 and you now have a 100uS count window. And pro rata etc etc...

Melanie

Sam
- 22nd March 2004, 19:50
Melanie,

Thanks much for your reply. It is a positive-going 'High' with alot of low time between the high pulses. I will do as you state and repost.

Again, much thanks as I didn't know what else to try.

Best regards