<?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 - Software</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>Wed, 20 Apr 2011 06:44:02 GMT</pubDate>

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

<item>
    <title>Drehgeberauswertung mit Beschleunigung</title>
    <link>http://www.lothar-miller.de/s9y/archives/71-Drehgeberauswertung-mit-Beschleunigung.html</link>
            <category>Encoder</category>
    
    <comments>http://www.lothar-miller.de/s9y/archives/71-Drehgeberauswertung-mit-Beschleunigung.html#comments</comments>
    <wfw:comment>http://www.lothar-miller.de/s9y/wfwcomment.php?cid=71</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=71</wfw:commentRss>
    

    <author>nospam@example.com (Lothar Miller)</author>
    <content:encoded>
    
&lt;p&gt;Hier eine &lt;b&gt;Drehgeberauswertung&lt;/b&gt;, die auf der Basis von Peter Danneggers Code (auf &lt;a title=&quot;mikrocontroller.net&quot; target=&quot;_blank&quot; href=&quot;http://www.mikrocontroller.net/topic/112603&quot;&gt;www.mikrocontroller.net&lt;/a&gt;) zusätzlich eine &lt;b&gt;dynamische Beschleunigung&lt;/b&gt; realisiert. Je schneller am Knopf gedreht wird, umso schneller ändert sich der Wert. Das ergibt ein gutes haptisches Gefühl, und man kann größere Bereiche einstellen, ohne dass umgegriffen werden muß.&lt;/p&gt;&lt;hr width=&quot;100%&quot; size=&quot;2&quot; /&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(0, 136, 136); font-weight: bold;&quot;&gt;volatile&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;int16_t&lt;/span&gt; enc_pos;&lt;br /&gt;&lt;span style=&quot;color: rgb(85, 119, 153);&quot;&gt;#define&lt;/span&gt; PHASE_A  (PINA &amp;amp; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;&amp;lt;&amp;lt;PA1)   &lt;br /&gt;&lt;span style=&quot;color: rgb(85, 119, 153);&quot;&gt;#define&lt;/span&gt; PHASE_B  (PINA &amp;amp; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;&amp;lt;&amp;lt;PA2)&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// ISR wird z.B. &lt;b&gt;jede ms&lt;/b&gt; aufgerufen&lt;/span&gt;&lt;br /&gt;ISR(SIG_OUTPUT_COMPARE1A)&lt;br /&gt;{&lt;br /&gt;&lt;span style=&quot;color: rgb(85, 119, 153);&quot;&gt;    #define&lt;/span&gt; DYNAMIK &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;40&lt;/span&gt;  &lt;br /&gt;    &lt;span style=&quot;color: rgb(0, 136, 136); font-weight: bold;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;uint8_t&lt;/span&gt; enc_ab = &lt;span style=&quot;color: rgb(0, 85, 136); font-weight: bold;&quot;&gt;0x01&lt;/span&gt;; &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;  // Encoderzustand 0..3 &lt;/span&gt;    &lt;br /&gt;    &lt;span style=&quot;color: rgb(0, 136, 136); font-weight: bold;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;uint8_t&lt;/span&gt; enc_accel = &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;;   &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// speichert die aktuelle Beschleunigung&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;int16_t&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;&lt;/span&gt;   p;                    &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// (position) lokale Variable für Positionsberechnung&lt;/span&gt;    &lt;br /&gt;    &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;int8_t&lt;/span&gt;    m = &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;;                &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// (moved) lokale Variable für Bewegungsberechnung&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;( enc_accel&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;&lt;/span&gt; ) enc_accel--;    &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// solange &amp;gt;0: pro ms um 1 &amp;quot;entschleunigen&amp;quot; &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;( PHASE_A ) m = &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;;            &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// Gray nach binär wandeln&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(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt;( PHASE_B ) m ^= &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;3&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;    m -= enc_ab;                     &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// berechnen, ob sich der Encoder bewegt hat&lt;/span&gt;&lt;br /&gt;                                     &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// gültige Werte für Differenz (m): -1, 0, +1 &lt;/span&gt;&lt;br /&gt;                                     &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// sonst ist die Abtastfrequenz zu niedrig!&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;( moved ) {                    &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// Positionsänderung am Encoder?&lt;/span&gt;&lt;br /&gt;        enc_ab += m;                &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt; // Encoderzustand speichern&lt;/span&gt;&lt;br /&gt;        p = enc_pos;                 &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// nicht auf globaler Variable (enc_pos) herumrechnen&lt;/span&gt;        &lt;br /&gt;        &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt; (enc_accel&amp;lt;&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;255&lt;/span&gt;-DYNAMIK)   &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// neuen Beschleunigungswert berechnen:&lt;/span&gt;            &lt;br /&gt;            enc_accel += DYNAMIK;    &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// solange &amp;lt;255 Beschleunigungswert aufaddieren&lt;/span&gt;&lt;br /&gt;        &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;else&lt;/span&gt;                         &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// sonst&lt;/span&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;span style=&quot;color: rgb(136, 136, 136);&quot;&gt; &lt;/span&gt;            &lt;br /&gt;            enc_accel = &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;255&lt;/span&gt;;         &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// auf 255 begrenzen&lt;/span&gt;  &lt;br /&gt;        &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt; (i&amp;amp;&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;2&lt;/span&gt;)                     &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// Bit 1 = Vorzeichen = Richtung (+/-)&lt;/span&gt;            &lt;br /&gt;            p += &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;+(enc_accel&amp;gt;&amp;gt;&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;6&lt;/span&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;// Erst Beschleunigungswerte &amp;gt;64 (wegen &amp;gt;&amp;gt;6)  &lt;/span&gt;        &lt;br /&gt;        &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;else&lt;/span&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;werden &lt;/span&gt;&lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;berücksichtigt. &lt;/span&gt;            &lt;br /&gt;            p -= &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;+(enc_accel&amp;gt;&amp;gt;&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;6&lt;/span&gt;); &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;  // Diese Division (Shift 6) evtl. anpassen...&lt;/span&gt;        &lt;br /&gt;        enc_pos = p;                 &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// lokale Variable auf globale Variable zurückkopieren&lt;br /&gt; &lt;/span&gt;    }&lt;br /&gt;    :&lt;br /&gt;    &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// ab hier kommt sonstiger Code im Timerinterrupt&lt;/span&gt;   &lt;br /&gt;}&lt;/pre&gt;&lt;hr width=&quot;100%&quot; size=&quot;2&quot; /&gt;&lt;p&gt; Im Beispiel sind die beiden Spuren an den Portpins 1 und 2 vom Port A angeschlossen. Mit dem &lt;b&gt;&lt;i&gt;#define DYNAMIK&lt;/i&gt;&lt;/b&gt; lässt sich der &amp;quot;Biss&amp;quot;, also die Beschleunigung einstellen. Leider funktioniert das z.B. mit den billigen Pollin-Encodern nur eingeschränkt, weil die pro Raste zwei Schritte machen. Also ist da etwas Spielen und Ausprobieren mit dem Wert angesagt. Ich habe noch jedesmal einen brauchbaren Wert gefunden. Mit einem &lt;b&gt;&lt;i&gt;uint16_t&lt;/i&gt;&lt;/b&gt; für &lt;b&gt;&lt;i&gt;enc_accel&lt;/i&gt;&lt;/b&gt; kann der Dynamikbereich wesentlich ausgeweitet werden.&lt;br /&gt;&lt;br /&gt;Die Umwandlung vom Gray- in den Binärcode erfolgt mit dem XOR Verfahren wie auf &lt;a title=&quot;Umwandlung Graycode&quot; href=&quot;http://www.lothar-miller.de/s9y/categories/53-Graycode&quot;&gt;Software/Graycode&lt;/a&gt; im letzten Beispiel beschrieben.&lt;/p&gt;


 
    </content:encoded>

    <pubDate>Fri, 12 Mar 2010 12:56:02 +0100</pubDate>
    <guid isPermaLink="false">http://www.lothar-miller.de/s9y/archives/71-guid.html</guid>
    
</item>
<item>
    <title>Graycode Umwandlung</title>
    <link>http://www.lothar-miller.de/s9y/archives/69-Graycode-Umwandlung.html</link>
            <category>Graycode</category>
    
    <comments>http://www.lothar-miller.de/s9y/archives/69-Graycode-Umwandlung.html#comments</comments>
    <wfw:comment>http://www.lothar-miller.de/s9y/wfwcomment.php?cid=69</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=69</wfw:commentRss>
    

    <author>nospam@example.com (Lothar Miller)</author>
    <content:encoded>
    
&lt;p&gt;Hier finden sich C-Routinen zur Umwandlung von Graycode nach Binärcode und umgekehrt. Das Ganze basiert auf dem VHDL-Code hier: &lt;a title=&quot;Graycode VHDL&quot; target=&quot;_blank&quot; href=&quot;http://www.lothar-miller.de/s9y/archives/68-Graycode-Umwandlung.html&quot;&gt;Graycode-Umwandlung in VHDL&lt;/a&gt;&lt;/p&gt;&lt;hr width=&quot;100%&quot; size=&quot;2&quot; /&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;/*&lt;br /&gt;The purpose of this function is to convert an unsigned&lt;br /&gt;binary number to reflected binary Gray code.&lt;br /&gt;Binary 1-x-0-x-1-x-0-x-1&lt;br /&gt;       |  `   `   `   ` &lt;br /&gt;       |   |   |   |   |       x = xor&lt;br /&gt;       v   v   v   v   v       Abarbeitung MSB ... LSB &lt;br /&gt;Gray   1   1   0   0   1&lt;br /&gt;*/&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;short&lt;/span&gt; BinaryToGray(&lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;short&lt;/span&gt; num)&lt;br /&gt;{&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;return&lt;/span&gt; (num&amp;gt;&amp;gt;&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;) ^ num;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;/*&lt;br /&gt;A tricky trick: for up to 2^n bits, you can convert Gray to binary by&lt;br /&gt;performing (2^n) - 1 binary-to Gray conversions. All you need is the&lt;br /&gt;function above and a &#039;for&#039; loop.&lt;br /&gt;*/&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;short&lt;/span&gt; GrayToBinary(&lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;short&lt;/span&gt; num)&lt;br /&gt;{&lt;br /&gt;  &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;int&lt;/span&gt; i;&lt;br /&gt;  &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;short&lt;/span&gt; temp = num;&lt;br /&gt;  &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;for&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, 0, 221); font-weight: bold;&quot;&gt;15&lt;/span&gt;; i++) temp = BinaryToGray(temp);&lt;br /&gt;  &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;return&lt;/span&gt; temp;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;/*&lt;br /&gt;Gray   1   0   1   0   1&lt;br /&gt;       |  /   /   /   / &lt;br /&gt;       | x   x   x   x     x = xor&lt;br /&gt;       v/ `v/ `v/ `v/ `v   Abarbeitung MSB ... LSB &lt;br /&gt;Binary 1   1   0   0   1   &lt;br /&gt;*/&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;short&lt;/span&gt; GrayToBinaryX(&lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;short&lt;/span&gt; num)&lt;br /&gt;{&lt;br /&gt;  &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;int&lt;/span&gt; i;&lt;br /&gt;  &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;short&lt;/span&gt; temp = num;&lt;br /&gt;  temp &amp;amp;= &lt;span style=&quot;color: rgb(0, 85, 136); font-weight: bold;&quot;&gt;0x8000&lt;/span&gt;;&lt;br /&gt;  &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;for&lt;/span&gt; (i=&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;14&lt;/span&gt;; i&amp;gt;=&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;; i--) {&lt;br /&gt;     &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt; ( (!!(temp&amp;amp;(&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;&amp;lt;&amp;lt;(i+&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;)))) != (!!(num&amp;amp;(&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;&amp;lt;&amp;lt;i))) )&lt;br /&gt;        temp |= (&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;&amp;lt;&amp;lt;i);&lt;br /&gt;  }&lt;br /&gt;  &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;return&lt;/span&gt; temp;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;/*&lt;br /&gt;The purpose of this function is to convert a reflected binary&lt;br /&gt;Gray code number to a binary number.&lt;br /&gt;*/&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;short&lt;/span&gt; GrayToBinaryPow2(&lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;short&lt;/span&gt; num)&lt;br /&gt;{&lt;br /&gt;  &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 119, 68); font-weight: bold;&quot;&gt;short&lt;/span&gt; temp = num;&lt;br /&gt;  temp ^= (temp&amp;gt;&amp;gt;&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;8&lt;/span&gt;);&lt;br /&gt;  temp ^= (temp&amp;gt;&amp;gt;&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;4&lt;/span&gt;);&lt;br /&gt;  temp ^= (temp&amp;gt;&amp;gt;&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;2&lt;/span&gt;);&lt;br /&gt;  temp ^= (temp&amp;gt;&amp;gt;&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;);&lt;br /&gt;  &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;return&lt;/span&gt; temp;&lt;br /&gt;}&lt;/pre&gt;&lt;hr width=&quot;100%&quot; size=&quot;2&quot; /&gt;&lt;p&gt;Die Grundlagen dieser Umwandlungsroutinen sind auf &lt;a href=&quot;http://www.wisc-online.com/ViewObject.aspx?ID=IAU8307&quot; target=&quot;_blank&quot; title=&quot;Basics Graycode-Umwandlung&quot;&gt;www.wisc-online.com&lt;/a&gt; schön erklärt.&lt;/p&gt;

 
    </content:encoded>

    <pubDate>Sun, 17 Jan 2010 19:07:00 +0100</pubDate>
    <guid isPermaLink="false">http://www.lothar-miller.de/s9y/archives/69-guid.html</guid>
    
</item>
<item>
    <title>FIFO</title>
    <link>http://www.lothar-miller.de/s9y/archives/66-FIFO.html</link>
            <category>Fifo</category>
    
    <comments>http://www.lothar-miller.de/s9y/archives/66-FIFO.html#comments</comments>
    <wfw:comment>http://www.lothar-miller.de/s9y/wfwcomment.php?cid=66</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=66</wfw:commentRss>
    

    <author>nospam@example.com (Lothar Miller)</author>
    <content:encoded>
    
Immer wieder braucht man einen &lt;font color=&quot;#990000&quot;&gt;&lt;b&gt;Fifo&lt;/b&gt;&lt;/font&gt;, wenn &lt;b&gt;zeitlich unabhängige Prozesse&lt;/b&gt; untereinander Daten austauschen müssen. Die &lt;b&gt;Berechnung&lt;/b&gt; eines Wertes ist z.B. schnell erledigt, wenn dieser Wert aber über die &lt;b&gt;serielle Schnittstelle&lt;/b&gt; verschickt werden (oder auch auf einem Display ausgegeben werden) muß, ist es unsinnig, auf das Übertragungsende jedes Zeichens zu warten. &lt;br /&gt;Also wird der Wert von einer Rotuine berechnet und anschliessend in einen Pufferspeicher abgelegt. Eine andere, zeit- und interruptgesteuerte Routine holt dann ein Zeichen nach dem anderen aus dem Puffer und versendet das Zeichen.&lt;br /&gt;&lt;br /&gt;Einfach und effizient zu implementieren ist ein Fifo, dessen Größe einer 2er-Potenz entspricht (8, 16, 32, 64...). Dann kann der Indexüberlauf einfach mit einer Bitmaske abgehandelt werden. Hier ist so eine Implementierung:&lt;br /&gt;&lt;hr size=&quot;2&quot; width=&quot;100%&quot; /&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(85, 119, 153);&quot;&gt;#define&lt;/span&gt; BLEN (&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;16&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color: rgb(85, 119, 153);&quot;&gt;#define&lt;/span&gt; BMSK (BLEN-&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;)&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;typedef&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;struct&lt;/span&gt; {&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;volatile&lt;/span&gt; &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;char&lt;/span&gt; w;&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;volatile&lt;/span&gt; &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;char&lt;/span&gt; r;&lt;br /&gt;   &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;char&lt;/span&gt; d[BLEN];  &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// die Daten sind nicht volatil, sie können sich &lt;/span&gt;&lt;br /&gt;} fifotyp;                 &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// nur geändert haben, wenn der Index sich ändert&lt;/span&gt;&lt;br /&gt;fifotyp fifo;&lt;br /&gt;:&lt;br /&gt;:&lt;br /&gt;   &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// Fifo schreiben&lt;/span&gt;&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt; ((fifo.w - fifo.r)&amp;amp;BMSK==BMSK) {&lt;br /&gt;       &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// Fehlerbehandlung: Fifo ist voll&lt;/span&gt;&lt;br /&gt;   }&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;else&lt;/span&gt; {&lt;br /&gt;      &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// Zeichen eintragen&lt;/span&gt;&lt;br /&gt;      fifo.d[fifo.w&amp;amp;BMSK] = din;    &lt;br /&gt;      fifo.w++;&lt;br /&gt;   }&lt;br /&gt;    &lt;br /&gt;   &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// Fifo lesen&lt;/span&gt;&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt; (fifo.w != fifo.r) { &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// Fifo belegt?&lt;/span&gt;&lt;br /&gt;      &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// Zeichen auslesen&lt;/span&gt;&lt;br /&gt;      dout = fifo.d[fifo.r&amp;amp;BMSK];&lt;br /&gt;      fifo.r++;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// Fifo leeren&lt;/span&gt;&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt; (cleanupfifo=&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;) {&lt;br /&gt;      fifo.w = fifo.r;&lt;br /&gt;   }&lt;/pre&gt;&lt;hr size=&quot;2&quot; width=&quot;100%&quot; /&gt;&lt;b&gt;Fifo leer:&lt;/b&gt; Wenn der Leseindex r gleich dem Schreibindex w ist, dann ist der Fifo leer.&lt;br /&gt;&lt;b&gt;Fifo belegt:&lt;/b&gt; Wenn der Leseindex r ungleich dem Schreibindex w ist, dann ist ein Zeichen im Puffer. Wichtig ist, dass zuerst das Zeichen in den Puffer geschrieben (bzw. gelesen) wird, und erst dann der Index erhöht wird. Denn sonst könnte nach der Indexmanipulation ein Interrupt kommen, und weil das Zeichen noch nicht eingetragen wurde, wird mit falschen Daten gearbeitet.
&lt;br /&gt;&lt;b&gt;Fifo Reset:&lt;/b&gt; Das Rücksetzen des Fifos erfolgt einfach, indem der Leseindex gleich dem Schreibindex gesetzt wird. Allerdings sollte dieser Vorgang nur im Notfall angewendet werden, denn dabei gehen garantiert irgendwelche gespeicherte Informationen verloren.&lt;br /&gt;&lt;b&gt;Fifo Overrun:&lt;/b&gt; Ob noch ein Zeichen in den Fifo passt oder dieser voll ist, kann durch die Subtraktion des Schreibindex w vom Leseindex r überprüft werden. Ist das Ergebnis dieser Operation -1, dann kann kein weiteres Zeichen gespeichert werden. 
    </content:encoded>

    <pubDate>Sat, 12 Dec 2009 14:05:30 +0100</pubDate>
    <guid isPermaLink="false">http://www.lothar-miller.de/s9y/archives/66-guid.html</guid>
    
</item>
<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>
<item>
    <title>Filter in C</title>
    <link>http://www.lothar-miller.de/s9y/archives/25-Filter-in-C.html</link>
            <category>Filter</category>
    
    <comments>http://www.lothar-miller.de/s9y/archives/25-Filter-in-C.html#comments</comments>
    <wfw:comment>http://www.lothar-miller.de/s9y/wfwcomment.php?cid=25</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=25</wfw:commentRss>
    

    <author>nospam@example.com (Lothar Miller)</author>
    <content:encoded>
    
&lt;p&gt;Ein Filter in der Art eines RC-Filters (PT1-Glied) kann in einem uC relativ leicht implementiert werden. Dazu bedarf es, wie beim RC-Glied eines &amp;quot;Summenspeichers&amp;quot; (der Kondensator) und einer Gewichtung (Widerstand bzw. Zeitkonstante). &lt;/p&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(51, 51, 153); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(51, 51, 153); font-weight: bold;&quot;&gt;long&lt;/span&gt; mittelwert(&lt;span style=&quot;color: rgb(51, 51, 153); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(51, 51, 153); font-weight: bold;&quot;&gt;long&lt;/span&gt; newval) &lt;br /&gt;{&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: rgb(51, 51, 153); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(51, 51, 153); font-weight: bold;&quot;&gt;long&lt;/span&gt; avgsum = 0;&lt;br /&gt;   &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// Filterlängen in 2er-Potenzen --&amp;gt; Compiler optimiert &lt;/span&gt;&lt;br /&gt;   avgsum -= avgsum/&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;128&lt;/span&gt;;&lt;br /&gt;   avgsum += newval;&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;return&lt;/span&gt; avgsum/&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;128&lt;/span&gt;;&lt;br /&gt;}&lt;/pre&gt;&lt;p /&gt;&lt;p&gt;&lt;br /&gt;&lt;br /&gt;Etwas spannender wird es, wenn die Initialisierung des Startwertes nicht so lange dauern soll. Wenn ich beispielsweise nach dem 1. Messwert diesen Wert und ab dem 2. Messwert bis zur Filterbreite den Mittelwert aus allen Messungen haben möchte, dann ist eine andere Behandlung der Initialisierung nötig.&lt;/p&gt;&lt;p /&gt;&lt;p /&gt;&lt;p&gt;
&lt;/p&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(51, 51, 153); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(51, 51, 153); font-weight: bold;&quot;&gt;long&lt;/span&gt; mittelwert(&lt;span style=&quot;color: rgb(51, 51, 153); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(51, 51, 153); font-weight: bold;&quot;&gt;long&lt;/span&gt; newval) &lt;br /&gt;{&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: rgb(51, 51, 153); font-weight: bold;&quot;&gt;short&lt;/span&gt; n = 0&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;&lt;/span&gt;;&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: rgb(51, 51, 153); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt; &lt;span style=&quot;color: rgb(51, 51, 153); font-weight: bold;&quot;&gt;long&lt;/span&gt; avgsum = 0;&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt; (n&amp;lt;&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;100&lt;/span&gt;) {&lt;br /&gt;      n++;&lt;br /&gt;      avgsum += newval;&lt;br /&gt;      &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;return&lt;/span&gt; avgsum/n;&lt;br /&gt;   }&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;else&lt;/span&gt; {&lt;br /&gt;      &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;// Konstanten kann der Compiler besser optimieren&lt;/span&gt;&lt;br /&gt;      avgsum -= avgsum/&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;100&lt;/span&gt;;&lt;br /&gt;      avgsum += newval;&lt;br /&gt;      &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;return&lt;/span&gt; avgsum/&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;100&lt;/span&gt;;&lt;br /&gt;   }&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Der Aufruf erfolgt z.B. anhand eines Timer-Flags:&lt;/p&gt;&lt;pre&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;int&lt;/span&gt; argc, &lt;span style=&quot;color: rgb(51, 51, 153); font-weight: bold;&quot;&gt;char&lt;/span&gt;* argv[])&lt;br /&gt;{&lt;br /&gt;   :&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;while&lt;/span&gt;(&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&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.Calc) {&lt;br /&gt;         avgwert = mittelwert(value[i]);&lt;br /&gt;         printf(&lt;span style=&quot;background-color: rgb(255, 240, 240);&quot;&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 34, 0);&quot;&gt;i: %3d --&amp;gt; Wert: %d --&amp;gt; Mittelwert: %d&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 68, 221);&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;,i, value[i], mw);&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;&lt;/p&gt; 
    </content:encoded>

    <pubDate>Mon, 01 Dec 2008 09:57:32 +0100</pubDate>
    <guid isPermaLink="false">http://www.lothar-miller.de/s9y/archives/25-guid.html</guid>
    
</item>

</channel>
</rss>
