<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>Lothar Miller - Zeiten</title>
    <link>http://www.lothar-miller.de/s9y/</link>
    <description>Elektronik und Musik</description>
    <dc:language>de</dc:language>
    <generator>Serendipity 1.3.1 - http://www.s9y.org/</generator>
    <pubDate>Mon, 01 Dec 2008 16:02:26 GMT</pubDate>

    <image>
        <url>http://www.lothar-miller.de/s9y/templates/bulletproof/img/s9y_banner_small.png</url>
        <title>RSS: Lothar Miller - Zeiten - Elektronik und Musik</title>
        <link>http://www.lothar-miller.de/s9y/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>Timer+Zeiten</title>
    <link>http://www.lothar-miller.de/s9y/archives/26-Timer+Zeiten.html</link>
            <category>Zeiten</category>
    
    <comments>http://www.lothar-miller.de/s9y/archives/26-Timer+Zeiten.html#comments</comments>
    <wfw:comment>http://www.lothar-miller.de/s9y/wfwcomment.php?cid=26</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://www.lothar-miller.de/s9y/rss.php?version=2.0&amp;type=comments&amp;cid=26</wfw:commentRss>
    

    <author>nospam@example.com (Lothar Miller)</author>
    <content:encoded>
    
&lt;p&gt;Die Softwarestruktur eines uC-Programms sollte so aussehen, dass alle &amp;quot;üblichen&amp;quot; Arbeiten in einer Hauptschleife ausgeführt werden. Interrupt-Rotuinen setzen &amp;quot;nur&amp;quot; Flags oder verwalten FIFOs. &lt;/p&gt;&lt;p&gt;Zeiten können elegant über eine Struktur (ti) verwaltet werden, die eine Systemzeit (ti.Akt) und andere Aktionszeiten bzw. Triggerzeiten enthält. &lt;/p&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(85, 119, 153);&quot;&gt;#include&lt;/span&gt; &lt;span style=&quot;color: rgb(187, 68, 68); font-weight: bold;&quot;&gt;&amp;lt;avr/io.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(85, 119, 153);&quot;&gt;#include&lt;/span&gt; &lt;span style=&quot;color: rgb(187, 68, 68); font-weight: bold;&quot;&gt;&amp;lt;avr/interrupt.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(85, 119, 153);&quot;&gt;#include&lt;/span&gt; &lt;span style=&quot;color: rgb(187, 68, 68); font-weight: bold;&quot;&gt;&amp;lt;stdint.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;//...&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;volatile&lt;/span&gt; uint32_t gtiAkt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;typedef&lt;/span&gt; {&lt;br /&gt;  uint32_t Akt; &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// Systemzeit in ms&lt;/span&gt;  &lt;br /&gt;  uint32_t Start;&lt;br /&gt;  uint32_t Stop;&lt;br /&gt;  uint32_t Event;&lt;br /&gt;  &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// usw...&lt;/span&gt;&lt;br /&gt;} tiStruct;&lt;br /&gt;tiStruct ti;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// Timer-Compare Interrupt ISR, wird z.B. alle 10ms ausgefuehrt&lt;/span&gt;&lt;br /&gt;ISR(TIMER1_COMPA_vect)&lt;br /&gt;{&lt;br /&gt;&lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;//...&lt;/span&gt;&lt;br /&gt;   gtiAkt+=&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;10&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;//...&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;span style=&quot;color: rgb(51, 51, 153); font-weight: bold;&quot;&gt;int&lt;/span&gt; main(&lt;span style=&quot;color: rgb(51, 51, 153); font-weight: bold;&quot;&gt;void&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;&lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;//...&lt;/span&gt;&lt;br /&gt;   uint_32t *tiptr;&lt;br /&gt;   &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;//...&lt;/span&gt;&lt;br /&gt;   cli();           &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// Interupts deaktivieren&lt;/span&gt;&lt;br /&gt;   ti.Akt = gtiAkt; &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// Zeit atomar abholen&lt;/span&gt;&lt;br /&gt;   sei();           &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// Ints wieder aktivieren&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt;(ti.Akt&amp;amp;&lt;span style=&quot;color: rgb(0, 85, 136); font-weight: bold;&quot;&gt;0xC0000000&lt;/span&gt;) {      &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// Zeitstempel laufen an die Obergrenze&lt;/span&gt;&lt;br /&gt;       tiptr = (uint_32t*)(ti); &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// von jedem Zeitstempel Offset abziehen&lt;/span&gt;&lt;br /&gt;       &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;for&lt;/span&gt;(&lt;span style=&quot;color: rgb(51, 51, 153); font-weight: bold;&quot;&gt;char&lt;/span&gt; i=&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;; i&amp;lt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;sizeof&lt;/span&gt;(ti)/&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;sizeof&lt;/span&gt;(uint32_t); tiptr++)   &lt;br /&gt;          *tiptr-=&lt;span style=&quot;color: rgb(0, 85, 136); font-weight: bold;&quot;&gt;0x80000000&lt;/span&gt;;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// Start-Zeitpunkt erreicht&lt;/span&gt;&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt;(ti.Akt&amp;gt;ti.Start) {&lt;br /&gt;      run = &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;;&lt;br /&gt;      ti.Start = ti.Akt + &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;100000&lt;/span&gt;;&lt;br /&gt;      ti.Stop  = ti.Akt + &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1000&lt;/span&gt;;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// Stop-Zeitpunkt erreicht&lt;/span&gt;&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt;(ti.Akt&amp;gt;ti.Stop) {&lt;br /&gt;      run = &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;;&lt;br /&gt;      ti.Start = ti.Akt + &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;2000&lt;/span&gt;;&lt;br /&gt;      ti.Stop  = ti.Akt + &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;100000&lt;/span&gt;;&lt;br /&gt;   }&lt;br /&gt;   &lt;br /&gt;   &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// Zeit für Port-Pin low&lt;/span&gt;&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt; (PortPin)  ti.Event = ti.Akt;&lt;br /&gt;   lowtime = ti.Akt-ti.Event; &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// zählt hoch, solange Portpin low&lt;/span&gt;&lt;br /&gt; &lt;br /&gt;&lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;//...&lt;/span&gt;&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;Hier wird in einer Interruptroutine ein Millisekunden-Zähler hochgezählt und als Zeitbasis auf eine globale Struktur abgebildet. Auf diese systemweit einmalige Zeit werden dann alle lokalen Zeiten bezogen. Bei einem drohenden Überlauf wird von allen Zeiten in der ti-Struktur ein Offset abgezogen.&lt;/p&gt;&lt;p&gt;
&lt;/p&gt; 
    </content:encoded>

    <pubDate>Mon, 01 Dec 2008 10:43:52 +0100</pubDate>
    <guid isPermaLink="false">http://www.lothar-miller.de/s9y/archives/26-guid.html</guid>
    
</item>

</channel>
</rss>
