PDA

View Full Version : Time window



Franko
- 9th August 2005, 01:18
Hi,
I've been programming Pics for a while now and mostly done somewhat basic
routines(although very useful to me). Anyway,I have been trying to write code to do the following...

Upon a pulse to a pin,activate a timer within the Pic (16F84A) that would allow another input to a different pin to activate the main code.

So, After the first input pulse you would have say 20 sec to press the button that would activate the code. After the 20 sec has timed out, pressing the button would do nothing until another input pulse starts the timer again.

I've tried variations of count,pulsein,for/next,searching here and can't get it.

Can someone please just point me in the right direction ?

Thanks,
Franko

JEC
- 9th August 2005, 01:27
I've done this sort of 'timeout' routine by sending the program into a tiny loop which monitors only the desired pins, after the main stimulus has been received.

Each time the miniloop executes, a counter is incremented.

If I receive an appropriate response (button, etc), I clear the counter and jump to the appropriate section of my code.

If the counter increments and reaches $BIGNUM, I exit the loop and go back to the main program.

John

yettie
- 9th August 2005, 01:37
franko,

consider yourself using a PIC16F628 since it has TIMER features. It will be a lot more easier since PIC16F84 have limited capabiliities. Another thing, it's a more cost efficient device for compared to other one.

in case you consider it, use can use particularly the TIMER1 feature of the device for it can count up to 1/100th (or better) of a second accuracy.

regards,
yettie

Melanie
- 9th August 2005, 01:41
PulseInput var PortB.0 ' Pin is HIGH with Pulse taking it LOW
ButtonInput var PortB.1 ' Pin is HIGH with Button Press taking it Low
LED var PortB.2 ' LED will Light when all Conditions Met

CounterA var Byte ' Just a variable to Count 20 Seconds

TRISB=%00000011 ' Setup Port I/O
LOW LED ' LED is OFF
Pause 500 ' Settling Timeout of 500mS
StartLoop:
While PulseInput=1:Wend ' Wait for Pulse Here
CounterA=0 ' Reset 20 seconds Counter
TimerLoop:
while ButtonInput=1 ' Loop waits for Button-Press
CounterA=CounterA+1 ' Increment Counter every 100mS
If CounterA=200 then StartLoop
' Redo from Start if 20 seconds elapsed
Pause 100 ' Kill 100mS
wend
MainCodeSuccess:
High LED ' Light LED
Pause 5000 ' for 5 Seconds
Low LED
Goto StartLoop ' And start over again

End

This is basically an example of what John/JEC first mentioned above. Enjoy.

Franko
- 9th August 2005, 01:59
Thank you all for your fast replies !

I have several 628s and will use them.

Melanie, That is extremely kind of you to do the code example,I appreciate it very much.

I have spent 2 days on this and now I can continue on.

Thanks again,
Franko

Melanie
- 9th August 2005, 07:46
Test it, Test it, Test it!

I wrote it off the top of my head, in five minutes at quarter to two in the morning at the end of a long day, so make sure it works, it makes sense and more importantly that you understand it before 'moving on'.

Franko
- 9th August 2005, 14:36
I will test it today and reply back. I read it over several times last night so as to understand all the steps and what they do.

As I test this one section alone, I will understand it even more.

Thanks

Franko
- 9th August 2005, 16:42
It works !

Melanie, I only had to make one change to get it to work...

While PulseInput=1:Wend
CounterA=0

I moved Wend to "after" CounterA=0...

While PulseInput=1
CounterA=0
Wend

Before I did that, LED would High anytime ButtonInput went Low.Now it only goes High during the "Time Window".
Works great and now I'll tweak it to suit my application and continue.

Thanks!!!