From 67d25d837ac55f28a366c0a3b262e439a6e75fc3 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 19 Aug 2017 12:15:28 +0200 Subject: Add AmForth --- amforth-6.5/avr8/lib/hardware/timer2.frt | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 amforth-6.5/avr8/lib/hardware/timer2.frt (limited to 'amforth-6.5/avr8/lib/hardware/timer2.frt') diff --git a/amforth-6.5/avr8/lib/hardware/timer2.frt b/amforth-6.5/avr8/lib/hardware/timer2.frt new file mode 100644 index 0000000..ed0472f --- /dev/null +++ b/amforth-6.5/avr8/lib/hardware/timer2.frt @@ -0,0 +1,42 @@ +\ TIMER_2 example +\ uses an external 32kHz clock quartz +\ 32kHz / 256 => 128 ticks per second +\ 7.8125 ms per tick (gets approximated) +\ --> less accurate than the other timers, but... +\ +\ 16 ticks are 125ms +\ 125 = 15*8+5: 15x 8-tock and a short step +\ or 125 = 15*7+20:15x 7-tock and a huge step +\ -> we choose the 1st variant +\ provides +\ timer2.tick -- increasing ticker +\ + +variable timer2.tick +variable timer2.tock \ used internally + +: timer2.isr ( -- ) + timer2.tock @ 1+ 15 = if + 0 timer2.tock ! + 5 timer2.tick +! + else + 8 timer2.tick +! + 1 timer2.tock +! + then +; + +: timer2.init ( -- ) + 1 TCCR2 c! + 8 ASSR c! + ['] timer2.isr TIMER2_OVFAddr int! +; + +: timer2.start + 0 timer2.tick ! + 0 timer2.tock ! + TIMSK c@ $40 or TIMSK c! ( enable timer2 interupt ) +; + +: timer2.stop + TIMSK c@ [ $40 invert ] literal and TIMSK c! \ stop timer2 interrupt +; -- cgit v1.2.3