Timer - pause? ..?


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Jul 2007
    Posts
    48

    Default Timer - pause? ..?

    How do you make a code work like this:

    When I push a button a timer starts and when I push it again it stops and make that time into a variabel. So I can use that time in my program something like this:

    Code:
    ...
    ...
    HIGH PORTB.1
    PAUSE "The Time"
    LOW PORTB.1
    ...
    ...

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    How accurate do you need it and how long will the timer run at a time?

    If you need to do other things while the timer is running then an interrupt will be needed. Search the forum for timers.

    If you want something quick and dirty and nothing else will be happening when the time is collected this idea might work for you.

    When the button is pushed goto a time loop and stay there until the button is pushed again.
    While in that loop have a pause for a certain amount of time . Count to a variable each time (T=T+1) through the loop. When you are out of the loop read the variable.

    Say the pause is 100 ms and it goes through the loop 10 times. that would equal 1 second plus execution time.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

  4. #4
    Join Date
    Jul 2007
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    Both includes a LCD wich make it harder to understand the code :/

  5. #5
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    xobx, Just declare a word size variable and then pass it as the variable to the pause statement, like this:

    time var word 'time in milliseconds

    HIGH PORTB.1
    PAUSE time
    LOW PORTB.1

    Dave Purola,
    N8NTA

  6. #6


    Did you find this post helpful? Yes | No

    Default forgive my phone formatting.

    maybe something like this? (§ indicates new line) §loop: §button portb.0,1,255,0,but1,0,loop §gettime: §pause 100 §thetime = thetime + 1 §button portb.0,1,255,0,but1,0,gettime §flash: §for blink = 1 to thetime §high portb.1 §pause 100 §next blink §low portb.1 §goto loop

  7. #7


    Did you find this post helpful? Yes | No

    Default thetime var word

    max number of pauses will be 65535. so with pause 100 max time will be 6553.5 seconds or just under 110 mins. for longer times use a longer pause, for better accuracy use a smaller pause. it would also need a line in gettime to make sure it doesn't overflow.
    Last edited by nomad; - 3rd December 2007 at 12:43. Reason: oops

  8. #8


    Did you find this post helpful? Yes | No

    Thumbs up now that I'm home

    This will be more readable:
    Code:
    loop: 
    button portb.0,1,255,0,but1,0,loop
    
    gettime: 
    pause 100 
    thetime = thetime + 1 
    button portb.0,1,255,0,but1,0,gettime
    
    flash: 
    for blink = 1 to thetime 
    high portb.1 
    pause 100 
    next blink 
    low portb.1 
    goto loop

  9. #9
    Join Date
    Jul 2007
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    Ok but I doesnt understand this line :/

    button portb.0,1,255,0,but1,0,loop

  10. #10
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,810


    Did you find this post helpful? Yes | No

    Default

    PBP Pro manual, page 47.

    All parameters explained

    Ioannis

Similar Threads

  1. Delayed output 10 secs
    By lilimike in forum mel PIC BASIC Pro
    Replies: 37
    Last Post: - 14th October 2011, 06:28
  2. Old and beyond help ?
    By DavidFMarks in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 11th December 2008, 15:23
  3. Replies: 11
    Last Post: - 12th July 2008, 02:36
  4. Fade out LEDs question
    By Sam in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 22nd June 2008, 10:50
  5. Help Quick Need to make code smaller
    By Programmednew in forum mel PIC BASIC Pro
    Replies: 41
    Last Post: - 25th January 2005, 03:46

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