<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Timer</title><link>https://sourceforge.net/p/flashforthforarduino/wiki/Timer/</link><description>Recent changes to Timer</description><atom:link href="https://sourceforge.net/p/flashforthforarduino/wiki/Timer/feed" rel="self"/><language>en</language><lastBuildDate>Sat, 17 Jan 2015 16:45:32 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/flashforthforarduino/wiki/Timer/feed" rel="self" type="application/rss+xml"/><item><title>Timer modified by Claus Kuehnel</title><link>https://sourceforge.net/p/flashforthforarduino/wiki/Timer/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v5
+++ v6
@@ -9,6 +9,8 @@
 When you recompile FF you can in the configuration file select the timer used for MS. It can be timer 0, 1 or 2.

 In the program sample *msecTimer.ff* I use Timer2 to generate a 10 ms output compare interrupt which increments a variable *count* each 10 ms.
+
+&amp;lt;http: sourceforge.net="" projects="" flashforthforarduino="" files="" msecTimer.ff=""&amp;gt;

 [[img src=msecTimer.png]]

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Claus Kuehnel</dc:creator><pubDate>Sat, 17 Jan 2015 16:45:32 -0000</pubDate><guid>https://sourceforge.net39be2b41b57c1cb78e3342527492948af3581da2</guid></item><item><title>Timer modified by Claus Kuehnel</title><link>https://sourceforge.net/p/flashforthforarduino/wiki/Timer/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Claus Kuehnel</dc:creator><pubDate>Sat, 17 Jan 2015 16:43:02 -0000</pubDate><guid>https://sourceforge.netcaad6eff24bfede8495b0743697ab7ff2038a69f</guid></item><item><title>Timer modified by Claus Kuehnel</title><link>https://sourceforge.net/p/flashforthforarduino/wiki/Timer/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Claus Kuehnel</dc:creator><pubDate>Sat, 17 Jan 2015 16:39:58 -0000</pubDate><guid>https://sourceforge.net9742a3bcb3b9320173a79742b4c43062fb0ea15e</guid></item><item><title>Timer modified by Claus Kuehnel</title><link>https://sourceforge.net/p/flashforthforarduino/wiki/Timer/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v2
+++ v3
@@ -9,6 +9,8 @@
 When you recompile FF you can in the configuration file select the timer used for MS. It can be timer 0, 1 or 2.

 In the program sample *msecTimer.ff* I use Timer2 to generate a 10 ms output compare interrupt which increments a variable *count* each 10 ms.
+
+[[img src=msecTimer.png]]

 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 \
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Claus Kuehnel</dc:creator><pubDate>Sat, 17 Jan 2015 16:36:17 -0000</pubDate><guid>https://sourceforge.net060fbab44ccba245480b7715529210d5b98fe513</guid></item><item><title>Timer modified by Claus Kuehnel</title><link>https://sourceforge.net/p/flashforthforarduino/wiki/Timer/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v1
+++ v2
@@ -8,4 +8,100 @@
 If you want to use Timer 1 you need to recompile FF without CPU load measurement.
 When you recompile FF you can in the configuration file select the timer used for MS. It can be timer 0, 1 or 2.

-In the program sample msecTimer.ff I use Timer2 to generate a 10 ms output compare interrupt which increments a variable count each 10 ms.
+In the program sample *msecTimer.ff* I use Timer2 to generate a 10 ms output compare interrupt which increments a variable *count* each 10 ms.
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+\
+\ Title        : msecTimer
+\ Author       : Claus Kuehnel
+\ Date     : 2015-01-17
+\ Id       : msecTimer.ff
+\ Version      : 5.0
+\
+\ DISCLAIMER:
+\ The author is in no way responsible for any problems or damage caused by
+\ using this code. Use at your own risk.
+\
+\ LICENSE:
+\ This code is distributed under the GNU Public License
+\ which can be found at http:\www.gnu.org/licenses/gpl.txt
+\
+\ Disable interrupt before removing the interrupt code
+T2_COMPA_Dis
+
+-msectimer
+marker -msectimer
+
+variable count
+
+\ Port Register Definitions
+$24 constant DDRB
+$25 constant PORTB
+#32 constant pLED
+
+\ Timer2 Register Definitions
+$b0 constant TCCR2A
+$b1 constant TCCR2B
+$b3 constant OCR2A
+$70 constant TIMSK2
+#8 constant OC2Aaddr \ interrupt vect no 8
+
+\ OCR2A Reload for 10 ms@16 MHz clock &amp;amp; prescaler 256
+$9c constant reload 
+
+: flash_led   ( -- )
+  PORTB c@ pLED xor PORTB c!
+;
+
+\ Interrupt routine for Timer1 CompareA
+: T2_COMPA_ISR
+    1 count +!
+;i
+
+: setup ( -- )
+    pLED DDRB mset    \ set pin as output
+    pLED PORTB mclr   \ LED off
+    
+    0 TCCR2B c!       \ Stop Timer2
+    reload OCR2A c!   \
+
+    0 count !
+    
+    ['] T2_COMPA_ISR OC2Aaddr int!
+  
+    %0010 TCCR2A c!   \ CTC Mode 
+    %0111 TCCR2B c!   \ Prescaler = 1024
+    %0010 TIMSK2 c!   \ Timer2 CompareA Interrupt enable
+    hex
+    cr ." OCR2A:  " OCR2A c@ 2 u.r   
+    cr ." TCCR2A: " TCCR2A c@ 2 u.r 
+    cr ." TCCR2B: " TCCR2B c@ 2 u.r 
+    cr ." TIMSK2: " TIMSK2 c@ 2 u.r 
+    cr ." Setup finished." cr
+    decimal
+;
+
+: T2_COMPA_Dis
+    1 TIMSK2 mclr
+;
+
+: main ( -- )
+    setup
+    begin
+        count @ #50 &amp;gt; 
+        if
+            ." ."
+            flash_led
+            0 count !
+        then
+    key? until
+;
+
+: test   ( -- )
+    0 count !
+    #1000 ms
+    count @ . ." counts in 1000ms" cr
+;
+decimal
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Claus Kuehnel</dc:creator><pubDate>Sat, 17 Jan 2015 16:32:43 -0000</pubDate><guid>https://sourceforge.net740bb6e425b78c2d7af1c3bde884b601ba83ef58</guid></item><item><title>Timer modified by Claus Kuehnel</title><link>https://sourceforge.net/p/flashforthforarduino/wiki/Timer/</link><description>&lt;div class="markdown_content"&gt;&lt;h1 id="timer"&gt;Timer&lt;/h1&gt;
&lt;p&gt;To realize exact timing Arduino has several timers which can be used with interrupts.&lt;/p&gt;
&lt;p&gt;Timer0 is used for ms. Timer1 is used for the CPU load measurement. Timer2 is free.&lt;/p&gt;
&lt;p&gt;If you want to use Timer 1 you need to recompile FF without CPU load measurement.&lt;br /&gt;
When you recompile FF you can in the configuration file select the timer used for MS. It can be timer 0, 1 or 2.&lt;/p&gt;
&lt;p&gt;In the program sample msecTimer.ff I use Timer2 to generate a 10 ms output compare interrupt which increments a variable count each 10 ms.&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Claus Kuehnel</dc:creator><pubDate>Sat, 17 Jan 2015 16:26:27 -0000</pubDate><guid>https://sourceforge.nete3293fd22a42428b4531eaed74d739a49539920c</guid></item></channel></rss>