
saludos gente, estaba buscando realizar un odometro y velocimetro para una bicicleta .....
la idea es usar dos timers del ATMEGA16 uno como contador y otro como timer para contar los pulsos q entran al micro en un segundo trabajando con
el oscilador externo de 1MHZ
tanto la velocidad como la distancia deben mostrarse por un lc 2*16

encontre este codigo que parece q funciona segun el criterio, realice algunos cambios para mi caso .......
el problema esta que no se como asignar valor al preescaler para obtener 1 seg para q me genere las interrupciones y q me ayuden a depurar
posibles problema
cualquier ayuda mil gracias
' 1.8 meter x 3.14 (PI) = 5.652 meter per revolution
'5.652 / 32 = 0.176625 meter per pulse
'0.176625 x 60 (sec/min) x 60 (min/hour) = 635.85 meters per hour
'635.85 / 1000 = 0.63585 Km/hr/pulse
'or
'1 / 0.63585 = 1.5727 pulses/km/hr
'Hookup your pulse input to T1 (Timer1/Counter1 input)
'Hookup 32.768 KHZ xtal T2 source, no need for the dallas external clock
'Hookup LCD
'Program lines below:
'*************************************************************************
' r=0.32m 2*3.14*0.32 = 2 meter per revolution
'2 / 1 = 2 meter per pulse un pulso por revolucion
'2 x 60 (sec/min) x 60 (min/hour) = 7200 meters per hour para mi caso
'7200 / 1000 = 7.2 Km/hr/pulse
'or
'1 / 7.2 = 0.13888 pulses/km/hr
'************************************************************************
$regfile = "m16def.dat"
$crystal = 1000000
$baud = 9600
Dim Speed As Word
Dim Speed_$ As String * 5
Config Timer1 = Counter , Edge = Falling , Prescale = 1
Config Timer2 = Timer , Async = On , Prescale = 128 ' ------>cambiar preescaler para 1mhz
On Timer2 Timer2_isr
Enable Interrupts
Enable Timer2
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Portb.3 , Rs = Portb.2
'Main Program
Cursor Off Noblink
Cls
Do
Speed_$ = Str(speed)
Speed_$ = Format(speed_$ , " 0.0") 'There are two space between the double quote and the first zero
Locate 1 , 1
Lcd "Speed is " ; Speed_$ ; " Km/hr"
Dist_$ = Str(dist)
Dist_$ = Format(dist_$ , " 0.0")
Locate 1 , 1
Lcd "Dist is " ; Dist_$ ; " Km/hr"
Wait 1 'Do nothing for 1 second
Loop
End
'ISR
Timer2_isr:
Speed = Counter1
Counter1 = 0
Speed = Speed * 7.2
Return