Robert,
long time back I used these words for time measurements:

\ 2007-12-26 EW   w4_clock_tick.fs
\ 2010-09-02 PITO - FLOAT TIME MEASUREMENT ATMEGA 32
\        +timer    register and enable interupt
\        -timer    disable interupt
\ this is for mega32

marker -mytimer

\ TIMER_COUNTER_2
$42 constant ASSR       \ Asynchronous Status Register
$45 constant TCCR2      \ Timer/Counter2 Control Register
$00A  constant TIMER2_OVFAddr \ Timer/Counter2 Overflow
$59 constant TIMSK      \ Timer/Counter Interrupt Mask Register

2variable timer

\ overflow2 interupt service routine
\ increment tick
: tick_isr
1. timer 2@ d+ timer 2! ;

\ enable ticks
\ overflow:  f_cpu/256/64
: +timer
\  $7 TCCR2 c! ( 111b = f_cpu clock/1024 )
$4 TCCR2 c! ( 100b = f_cpu clock/64 )
$0 ASSR  c! ( source: internal clock f_cpu)
['] tick_isr TIMER2_OVFAddr int! ( register interrupt )
0. timer 2!
TIMSK c@  $40 or TIMSK c! ( enable timer2 interrupt ) ; 

\ disable ticks
: -timer
TIMSK c@ 
[ $40 invert $ff and ] literal and TIMSK c! ( clr timer2 interrupt )
;

\ MEASURE TIME IN SECONDS (FLOAT)
decimal
2variable elapsed_ticks
\ tck_ms = 1 / f_cpu / 256 / 64
f_cpu d>f 256 s>f f/ 64 s>f f/ 1 s>f fswap f/  fconstant tck_ms
: timer-start ( -- ) timer 2@ elapsed_ticks 2! ;
: timer-stop (  -- f ) timer 2@ d>f elapsed_ticks 2@ d>f f- tck_ms
f* ;

+timer

Regards,
Pito

----- PŮVODNÍ ZPRÁVA -----
Od: "Robert Epprecht" <eppre...@solnet.ch>
Komu: amforth-devel@lists.sourceforge.net
Předmět: [Amforth] measuring time
Datum: 15.1.2012 - 14:28:01

> Does amforth set up a timer to measure time or do
> I have to do that by
> hand? I need a word similar to arduino micros() to
> keep track of time.
> Has somebody already written that?
> 
> btw: What hw initialization (like timers, setting
> up i/o pins and the
> like) does amforth do, if any? 
> 
> Robert
> 
> 
> ------------------------------------------------------------------------------
> > RSA(R) Conference 2012
> Mar 27 - Feb 2
> Save $400 by Jan. 27
> Register now!
> http://p.sf.net/sfu/rsa-sfdev2dev2
> _______________________________________________
> Amforth-devel mailing list for
> http://amforth.sf.net/
> Amforth-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/amforth-devel
> 

-- 
- - Reklama - - - - - - - - - - - - - -
Lyže, snowboardy, monoski, sáňky, brusle, sněžnice a další kluzadla
oprášit, zimní radovánky jsou tu! Speciál Zima portálu VOLNÝ.cz
najdete na http://bit.ly/ymcefA


------------------------------------------------------------------------------
RSA(R) Conference 2012
Mar 27 - Feb 2
Save $400 by Jan. 27
Register now!
http://p.sf.net/sfu/rsa-sfdev2dev2
_______________________________________________
Amforth-devel mailing list for http://amforth.sf.net/
Amforth-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amforth-devel

Reply via email to