Time window


Closed Thread
Results 1 to 8 of 8

Thread: Time window

Hybrid View

  1. #1
    Franko's Avatar
    Franko Guest

    Default Time window

    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
    Last edited by Franko; - 9th August 2005 at 01:22.

  2. #2
    Join Date
    Nov 2004
    Posts
    61


    Did you find this post helpful? Yes | No

    Default

    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

  3. #3
    Join Date
    Aug 2005
    Location
    antipolo city, philippines
    Posts
    23


    Did you find this post helpful? Yes | No

    Default consider PIC16f628

    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

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Code:
    	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.

  5. #5
    Franko's Avatar
    Franko Guest


    Did you find this post helpful? Yes | No

    Default

    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

  6. #6
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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'.

Similar Threads

  1. I don't understand this code!
    By Russ Kincaid in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 13th February 2008, 02:55
  2. Measuring time
    By AugustoPedrone in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 30th July 2007, 23:46
  3. Serout2/serin2 Pbp Problem
    By SOMRU in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th December 2006, 19:55
  4. Alarm Time
    By Santana in forum Code Examples
    Replies: 1
    Last Post: - 8th December 2006, 13:58
  5. Timer in real time
    By martarse in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 29th July 2005, 14:24

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts