|
From: pito <pi...@vo...> - 2010-07-07 18:06:11
|
Hi dear friends, this is a small routine for generating 1 second with any value Xtal, using F_CPU only (no need for 32Khz external clock). Precision is subject to knowing the CPU Xtal frequency as precise as possible. Not optimised yet. Thanks Erich for tick_isr clarification. marker _zerodriftclock_ \ ZERO DRIFT CLOCK \ IT USES F_CPU ONLY (XTAL FREQUENCY SHALL BE KNOWN AS PRECISE AS POSSIBLE) \ IT WORKS WITH ANY VALUE XTAL ! \ SECONDS ARE INCREMENTED IN 1 SEC INTERVAL \ USES TIMER2 ATMEGA32 decimal 2variable ticker variable seconds 262144. 2constant clkpi ( clk per interrupt = 256*prescaler ) 1. ticker 2! 0 seconds ! \ overflow2 interupt service routine \ ! not optimised yet : tick_isr ticker 2@ clkpi d- ticker 2! ticker 2@ clkpi d< if f_cpu ticker 2@ d+ ticker 2! 1 seconds +! then ; hex \ enable ticks : +ticks 7 TCCR2 c! ( 00000111b = f_cpu clock/1024 ) 0 ASSR c! ( source: internal clock f_cpu) ['] tick_isr TIMER2_OVFAddr int! ( register interupt ) TIMSK c@ 40 or TIMSK c! ( enable timer2 interupt ) ; \ disable ticks : -ticks TIMSK c@ [ 40 invert ff and ] literal and TIMSK c! ( clr timer2 ) ; decimal : shwticker 1000 0 do cr ticker 2@ d. space seconds @ u. loop ; : shwsec seconds @ u. ; |