From: Robert L. <xu...@xu...> - 2009-12-17 00:08:03
|
Thanks so much for your quick response to my question. This is exactly what I was looking for. I've checked out the latest source from the Subversion repository and will take some time to read the rest of the ewlib code. Thanks again! Robert AK6L On Wed, Dec 16, 2009 at 12:45 PM, Erich Waelde <ew....@na...> wrote: > Hi and welcome! > > Robert Liesenfeld wrote: > > I'm just beginning to use amforth for some of my ATmega-based projects, > and > > I have a need for a timer ISR. Ideally I'd like this to be in Forth > rather > > than AVR assembly, mostly because I'm not very good at assembly. > Basically > > all I want to do is keep track of the number of milliseconds since > "boot", > > for interval tracking purposes. The technical documentation for amforth > > makes it sound like this is possible in a native Forth word, but doesn't > go > > into detail, or if it does, I missed it. > > I'm using timer2 driven by a 32768 Hz quarz to generate a timebase. No > assembly > involved, because there is no need to clear a bit to acknowledge the > interrupt. > > > > --- begin clock_tick.fs --------------------------------- > \ 2007-12-26 EW clock_tick.fs > \ geklaut aus appl/tv/blocks/realtimeclock.frt > \ words: timer2 variable > \ tick_isr interupt service routine: increments timer2 > \ +ticks register and enable interupt > \ -ticks disable interupt > > variable timer2 > > hex > \ overflow2 interupt service routine > \ increment tick > : tick_isr > 1 timer2 +! > ; > > \ enable ticks > \ crystal: 32768 /sec > \ clock src: 32768 /sec > \ overflow: 32768/256 = 128 /sec =^= 7.8125 milli-sec ticks > : +ticks > 1 TCCR2 c! ( 001 = clock_ts2/1 ) > 8 ASSR c! ( source: 32 kiHz crystal ) > ['] 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 Timer 2 ) > ; > ----------------------------------------------------------------- > > > > +ticks > makes the "clock" run > > > timer2 @ u. > DA6 ok > > timer2 @ u. > 10DA ok > > -ticks > ok > > timer2 @ u. > 129F ok > > timer2 @ u. > 129F ok > > and -tick stop it. Use the content of variable timer2 to keep track of the > time. > You must read this variable regularly and count up other counters to avoid > untracked overflow of timer2. > > Have a look at amforth/applications/ewlib/timeup.frt for using this. > > > Cheers, > Erich > > > ------------------------------------------------------------------------------ > This SF.Net email is sponsored by the Verizon Developer Community > Take advantage of Verizon's best-in-class app development support > A streamlined, 14 day to market process makes app distribution fast and > easy > Join now and get one step closer to millions of Verizon customers > http://p.sf.net/sfu/verizon-dev2dev > _______________________________________________ > Amforth-devel mailing list > Amf...@li... > https://lists.sourceforge.net/lists/listinfo/amforth-devel > |