Measuring time


Closed Thread
Results 1 to 4 of 4

Thread: Measuring time

  1. #1
    Join Date
    Jul 2007
    Location
    Brazil
    Posts
    1

    Default Measuring time

    Hi, itīs my first topic. This forum solved many questions to me, just reading it ! Thanks a lot.

    Iīve got a problem...

    I want to measure the time between the second and the third press of a button. The first press is like a "preparing" to the measuring that ocurrs in then 2. and the 3. press.

    My basic code returns non-precise measured times, and I donīt know why.

    DEFINE OSC 4

    INPUT PORTB.0 ' input button
    OUTPUT PORTB.7 ' blinking-time led
    LED VAR PORTB.7 ' blinking-time led
    FLAGS = 0
    TEMPO VAR WORD ' time variable
    TEMPO = 500 ' value to start tempo
    A VAR WORD' variable that contains time measured

    INICIO: ' looks if the button was pressed or show the value of tempo
    ENABLE INTERRUPT : INTCON = %10010000
    ON INTERRUPT GOTO PAROU
    LCDOUT $FE,1,"TEMPO = ",#TEMPO

    LOOP1: ' blink the led
    TOGGLE LED
    PAUSE TEMPO/2
    TOGGLE LED
    PAUSE TEMPO/2
    GOTO LOOP1

    PAROU: ' prepare to measure the time
    DISABLE INTERRUPT : INTCON = $80
    LCDOUT $FE,1,"PREPARE"
    BOTAO VAR PORTB.0 ' transform the interrupt to button measure
    A=0
    PAUSE 200 ' cheap debouncing

    LOOPBOBO: ' debouncing for the first press to measure
    if botao=1 then LOO1
    GOTO LOOPBOBO

    LOO1: ' measure the time
    PAUSE 100 ' debouncing time (minimum measured)
    LOO:
    if botao=1 then fecha2
    pause 1
    if botao=1 then fecha2
    pause 1
    if botao=1 then fecha2
    pause 1
    if botao=1 then fecha2
    pause 1
    if botao=1 then fecha2
    pause 1
    if botao=1 then fecha2
    pause 1
    if botao=1 then fecha2
    pause 1
    if botao=1 then fecha2
    pause 1
    if botao=1 then fecha2
    pause 1
    if botao=1 then fecha2
    pause 1
    if botao=1 then fecha2
    A=A+1 ' increment time counter
    GOTO LOO

    fecha2:
    TEMPO = A*10 + 100 ' adjusts the time variable
    LCDOUT $FE,1,"OK"
    PAUSE 1000
    goto INICIO
    END


    Thanks if someone could help me.

    Augusto Pedrone.
    São Paulo - Brazil.
    Attached Files Attached Files

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    <B>From the manual</b>
    PBP will not enter the BASIC interrupt handler until it has finished
    executing the current statement. If the statement is a PAUSE or SERIN,
    it could be quite a while before the interrupt is acknowledged. The
    program must be designed with this latency in mind. If it is
    unacceptable and the interrupts must be handled more quickly, an
    assembly language interrupt routine must be used.
    This is just one of the reasons why.

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


    Did you find this post helpful? Yes | No

    Default

    You may want to take a look at this http://www.picbasic.co.uk/forum/showthread.php?t=3251
    I hear it is pretty good
    Dave
    Always wear safety glasses while programming.

  4. #4


    Did you find this post helpful? Yes | No

    Default

    I found this site to be easier on the eyes...

    http://darreltaylor.com/DT_INTS-14/blinky.html

Similar Threads

  1. need help for measuring two freq at same time
    By vu2iia in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd January 2009, 05:48
  2. I don't understand this code!
    By Russ Kincaid in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 13th February 2008, 03:55
  3. Serout2/serin2 Pbp Problem
    By SOMRU in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th December 2006, 20:55
  4. Time Measuring
    By peterson in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 20th May 2006, 18:22
  5. Timer in real time
    By martarse in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 29th July 2005, 15: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