Measuring time


Results 1 to 4 of 4

Thread: Measuring time

Threaded View

  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

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, 04:48
  2. I don't understand this code!
    By Russ Kincaid in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 13th February 2008, 02:55
  3. Serout2/serin2 Pbp Problem
    By SOMRU in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th December 2006, 19:55
  4. Time Measuring
    By peterson in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 20th May 2006, 17:22
  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 : 0

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