PDA

View Full Version : Measuring time



AugustoPedrone
- 30th July 2007, 15:21
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.

Jerson
- 30th July 2007, 15:59
<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.

mackrackit
- 30th July 2007, 17:52
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:)

Michael Wakileh
- 30th July 2007, 23:46
I found this site to be easier on the eyes...

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