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