<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet href="/s9y/templates/default/atom.css" type="text/css" ?>

<feed 
   xmlns="http://www.w3.org/2005/Atom"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/">
    <link href="http://www.lothar-miller.de/s9y/feeds/atom.xml" rel="self" title="Lothar Miller" type="application/atom+xml" />
    <link href="http://www.lothar-miller.de/s9y/"                        rel="alternate"    title="Lothar Miller" type="text/html" />
    <link href="http://www.lothar-miller.de/s9y/rss.php?version=2.0"     rel="alternate"    title="Lothar Miller" type="application/rss+xml" />
    <title type="html">Lothar Miller</title>
    <subtitle type="html">Elektronik und Musik</subtitle>
    <icon>http://www.lothar-miller.de/s9y/templates/bulletproof/img/s9y_banner_small.png</icon>
    <id>http://www.lothar-miller.de/s9y/</id>
    <updated>2011-11-10T14:41:27Z</updated>
    <generator uri="http://www.s9y.org/" version="1.3.1">Serendipity 1.3.1 - http://www.s9y.org/</generator>
    <dc:language>de</dc:language>

    <entry>
        <link href="http://www.lothar-miller.de/s9y/archives/82-Qualifier.html" rel="alternate" title="Qualifier" />
        <author>
            <name>Lothar Miller</name>
                    </author>
    
        <published>2011-11-10T12:16:56Z</published>
        <updated>2011-11-10T14:41:27Z</updated>
        <wfw:comment>http://www.lothar-miller.de/s9y/wfwcomment.php?cid=82</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://www.lothar-miller.de/s9y/rss.php?version=atom1.0&amp;type=comments&amp;cid=82</wfw:commentRss>
    
            <category scheme="http://www.lothar-miller.de/s9y/categories/48-Code-Schnipsel" label="Code-Schnipsel" term="Code-Schnipsel" />
    
        <id>http://www.lothar-miller.de/s9y/archives/82-guid.html</id>
        <title type="html">Qualifier</title>
        <content type="xhtml" xml:base="http://www.lothar-miller.de/s9y/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                
<p>Es gestaltet sich in VHDL oft nicht so einfach, dem Synthesizer etwas Glasklares zu vermitteln. Nehmen wir mal diese einfache Aufgabe: Eine Konstante x&quot;1234&quot; soll an einen Vektor (<i>std_logic_vector</i> oder <i>unsigned</i>) zugewiesen werden. Weil die Länge des Vektors noch nicht feststeht, soll vorher ein <i>resize()</i> durchgeführt werden. <br />Wenn man das jetzt einfach so hinschreibt:</p><pre>slv &lt;= <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(resize(x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>1234</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>, slv<span style="color: rgb(0, 68, 221);">'l</span>ength));</pre>
<p>Dann erlebt man ein blaues Wunder. Obwohl eigentlich auf Anhieb erkennbar ist, was hier passieren soll, zickt der Compiler herum und meldet sowas wie:<br /><br /><b><font face="courier new,courier,monospace">Expression in type conversion to std_logic_vector has 2 possible definitions in this scope, for example, SIGNED and UNSIGNED.</font></b><br /><br />Was ist passiert?<br /><i>resize()</i> kann <i>signed </i>oder <i>unsigned </i>für diese Konstante zurückliefern. Weil der Synthesizer selber aber nicht entscheiden kann, welcher Datentyp gemeint ist, weiß er auch nicht, ob die <i>resize()</i> Funktion die Konstante als <i>signed </i>oder <i>unsigned </i>zu betrachten hat.<br />Dies kann ihm mit einem Qualifier gesagt werden: <i>unsigned'</i> sagt, dass der folgende Wert als <i>unsigned</i> zu betrachten ist. </p><pre>slv &lt;= <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(<span style="color: rgb(0, 119, 68); font-weight: bold;">unsigned</span><span style="color: rgb(0, 68, 221);">'(</span>resize(x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>1234</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>, slv<span style="color: rgb(0, 68, 221);">'l</span>ength)));</pre><p>Das hilft dem Synthesizer aus der Klemme, denn jetzt weiß er was das Ziel ist und er verwendet die gewünschte Implementierung der Funktion. </p><p>Hier mal eine kleine Aufstellung, was geht und was nicht:</p><p /><hr width="100%" size="2" /><pre><span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> slv  :  <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span> (<span style="color: rgb(0, 0, 221); font-weight: bold;">15</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>);
<span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> uv   :  <span style="color: rgb(0, 119, 68); font-weight: bold;">unsigned</span> (<span style="color: rgb(0, 0, 221); font-weight: bold;">15</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>);


slv &lt;= <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(resize(x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>1234</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>, slv<span style="color: rgb(0, 68, 221);">'l</span>ength));
<span style="color: rgb(136, 136, 136);">--&gt; Expression in type conversion to std_logic_vector has 2 possible definitions in this scope, for example, SIGNED and UNSIGNED.</span>

slv &lt;= <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(<span style="color: rgb(0, 119, 68); font-weight: bold;">unsigned</span><span style="color: rgb(0, 68, 221);">'(</span>resize(x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>1234</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>, slv<span style="color: rgb(0, 68, 221);">'l</span>ength)));
<span style="color: rgb(136, 136, 136);">--&gt; ok, das Ergebnis von resize ist ein unsigned Vektor</span>

slv &lt;= <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(resize(<span style="color: rgb(0, 119, 68); font-weight: bold;">unsigned</span>(x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>1234</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>), slv<span style="color: rgb(0, 68, 221);">'l</span>ength));
<span style="color: rgb(136, 136, 136);">--&gt; Expression in type conversion to unsigned has 7 possible definitions in this scope, for example, std_ulogic_vector and std_logic_vector.</span>

slv &lt;= <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(resize(<span style="color: rgb(0, 119, 68); font-weight: bold;">unsigned</span><span style="color: rgb(0, 68, 221);">'(</span>x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>1234</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>), slv<span style="color: rgb(0, 68, 221);">'l</span>ength));
<span style="color: rgb(136, 136, 136);">--&gt; ok, die Konstante x&quot;1234&quot; ist ein unsigned Wert</span>

uv &lt;= resize(<span style="color: rgb(0, 119, 68); font-weight: bold;">unsigned</span>(x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>1234</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>), uv<span style="color: rgb(0, 68, 221);">'l</span>ength);
<span style="color: rgb(136, 136, 136);">--&gt; Expression in type conversion to unsigned has 7 possible definitions in this scope, for example, std_ulogic_vector and std_logic_vector.</span>

uv &lt;= resize(<span style="color: rgb(0, 119, 68); font-weight: bold;">unsigned</span><span style="color: rgb(0, 68, 221);">'(</span>x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span></span><span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);"></span><span>1234</span><span style="color: rgb(119, 17, 0);"></span></span><span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);"></span><span style="color: rgb(119, 17, 0);">&quot;</span></span>), uv<span style="color: rgb(0, 68, 221);">'l</span>ength);
<span style="color: rgb(136, 136, 136);">--&gt; ok, die Konstante x&quot;1234&quot; ist ein unsigned Wert</span>

uv &lt;= resize(x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span></span><span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);"></span><span>1234</span><span style="color: rgb(119, 17, 0);"></span></span><span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);"></span><span style="color: rgb(119, 17, 0);">&quot;</span></span>, uv<span style="color: rgb(0, 68, 221);">'l</span>ength);
<span style="color: rgb(136, 136, 136);">--&gt; ok, der Typ von uv wird für resize verwendet</span></pre><hr width="100%" size="2" />
<p><br />
Bis zu einer Vektorlänge von 31 Bit geht es auch so:




</p><pre>slv &lt;= <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(to_unsigned(<span style="color: rgb(0, 0, 221); font-weight: bold;">16</span><span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">#</span></span><span style="color: rgb(0, 0, 221); font-weight: bold;">1234</span><span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">#</span></span>, slv<span style="color: rgb(0, 68, 221);">'l</span>ength));</pre><p />


 
            </div>
        </content>
        
    </entry>
    <entry>
        <link href="http://www.lothar-miller.de/s9y/archives/81-Xilinx-ISE-Step-by-Step.html" rel="alternate" title="Xilinx ISE Step-by-Step" />
        <author>
            <name>Lothar Miller</name>
                    </author>
    
        <published>2011-09-23T10:22:39Z</published>
        <updated>2011-09-23T10:34:57Z</updated>
        <wfw:comment>http://www.lothar-miller.de/s9y/wfwcomment.php?cid=81</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://www.lothar-miller.de/s9y/rss.php?version=atom1.0&amp;type=comments&amp;cid=81</wfw:commentRss>
    
            <category scheme="http://www.lothar-miller.de/s9y/categories/41-Xilinx-ISE" label="Xilinx ISE" term="Xilinx ISE" />
    
        <id>http://www.lothar-miller.de/s9y/archives/81-guid.html</id>
        <title type="html">Xilinx ISE Step-by-Step</title>
        <content type="xhtml" xml:base="http://www.lothar-miller.de/s9y/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                
Die <b>Xilinx ISE Entwicklungumgebung</b> ist eigentlich nicht kompliziert, nur eben umfangreich. Leicht kann da ein Anfänger mal einen falschen Knopf drücken und verliert sich dann in der Vielfalt der Menüs...
<br /><br /><p>Hier ein bebildertes <b>Tutorial </b>als Schritt-für-Schritt Anleitung, wie man </p><p>1) mit ISE ein Projekt aufsetzt, </p><p>2) den <a href="http://www.lothar-miller.de/s9y/archives/80-Hello-World!.html" title="Hello World!">VHDL-Code für eine blinkende LED</a> schreibt, </p><p>3) eine Testbench aufsetzt und den Code mit ISIM simuliert</p><p>4) die Pinzuordnung mit PlanAhead vornimmt</p><p>5) das Ganze implementiert und</p><p>6) mit Impact auf das FPGA lädt.</p><p /><p><a href="http://www.lothar-miller.de/s9y/uploads/Tutorial_Xilinx_ISE13.pdf">Zum PDF-Download (1,5MB) HIER clicken.</a></p><br />

 
            </div>
        </content>
        
    </entry>
    <entry>
        <link href="http://www.lothar-miller.de/s9y/archives/80-Hello-World!.html" rel="alternate" title="Hello World!" />
        <author>
            <name>Lothar Miller</name>
                    </author>
    
        <published>2011-09-23T09:59:39Z</published>
        <updated>2011-11-08T07:05:31Z</updated>
        <wfw:comment>http://www.lothar-miller.de/s9y/wfwcomment.php?cid=80</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://www.lothar-miller.de/s9y/rss.php?version=atom1.0&amp;type=comments&amp;cid=80</wfw:commentRss>
    
            <category scheme="http://www.lothar-miller.de/s9y/categories/48-Code-Schnipsel" label="Code-Schnipsel" term="Code-Schnipsel" />
    
        <id>http://www.lothar-miller.de/s9y/archives/80-guid.html</id>
        <title type="html">Hello World!</title>
        <content type="xhtml" xml:base="http://www.lothar-miller.de/s9y/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                
<p><b>Eine blinkende LED ist das &quot;<font color="#000099">Hello World!</font>&quot; der Hardware.</b> </p><p>Man kann daran erkennen, dass die Versorgung funktioniert, die Logik arbeitet und anhand der Blinkfrequenz einen Zähler beurteilen. Also schon einiges, was so eine einzelne Funzel einem sagen kann <img src="http://www.lothar-miller.de/s9y/templates/default/img/emoticons/smile.png" alt=":-)" style="display: inline; vertical-align: bottom;" class="emoticon" /> </p><p>Leider funktioniert diese einfache Variante eines Blinklichts nur in der Simulation:</p><p /><hr size="2" width="100%" /><pre><span style="color: rgb(0, 136, 0); font-weight: bold;">library</span> IEEE; 
<span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.STD_LOGIC_1164.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>; 
<span style="color: rgb(0, 136, 0); font-weight: bold;"></span> 
<span style="color: rgb(0, 136, 0); font-weight: bold;">entity</span> BlinkLED <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span> 
    <span style="color: rgb(0, 136, 0); font-weight: bold;">Port</span> (led : <span style="color: rgb(0, 136, 0); font-weight: bold;">buffer</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">STD_LOGIC </span>:= <span style="color: rgb(0, 68, 221);">'0'</span>); 
<span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> BlinkLED; 
 
<span style="color: rgb(0, 136, 0); font-weight: bold;">architecture</span> Behavioral <span style="color: rgb(0, 136, 0); font-weight: bold;">of</span> BlinkLED <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span> 
<span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span> 
   led &lt;= <span style="color: rgb(0, 136, 0); font-weight: bold;">not</span> led <span style="color: rgb(0, 136, 0); font-weight: bold;">after</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">500</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">ms</span>;    <span style="color: rgb(136, 136, 136);">-- LED alle 500 ms toggeln </span>
<span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> Behavioral;</pre><hr size="2" width="100%" /><p>Warum geht das nicht? Es gibt keine &quot;einstellbaren Verzögerungsglieder&quot; (ähnlich wie Monoflops oder RC-Glieder...) im FPGA. Alles, was mit Zeiten zu tun hat, muss in einem FPGA als Zähler aufgebaut werden, der einen Takt mitzählen und beim Erreichen eines passenden Endwertes eine Reaktion auslöst. <br />Also brauchen wir einen Takt und einen Zähler. In der Regel ist am FPGA ein Quarz mit z.B. 50MHz angeschlossen. Für eine halbe Sekunde müssen also 25 Millionen Takte gezählt werden. Das ergibt eine Registerkette mit 25 Bits (mit diesen 25 Bit wären maximal 2^25=33554432 Zählschritte möglich).<br />Und diese 25 Register werden mit einem festen Wert 24999999 verglichen. Warum 24999999 und nicht 25000000? <br />Weil 0...24999999 schon 25000000 Schritte sind. Einfacher wird es vielleicht mit kleineren Zahlen: ein Zähler, der 5 Schritte abzählen muß, braucht die Zahlen 0, 1, 2, 3 und 4.</p><p>Also zusammengefasst:<br />Ein Takt geht auf einen Zähler, der mit einem festen Wert verglichen wird, bei dessen Erreichen zurückgesetzt wird und gleichzeitig eine Aktion auslöst: die LED wird getoggelt.</p><p>Hier ist der VHDL-Quellcode für so ein Blinklicht:</p><hr size="2" width="100%" /><pre><span style="color: rgb(0, 136, 0); font-weight: bold;">library</span> IEEE; 
<span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.STD_LOGIC_1164.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>; 
<span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.NUMERIC_STD.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>; 
 
<span style="color: rgb(0, 136, 0); font-weight: bold;">entity</span> BlinkLED <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span> 
    <span style="color: rgb(0, 136, 0); font-weight: bold;">Port</span> ( clk : <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">STD_LOGIC</span>; 
           led : <span style="color: rgb(0, 136, 0); font-weight: bold;">out</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">STD_LOGIC</span>); 
<span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> BlinkLED; 
 
<span style="color: rgb(0, 136, 0); font-weight: bold;">architecture</span> Behavioral <span style="color: rgb(0, 136, 0); font-weight: bold;">of</span> BlinkLED <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span> 

<span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> c : <span style="color: rgb(0, 119, 68); font-weight: bold;">integer</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">to</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">24999999</span> := <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>; <span style="color: rgb(136, 136, 136);">-- 0,5s bei 50MHz fosc</span>
<span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> x : <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>:= <span style="color: rgb(0, 68, 221);">'0'</span>;  

<span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span> 
   <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span>  
      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">until</span> rising_edge(clk); <span style="color: rgb(136, 136, 136);">-- warten bis zum nächsten Takt </span>
      <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (c&lt;<span style="color: rgb(0, 0, 221); font-weight: bold;">24999999</span>) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span>         <span style="color: rgb(136, 136, 136);">-- 0…24999999 = 25000000 Takte = 1/2 Sekunde bei 50MHz </span>
          c &lt;= c+<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>;                <span style="color: rgb(136, 136, 136);">-- wenn kleiner: weiterzählen </span>
      <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>                         <span style="color: rgb(136, 136, 136);">-- wenn Zählerende erreicht: </span>
          c &lt;= <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>;                  <span style="color: rgb(136, 136, 136);">-- Zähler zurücksetzen </span>
          x &lt;= <span style="color: rgb(0, 136, 0); font-weight: bold;">not</span> x;              <span style="color: rgb(136, 136, 136);">-- und Signal x togglen </span>
      <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>; 
   <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span>; 
   led &lt;= x;                       <span style="color: rgb(136, 136, 136);">-- Signal x an LED ausgeben </span>
<span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> Behavioral;</pre><hr size="2" width="100%" /><p>Zur Funktionsweise:<br />mit einem Zähler werden 25 Millionen Takte eines 50 MHz Taktes abgezählt (also 0..24999999). Wenn der Zählerendwert erreicht wurde, wird der Zähler zurückgesetzt und gleichzeitig ein lokales Signal <b><i>x</i></b> getoggelt. Dieses Signal wird dann an den <b><i>led </i></b>Ausgang gegeben.</p><p>Das lokale Signal <b><i>x</i></b> brauchen wir, weil der Port <b><i>led </i></b>als <b><i>out </i></b>deklariert ist, und daher entsprechend den VHDL Richtlinien <u>nicht lesbar</u> ist.<br />Und um den Schlauen zuvorzukommen: Nein, es ist <u>keine gute Idee</u>, den Port <b><i>led </i></b>als <b><i>buffer </i></b>oder <b><i>inout </i></b>zu deklarieren, nur damit er zurückgelesen werden und so ein lokales Signal gespart werden kann. Das ist eher ein Kündigungsgrund oder sollte wenigstens einen strengen Verweis in der Personalakte nach sich ziehen...<br />Als kleiner Lichtblick: ab VHDL 2008 können auch <b><i>out </i></b>Ports wieder zurückgelesen werden, diese Ports verhalten sich dann ähnlich wie <i><b>buffer</b></i>. So ist es dann möglich, z.B. einen Zähler direkt auf einen <b><i>out</i></b> Port zu erzeugen.<br /> </p><p>Und hier die kompakte Stimuli-&quot;Testbench&quot;:</p><hr size="2" width="100%" /><pre><span style="color: rgb(0, 136, 0); font-weight: bold;">library</span> IEEE; 
<span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.STD_LOGIC_1164.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>; 
<span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.NUMERIC_STD.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>;  
  
<span style="color: rgb(0, 136, 0); font-weight: bold;">entity</span> tb_BlinkLED <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span> 
                                   <span style="color: rgb(136, 136, 136);">-- leere Entity --&gt; Testbench</span>
<span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> tb_BlinkLED; 
  
<span style="color: rgb(0, 136, 0); font-weight: bold;">architecture</span> behavior <span style="color: rgb(0, 136, 0); font-weight: bold;">of</span> tb_BlinkLED <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span>
   <span style="color: rgb(0, 136, 0); font-weight: bold;">component</span> BlinkLED 
   <span style="color: rgb(0, 136, 0); font-weight: bold;">port</span>( clk : <span style="color: rgb(0, 136, 0); font-weight: bold;">IN</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>; 
         led : <span style="color: rgb(0, 136, 0); font-weight: bold;">OUT</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span> ); 
   <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">component</span>; 
    
   <span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> clk : <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span> := <span style="color: rgb(0, 68, 221);">'0'</span>;  <span style="color: rgb(136, 136, 136);">-- lokale Signale der Testbench</span>
   <span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> led : <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>;         <span style="color: rgb(136, 136, 136);">-- werden an den Prüfling angeschlossen</span>

<span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span>
   uut: BlinkLED                   <span style="color: rgb(136, 136, 136);">-- der Prüfling wird verdrahtet</span>
   <span style="color: rgb(0, 136, 0); font-weight: bold;">port</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">map</span> ( clk =&gt; clk, 
              led =&gt; led ); 
 
   clk &lt;= <span style="color: rgb(0, 136, 0); font-weight: bold;">not</span> clk <span style="color: rgb(0, 136, 0); font-weight: bold;">after</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">10</span> ns;     <span style="color: rgb(136, 136, 136);">-- einen 50MHz Takt erzeugen</span>
<span style="color: rgb(0, 136, 0); font-weight: bold;">end</span>;</pre><hr size="2" width="100%" /><p>
Wer dieses Blinklicht zum ersten Mal mit ISE realisieren will, der kann sich die <a title="Xilinx ISE Schritt für Schritt" target="_blank" href="http://www.lothar-miller.de/s9y/archives/81-Xilinx-ISE-Step-by-Step.html">Schritt-für-Schritt Anleitung HIER mal ansehen</a>.
</p><p><br />Für alle, die noch nicht genug haben kommt hier der Binärzähler auf 8 LEDs.</p><hr size="2" width="100%" /><pre><span style="color: rgb(0, 136, 0); font-weight: bold;">library</span> IEEE; 
<span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.STD_LOGIC_1164.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>; 
<span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.NUMERIC_STD.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>; 
 
<span style="color: rgb(0, 136, 0); font-weight: bold;">entity</span> BinaryLED <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span> 
    <span style="color: rgb(0, 136, 0); font-weight: bold;">Port</span> ( clk  : <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">STD_LOGIC</span>; 
           leds : <span style="color: rgb(0, 136, 0); font-weight: bold;">out</span> <span style="color: rgb(0, 119, 68); font-weight: bold;">STD_LOGIC_VECTOR</span>(<span style="color: rgb(0, 0, 221); font-weight: bold;">7</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>)); 
<span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> BinaryLED; 
 
<span style="color: rgb(0, 136, 0); font-weight: bold;">architecture</span> Behavioral <span style="color: rgb(0, 136, 0); font-weight: bold;">of</span> BinaryLED <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span> 

<span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> c : <span style="color: rgb(0, 119, 68); font-weight: bold;">integer</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">to</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">12499999</span> := <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>; <span style="color: rgb(136, 136, 136);">-- 0,25s bei 50MHz fosc</span>
<span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> x : <span style="color: rgb(0, 119, 68); font-weight: bold;">unsigned</span> (<span style="color: rgb(0, 0, 221); font-weight: bold;">7</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>) := (<span style="color: rgb(0, 136, 0); font-weight: bold;">others</span>=&gt;<span style="color: rgb(0, 68, 221);">'0'</span>);  

<span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span> 
   <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span>  
      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">until</span> rising_edge(clk); <span style="color: rgb(136, 136, 136);">-- warten bis zum nächsten Takt </span>
      <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (c&lt;<span style="color: rgb(0, 0, 221); font-weight: bold;">12499999</span> ) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span>        <span style="color: rgb(136, 136, 136);">-- 0..12499999 = 12500000 Takte = 1/4 Sekunde bei 50MHz </span>
          c &lt;= c+<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>;                <span style="color: rgb(136, 136, 136);">-- wenn kleiner: c weiterzählen </span>
      <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>                         <span style="color: rgb(136, 136, 136);">-- wenn Zählerende erreicht: </span>
          c &lt;= <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>;                  <span style="color: rgb(136, 136, 136);">-- Zähler c zurücksetzen </span>
          x &lt;= x+<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>;                <span style="color: rgb(136, 136, 136);">-- und Zähler x hochzählen </span>
      <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>; 
   <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span>; 
   leds &lt;= <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(x);    <span style="color: rgb(136, 136, 136);">-- Signal x an LEDs ausgeben </span>
<span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> Behavioral;</pre><hr size="2" width="100%" /><p>Im Großen und Ganzen ist das Beispiel gleich wie das obere. Nur wird hier statt der einzelnen LED ein <i><b>unsigned</b></i>-Vektor hochgezählt. Das Hochzählen von Vektoren hat den Vorteil, dass der Überlauf von <i>11111111bin </i>= <i>255dez </i>nach <i>00000000bin </i>= <i>0dez </i>automatisch passiert. <br /><br /><br />Ich hätte den Zähler <i><b>x</b></i> natürlich wie den Zähler <i><b>c</b></i> auch als <i><b>integer </b></i>machen können, dann hätte der Code (für eine fehlerfreie Simulation) aber so aussehen müssen:</p><hr size="2" width="100%" /><pre><span style="color: rgb(0, 136, 0); font-weight: bold;">library</span> IEEE; 
<span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.STD_LOGIC_1164.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>; 
<span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.NUMERIC_STD.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>; 
 
<span style="color: rgb(0, 136, 0); font-weight: bold;">entity</span> BinaryLED <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span> 
    <span style="color: rgb(0, 136, 0); font-weight: bold;">Port</span> ( clk  : <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">STD_LOGIC</span>; 
           leds : <span style="color: rgb(0, 136, 0); font-weight: bold;">out</span> <span style="color: rgb(0, 119, 68); font-weight: bold;">STD_LOGIC_VECTOR</span>(<span style="color: rgb(0, 0, 221); font-weight: bold;">7</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>)); 
<span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> BinaryLED; 
 
<span style="color: rgb(0, 136, 0); font-weight: bold;">architecture</span> Behavioral <span style="color: rgb(0, 136, 0); font-weight: bold;">of</span> BinaryLED <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span> 

<span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> c : <span style="color: rgb(0, 119, 68); font-weight: bold;">integer</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">to</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">12499999</span> := <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>; <span style="color: rgb(136, 136, 136);">-- 0,25s bei 50MHz fosc</span>
<span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> x : <span style="color: rgb(0, 119, 68); font-weight: bold;">integer</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">to</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">255</span> := <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>;  

<span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span> 
   <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span>  
      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">until</span> rising_edge(clk); <span style="color: rgb(136, 136, 136);">-- warten bis zum nächsten Takt </span>
      <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (c&lt;<span style="color: rgb(0, 0, 221); font-weight: bold;">12499999</span> ) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span>        <span style="color: rgb(136, 136, 136);">-- 0..12499999 = 12500000 Takte </span>
          c &lt;= c+<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>;                <span style="color: rgb(136, 136, 136);">-- wenn kleiner: c weiterzählen </span>
      <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>                         <span style="color: rgb(136, 136, 136);">-- wenn Zählerende erreicht: </span>
          c &lt;= <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>;                  <span style="color: rgb(136, 136, 136);">-- Zähler c zurücksetzen </span>
          <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (x&lt;<span style="color: rgb(0, 0, 221); font-weight: bold;">255</span>) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span>          <span style="color: rgb(136, 136, 136);">-- ist Zähler x schon &quot;oben&quot; angekommen</span>
             x &lt;= x+<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>;             <span style="color: rgb(136, 136, 136);">-- nein: Zähler x hochzählen </span>
          <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>
             x &lt;= <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>;               <span style="color: rgb(136, 136, 136);">-- ja: zurücksetzen</span>
          <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>;
      <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>; 
   <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span>; 
   <span style="color: rgb(136, 136, 136);">-- Signal konvertieren und casten und an LEDs ausgeben </span>
   leds &lt;= <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(to_unsigned(x,<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>)); 
<span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> Behavioral;</pre><hr size="2" width="100%" /><p><br />Der nächste logische Schritt ist dann, die Erzeugung des Fortschaltimpulses in einem eigenen Prozess zu erzeugen.</p><hr size="2" width="100%" /><pre><span style="color: rgb(0, 136, 0); font-weight: bold;">library</span> IEEE; 
<span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.STD_LOGIC_1164.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>; 
<span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.NUMERIC_STD.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>; 
 
<span style="color: rgb(0, 136, 0); font-weight: bold;">entity</span> BinaryLED <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span> 
    <span style="color: rgb(0, 136, 0); font-weight: bold;">Port</span> ( clk  : <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">STD_LOGIC</span>; 
           leds : <span style="color: rgb(0, 136, 0); font-weight: bold;">out</span> <span style="color: rgb(0, 119, 68); font-weight: bold;">STD_LOGIC_VECTOR</span>(<span style="color: rgb(0, 0, 221); font-weight: bold;">7</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>)); 
<span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> BinaryLED; 
 
<span style="color: rgb(0, 136, 0); font-weight: bold;">architecture</span> Behavioral <span style="color: rgb(0, 136, 0); font-weight: bold;">of</span> BinaryLED <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span> 

<span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> c : <span style="color: rgb(0, 119, 68); font-weight: bold;">integer</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">to</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">12499999</span> := <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>; <span style="color: rgb(136, 136, 136);">-- 0,25s bei 50MHz fosc</span>
<span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> t : <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span> := <span style="color: rgb(0, 68, 221);">'0'</span>;
<span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> x : <span style="color: rgb(0, 119, 68); font-weight: bold;">integer</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">to</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">255</span> := <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>;  

<span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span> 
   <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span>  
      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">until</span> rising_edge(clk); <span style="color: rgb(136, 136, 136);">-- warten bis zum nächsten Takt </span>
      <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (c&lt;<span style="color: rgb(0, 0, 221); font-weight: bold;">12499999</span> ) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span>        <span style="color: rgb(136, 136, 136);">-- 1/4 Sekunde bei 50MHz </span>
          c &lt;= c+<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>;                <span style="color: rgb(136, 136, 136);">-- wenn kleiner: c weiterzählen </span>
          t &lt;= <span style="color: rgb(0, 68, 221);">'0'</span>;                
      <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>                         <span style="color: rgb(136, 136, 136);">-- wenn Zählerende erreicht: </span>
          c &lt;= <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>;                  <span style="color: rgb(136, 136, 136);">-- Zähler c zurücksetzen </span>
          t &lt;= <span style="color: rgb(0, 68, 221);">'1'</span>;                <span style="color: rgb(136, 136, 136);">-- Flag für Tick setzen</span>
      <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>; 
   <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span>; 

   <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span>  
      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">until</span> rising_edge(clk); <span style="color: rgb(136, 136, 136);">-- warten bis zum nächsten Takt </span>
      <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (t=<span style="color: rgb(0, 68, 221);">'1'</span>) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span>              <span style="color: rgb(136, 136, 136);">-- sind schon wieder 0,25 sec vorbei?</span>
          <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (x&lt;<span style="color: rgb(0, 0, 221); font-weight: bold;">255</span>) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span>          <span style="color: rgb(136, 136, 136);">-- ist Zähler x schon &quot;oben&quot; angekommen</span>
             x &lt;= x+<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>;             <span style="color: rgb(136, 136, 136);">-- nein: Zähler x hochzählen </span>
          <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>
             x &lt;= <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>;               <span style="color: rgb(136, 136, 136);">-- ja: zurücksetzen</span>
          <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>;
      <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>; 
   <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span>; 

   <span style="color: rgb(136, 136, 136);">-- Signal konvertieren und casten und an LEDs ausgeben </span>
   leds &lt;= <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(to_unsigned(x,<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>)); 
<span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> Behavioral;</pre><hr size="2" width="100%" /><p><br />Wie man klar sieht, gibt es in diesem Design nur und genau einen einzigen Takt <i><b>clk</b></i>. Das ist der Quarzoszillator, der aussen am FPGA angeschlossen ist. Mit diesem Takt läuft das ganze Design. Für Anfänger gilt: <br /><b>Der Takt ist wie der Highlander: es kann nur einen geben</b>. </p>



 
            </div>
        </content>
        
    </entry>
    <entry>
        <link href="http://www.lothar-miller.de/s9y/archives/79-use_new_parser-YES.html" rel="alternate" title="-use_new_parser YES" />
        <author>
            <name>Lothar Miller</name>
                    </author>
    
        <published>2011-08-31T06:00:58Z</published>
        <updated>2011-08-31T07:39:44Z</updated>
        <wfw:comment>http://www.lothar-miller.de/s9y/wfwcomment.php?cid=79</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://www.lothar-miller.de/s9y/rss.php?version=atom1.0&amp;type=comments&amp;cid=79</wfw:commentRss>
    
            <category scheme="http://www.lothar-miller.de/s9y/categories/41-Xilinx-ISE" label="Xilinx ISE" term="Xilinx ISE" />
    
        <id>http://www.lothar-miller.de/s9y/archives/79-guid.html</id>
        <title type="html">-use_new_parser YES</title>
        <content type="xhtml" xml:base="http://www.lothar-miller.de/s9y/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                
<p>Leider kann die Xilinx-Synthese nur Arrays bis max. 2 Dimensionen. Der 
Xilinx SXT User Guide dazu:<br /> <font color="#0000CC" face="courier new,courier,monospace">XST supports multi-dimensional array types 
of up to two dimensions.</font><br />Das ist lästig, wenn man mehr Dimensionen bräuchte, und der Simulator das problemlos mitmacht...</p><p>Ein anderer Effekt ist das Initialisieren von Arrays, das in bestimmten Konstellationen einfach nicht klappt und mit einer Meldung wie<br /> <font color="#0000CC" face="courier new,courier,monospace">Default value is ignored for signal &lt;my_array&gt;</font> <br />kommentiert wird. Und auch hier: die Simulation läuft tadellos, nur der Synthesizer schafft die Initialisierung nicht...</p><p>Glück gehabt: die Rettung naht verkleidet als undokumentierte Syntheseoption: -use_new_parser yes</p><p>Der ist zu finden in den Process-Properties, die mit einem Rechtsclick auf <i><b>Synthesize-XST</b></i> auswählbar sind. Dort muß dann <i><b>Property display level: Advanced</b></i> ausgewählt und in der letzten Zeile bei <i><b>Other XST Command Line Options</b></i> der Schalter <i><b>-use_new_parser yes</b></i> eingetragen werden.
<br /><br /><br /><!-- s9ymdb:148 --><img height="260" width="700" class="serendipity_image_center" style="border: 0px none; padding-left: 5px; padding-right: 5px;" src="http://www.lothar-miller.de/s9y/uploads/Bilder/use_new_parser.gif" /><br /><br />Mit diesem Schalter ergibt sich dann eine wundersame Wandlung:</p><pre>  <span style="color: rgb(136, 136, 136);">-- XST13: OK  </span>
  <span style="color: rgb(0, 136, 0); font-weight: bold;">TYPE</span> array_typ1 <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">array</span> (<span style="color: rgb(0, 119, 68); font-weight: bold;">natural</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> &lt;&gt;) <span style="color: rgb(0, 136, 0); font-weight: bold;">of</span> <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>;
  <span style="color: rgb(0, 136, 0); font-weight: bold;">TYPE</span> array_typ2 <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">array</span> (<span style="color: rgb(0, 119, 68); font-weight: bold;">natural</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> &lt;&gt;, <span style="color: rgb(0, 119, 68); font-weight: bold;">natural</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> &lt;&gt;) <span style="color: rgb(0, 136, 0); font-weight: bold;">of</span> <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>;

  <span style="color: rgb(136, 136, 136);">-- XST13 default: Fehler  / mit &quot;-use_new_parser yes&quot;: OK</span>
  <span style="color: rgb(0, 136, 0); font-weight: bold;">TYPE</span> array_typ3 <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">array</span> (<span style="color: rgb(0, 119, 68); font-weight: bold;">natural</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> &lt;&gt;, <span style="color: rgb(0, 119, 68); font-weight: bold;">natural</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> &lt;&gt;, <span style="color: rgb(0, 119, 68); font-weight: bold;">natural</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> &lt;&gt;) <span style="color: rgb(0, 136, 0); font-weight: bold;">of</span> <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>;
  <span style="color: rgb(0, 136, 0); font-weight: bold;">TYPE</span> array_typ4 <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">array</span> (<span style="color: rgb(0, 119, 68); font-weight: bold;">natural</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> &lt;&gt;, <span style="color: rgb(0, 119, 68); font-weight: bold;">natural</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> &lt;&gt;, <span style="color: rgb(0, 119, 68); font-weight: bold;">natural</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> &lt;&gt;, <span style="color: rgb(0, 119, 68); font-weight: bold;">natural</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> &lt;&gt;) <span style="color: rgb(0, 136, 0); font-weight: bold;">of</span> <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>;
  <span style="color: rgb(0, 136, 0); font-weight: bold;">TYPE</span> array_typ5 <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">array</span> (<span style="color: rgb(0, 119, 68); font-weight: bold;">natural</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> &lt;&gt;, <span style="color: rgb(0, 119, 68); font-weight: bold;">natural</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> &lt;&gt;, <span style="color: rgb(0, 119, 68); font-weight: bold;">natural</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> &lt;&gt;, <span style="color: rgb(0, 119, 68); font-weight: bold;">natural</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> &lt;&gt;, <span style="color: rgb(0, 119, 68); font-weight: bold;">natural</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> &lt;&gt;) <span style="color: rgb(0, 136, 0); font-weight: bold;">of</span> <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>;</pre><p>Hier der komplette Quelltext dazu: <b><a target="_blank" title="PackageTypedef.vhd" href="http://www.lothar-miller.de/s9y/uploads/PackageTypedef.vhd">PackageTypedef.vhd</a></b></p>






 
            </div>
        </content>
        
    </entry>
    <entry>
        <link href="http://www.lothar-miller.de/s9y/archives/78-Bubblesort.html" rel="alternate" title="Bubblesort" />
        <author>
            <name>Lothar Miller</name>
                    </author>
    
        <published>2011-04-21T09:22:18Z</published>
        <updated>2011-08-31T07:38:27Z</updated>
        <wfw:comment>http://www.lothar-miller.de/s9y/wfwcomment.php?cid=78</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://www.lothar-miller.de/s9y/rss.php?version=atom1.0&amp;type=comments&amp;cid=78</wfw:commentRss>
    
            <category scheme="http://www.lothar-miller.de/s9y/categories/24-Rechnen" label="Rechnen " term="Rechnen " />
    
        <id>http://www.lothar-miller.de/s9y/archives/78-guid.html</id>
        <title type="html">Bubblesort</title>
        <content type="xhtml" xml:base="http://www.lothar-miller.de/s9y/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                
<p>Hier jetzt mal eine Umsetzung des allseits bekannten Bubblesort-Algorithmus in VHDL. <br />Zuerst die rein kombinatorische Variante:</p><hr size="2" width="100%" /><pre><span style="color: rgb(0, 136, 0); font-weight: bold;">library</span> IEEE;
<span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.STD_LOGIC_1164.<span style="color: rgb(0, 136, 0); font-weight: bold;">all</span>;

<span style="color: rgb(0, 136, 0); font-weight: bold;">package</span> BSTypes <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span>
  <span style="color: rgb(0, 136, 0); font-weight: bold;">type</span> BSData_Typ <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">array</span> (<span style="color: rgb(0, 0, 221); font-weight: bold;">0</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">to</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">9</span>) <span style="color: rgb(0, 136, 0); font-weight: bold;">of</span> <span style="color: rgb(0, 119, 68); font-weight: bold;">integer</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">to</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">127</span>;
<span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> BSTypes;

<span style="color: rgb(0, 136, 0); font-weight: bold;">package</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">body</span> BSTypes <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span>
<span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> BSTypes;




<span style="color: rgb(0, 136, 0); font-weight: bold;">library</span> IEEE;
<span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.STD_LOGIC_1164.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>;
<span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.NUMERIC_STD.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>;
<span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> work.bstypes.<span style="color: rgb(0, 136, 0); font-weight: bold;">all</span>;

<span style="color: rgb(0, 136, 0); font-weight: bold;">entity</span> Bubblesort <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span>
    <span style="color: rgb(0, 136, 0); font-weight: bold;">Port</span> ( di  : <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span>  BSData_Typ;
           do  : <span style="color: rgb(0, 136, 0); font-weight: bold;">out</span> BSData_Typ );
<span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> Bubblesort;

<span style="color: rgb(0, 136, 0); font-weight: bold;">architecture</span> Behavioral <span style="color: rgb(0, 136, 0); font-weight: bold;">of</span> Bubblesort <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span>
<span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span>

   <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span> (di) 
   <span style="color: rgb(0, 136, 0); font-weight: bold;">variable</span> din  : BSData_Typ;
   <span style="color: rgb(0, 136, 0); font-weight: bold;">variable</span> temp : <span style="color: rgb(0, 119, 68); font-weight: bold;">integer</span>;
   <span style="color: rgb(0, 136, 0); font-weight: bold;">variable</span> n    : <span style="color: rgb(0, 119, 68); font-weight: bold;">integer</span>;
   <span style="color: rgb(0, 136, 0); font-weight: bold;">variable</span> oncemore : <span style="color: rgb(0, 119, 68); font-weight: bold;">boolean</span>;
   <span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span>
      din      := di;
      n        := din<span style="color: rgb(0, 68, 221);">'l</span>ength;
      oncemore := TRUE;
      <span style="color: rgb(0, 136, 0); font-weight: bold;">while</span> oncemore = TRUE <span style="color: rgb(0, 136, 0); font-weight: bold;">and</span> n &gt; <span style="color: rgb(0, 0, 221); font-weight: bold;">1</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">loop</span>
         oncemore := FALSE;
         <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> i <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">to</span> din<span style="color: rgb(0, 68, 221);">'l</span>ength-<span style="color: rgb(0, 0, 221); font-weight: bold;">2</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">loop</span>
            <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> din(i) &gt; din(i+<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span> 
               temp     := din(i);   <span style="color: rgb(136, 136, 136);">-- Dreieckstausch</span>
               din(i)   := din(i+<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>);
               din(i+<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>) := temp;
               oncemore := TRUE;
            <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>;
         <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">loop</span>;
         n := n-<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>;
      <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">loop</span>;
      do &lt;= din;
   <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span>;
   
<span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> Behavioral;</pre><hr size="2" width="100%" /><p>In einem Spartan 3 FPGA braucht diese Lösung abhängig vom Abbruch (über die Variable oncemore) unterschiedlich viele Ressourcen:<br />Mit Abbruch:      Number of Slices  1293         Number of 4 input LUTs 2272<br />Ohne Abbruch:   Number of Slices  976           Number of 4 input LUTs 1701</p><p>Der offensichtlichste Unterschied ist, dass der in der Software effizientere Abbruch (wenn das Array schon vor Ablauf aller Kombinationen schon komplett sortiert ist) in der Hardware nur Nachteile mit sich bringt.</p><p>Nachfolgend eine getaktete Lösung, die auf Kosten der Rechenzeit deutlich weniger Ressourcen braucht. <a href="http://www.lothar-miller.de/s9y/uploads/Bubblesort.zip" title="Bubblesort.zip" target="_blank">Bubblesort.zip</a><br />Insbesondere fällt hier der Unterschied zwischen der Variante mit und der ohneAbbruch wesentlich geringer aus:<br />Mit Abbruch:      Number of Slices  168           Number of 4 input LUTs 250<br />Ohne Abbruch:   Number of Slices  167           Number of 4 input LUTs 245</p><hr size="2" width="100%" /><pre><span style="color: rgb(136, 136, 136);">-- Typdefinition BSData_Typ s.o.</span>

<span style="color: rgb(0, 136, 0); font-weight: bold;">library</span> IEEE;
<span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.STD_LOGIC_1164.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>;
<span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.NUMERIC_STD.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>;
<span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> work.bstypes.<span style="color: rgb(0, 136, 0); font-weight: bold;">all</span>;

<span style="color: rgb(0, 136, 0); font-weight: bold;">entity</span> Bubblesort <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span>
    <span style="color: rgb(0, 136, 0); font-weight: bold;">Port</span> ( di    : <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span>  BSData_Typ;
           do    : <span style="color: rgb(0, 136, 0); font-weight: bold;">out</span> BSData_Typ;
           start : <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>;
           done  : <span style="color: rgb(0, 136, 0); font-weight: bold;">out</span> <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>;
           clk   : <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>);
<span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> Bubblesort;

<span style="color: rgb(0, 136, 0); font-weight: bold;">architecture</span> Behavioral <span style="color: rgb(0, 136, 0); font-weight: bold;">of</span> Bubblesort <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span>
<span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> busy     : <span style="color: rgb(0, 119, 68); font-weight: bold;">boolean</span> := FALSE;
<span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> din      : BSData_Typ;
<span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> n,i      : <span style="color: rgb(0, 119, 68); font-weight: bold;">integer</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">to</span> din<span style="color: rgb(0, 68, 221);">'l</span>ength;
<span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span>

   <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span> 
   <span style="color: rgb(0, 136, 0); font-weight: bold;">variable</span> temp : <span style="color: rgb(0, 119, 68); font-weight: bold;">integer</span>;
   <span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span>
      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">until</span> rising_edge(clk);
      <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (busy=FALSE) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span>
         <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (start=<span style="color: rgb(0, 68, 221);">'1'</span>) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span>
            din  &lt;= di;
            busy &lt;= TRUE;
            n    &lt;= <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>;
            i    &lt;= <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>;
         <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>;
      <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>
         <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (n &lt; din<span style="color: rgb(0, 68, 221);">'l</span>ength) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span>
            <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (i&lt;din<span style="color: rgb(0, 68, 221);">'l</span>ength-<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span>
               <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> din(i) &gt; din(i+<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span>
                  temp     := din(i);   <span style="color: rgb(136, 136, 136);">-- Dreieckstausch</span>
                  din(i)   &lt;= din(i+<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>);
                  din(i+<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>) &lt;= temp;
               <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>;
               i &lt;= i+<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>;
            <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>
               i &lt;= <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>;
               n &lt;= n+<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>;
            <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>;
         <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>
            busy &lt;= FALSE;       
            do   &lt;= din;
         <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>;
      <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>;
   <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span>;
   
   done &lt;= <span style="color: rgb(0, 68, 221);">'1'</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">when</span> start=<span style="color: rgb(0, 68, 221);">'0'</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">and</span> busy=FALSE <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span> <span style="color: rgb(0, 68, 221);">'0'</span>;

<span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> Behavioral;</pre><hr size="2" width="100%" /><p>Das ist die Testbench für die kombinatorische Variante:</p><hr size="2" width="100%" /><pre><span style="color: rgb(0, 136, 0); font-weight: bold;">LIBRARY</span> ieee;
<span style="color: rgb(0, 136, 0); font-weight: bold;">USE</span> ieee.std_logic_1164.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>;
<span style="color: rgb(0, 136, 0); font-weight: bold;">USE</span> ieee.numeric_std.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>;
<span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> ieee.math_real.<span style="color: rgb(0, 136, 0); font-weight: bold;">all</span>;
<span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> work.bstypes.<span style="color: rgb(0, 136, 0); font-weight: bold;">all</span>;
 
<span style="color: rgb(0, 136, 0); font-weight: bold;">ENTITY</span> tb_BubbleSort <span style="color: rgb(0, 136, 0); font-weight: bold;">IS</span>
<span style="color: rgb(0, 136, 0); font-weight: bold;">END</span> tb_BubbleSort;
 
<span style="color: rgb(0, 136, 0); font-weight: bold;">ARCHITECTURE</span> behavior <span style="color: rgb(0, 136, 0); font-weight: bold;">OF</span> tb_BubbleSort <span style="color: rgb(0, 136, 0); font-weight: bold;">IS</span> 
    <span style="color: rgb(0, 136, 0); font-weight: bold;">COMPONENT</span> Bubblesort
    <span style="color: rgb(0, 136, 0); font-weight: bold;">Port</span> ( di  : <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span>  BSData_Typ;
           do  : <span style="color: rgb(0, 136, 0); font-weight: bold;">out</span> BSData_Typ );
    <span style="color: rgb(0, 136, 0); font-weight: bold;">END</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">COMPONENT</span>;

   <span style="color: rgb(136, 136, 136);">--Inputs</span>
   <span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> di : BSData_Typ := (<span style="color: rgb(0, 0, 221); font-weight: bold;">3</span>,<span style="color: rgb(0, 0, 221); font-weight: bold;">6</span>,<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>,<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>,<span style="color: rgb(0, 0, 221); font-weight: bold;">7</span>,<span style="color: rgb(0, 0, 221); font-weight: bold;">2</span>,<span style="color: rgb(0, 0, 221); font-weight: bold;">4</span>,<span style="color: rgb(0, 0, 221); font-weight: bold;">5</span>,<span style="color: rgb(0, 0, 221); font-weight: bold;">9</span>,<span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>);
   <span style="color: rgb(136, 136, 136);">--Outputs</span>
   <span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> do : BSData_Typ;
   
<span style="color: rgb(0, 136, 0); font-weight: bold;">BEGIN</span>
  <span style="color: rgb(136, 136, 136);">-- Instantiate the Unit Under Test (UUT)</span>
   uut: Bubblesort <span style="color: rgb(0, 136, 0); font-weight: bold;">PORT</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">MAP</span> (
          di =&gt; di,
          do =&gt; do
        );

   <span style="color: rgb(136, 136, 136);">-- Stimulus process</span>
   stim_proc: <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span>
    <span style="color: rgb(0, 136, 0); font-weight: bold;">variable</span> rand  : <span style="color: rgb(0, 119, 68); font-weight: bold;">real</span>;
    <span style="color: rgb(0, 136, 0); font-weight: bold;">variable</span> seed1 : <span style="color: rgb(0, 119, 68); font-weight: bold;">positive</span> := <span style="color: rgb(0, 0, 221); font-weight: bold;">234</span>;
    <span style="color: rgb(0, 136, 0); font-weight: bold;">variable</span> seed2 : <span style="color: rgb(0, 119, 68); font-weight: bold;">positive</span> := <span style="color: rgb(0, 0, 221); font-weight: bold;">567</span>;
   <span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span>    
      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">100</span> ns;  
      <span style="color: rgb(0, 136, 0); font-weight: bold;">loop</span>
         <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> i <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">to</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">9</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">loop</span>
            UNIFORM(seed1, seed2, rand);
            di(i) &lt;= <span style="color: rgb(0, 119, 68); font-weight: bold;">integer</span>(TRUNC(rand*<span style="color: rgb(0, 0, 221); font-weight: bold;">12</span><span style="color: rgb(102, 0, 238); font-weight: bold;">7</span><span style="color: rgb(102, 0, 238); font-weight: bold;">.999</span>));
         <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">loop</span>;
         <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">10</span> ns;
         <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> i <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">to</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">8</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">loop</span>
            <span style="color: rgb(0, 136, 0); font-weight: bold;">assert</span> do(i)&lt;=do(i+<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>) <span style="color: rgb(0, 136, 0); font-weight: bold;">report</span> <span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>Falsche Reihenfolge!</span><span style="color: rgb(119, 17, 0);">&quot;</span></span> <span style="color: rgb(0, 136, 0); font-weight: bold;">severity</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">failure</span>;
         <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">loop</span>;
       <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">loop</span>;
   <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span>;

<span style="color: rgb(0, 136, 0); font-weight: bold;">END</span>;</pre><hr size="2" width="100%" /><p>Und das kommt dabei heraus:</p><div class="serendipity_imageComment_center" style="width: 711px;"><div class="serendipity_imageComment_img"><!-- s9ymdb:147 --><img height="104" width="711" class="serendipity_image_center" src="http://www.lothar-miller.de/s9y/uploads/Bilder/BubblesortKomb.gif" /></div><div class="serendipity_imageComment_txt">Waveform der Testbench für den kombinatorischen Sortierer</div></div><p /><p /><p><br />Und hier können die Dateien gezippt heruntergeladen werden: <b><a target="_blank" title="Bubblesort.zip" href="http://www.lothar-miller.de/s9y/uploads/Bubblesort.zip">Bubblesort.zip</a></b></p>





 
            </div>
        </content>
        
    </entry>
    <entry>
        <link href="http://www.lothar-miller.de/s9y/archives/27-Xilinx-New-Source.html" rel="alternate" title="Xilinx New Source" />
        <author>
            <name>Lothar Miller</name>
                    </author>
    
        <published>2011-04-13T07:19:00Z</published>
        <updated>2011-04-20T06:45:41Z</updated>
        <wfw:comment>http://www.lothar-miller.de/s9y/wfwcomment.php?cid=27</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://www.lothar-miller.de/s9y/rss.php?version=atom1.0&amp;type=comments&amp;cid=27</wfw:commentRss>
    
            <category scheme="http://www.lothar-miller.de/s9y/categories/41-Xilinx-ISE" label="Xilinx ISE" term="Xilinx ISE" />
    
        <id>http://www.lothar-miller.de/s9y/archives/27-guid.html</id>
        <title type="html">Xilinx New Source</title>
        <content type="xhtml" xml:base="http://www.lothar-miller.de/s9y/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                
<p>Wenn mit <b>Xilinx ISE</b> ein <b>neues Projekt oder Source-File</b> angelegt wird, fragt der Wizzard nach EA und Bitbreiten. Nach einem Klick auf &quot;DONE&quot; wird dann ein neues Sourcefile angelegt, in dem aber ein riesiger Header und die alten Synopsys-Libs eingebunden sind:</p><hr width="100%" size="2" /><pre><span style="color: rgb(136, 136, 136);">--------------------------------------------------------</span><br /><span style="color: rgb(136, 136, 136);">-- Company: </span><br /><span style="color: rgb(136, 136, 136);">-- Engineer: </span><br /><span style="color: rgb(136, 136, 136);">-- </span><br /><span style="color: rgb(136, 136, 136);">-- Create Date:    11:21:38 </span><span style="color: rgb(136, 136, 136);">01/04/2010</span><span style="color: rgb(136, 136, 136);"> </span><br /><span style="color: rgb(136, 136, 136);">-- Design Name: </span><br /><span style="color: rgb(136, 136, 136);">-- Module Name:    Defaulttext - Behavioral </span><br /><span style="color: rgb(136, 136, 136);">-- Project Name: </span><br /><span style="color: rgb(136, 136, 136);">-- Target Devices: </span><br /><span style="color: rgb(136, 136, 136);">-- Tool versions: </span><br /><span style="color: rgb(136, 136, 136);">-- Description: </span><br /><span style="color: rgb(136, 136, 136);">--</span><br /><span style="color: rgb(136, 136, 136);">-- Dependencies: </span><br /><span style="color: rgb(136, 136, 136);">--</span><br /><span style="color: rgb(136, 136, 136);">-- Revision: </span><br /><span style="color: rgb(136, 136, 136);">-- Revision 0.01 - File Created</span><br /><span style="color: rgb(136, 136, 136);">-- Additional Comments: </span><br /><span style="color: rgb(136, 136, 136);">--</span><br /><span style="color: rgb(136, 136, 136);">--------------------------------------------------------</span><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">library</span> <span>IEEE</span>;<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> <span>IEEE</span>.<span>STD_LOGIC_1164</span>.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>;<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> <span>IEEE</span>.<span>STD_LOGIC_ARITH</span>.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>;<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> <span>IEEE</span>.<span>STD_LOGIC_UNSIGNED</span>.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>;<br /><br /><span style="color: rgb(136, 136, 136);">---- Uncomment the following library declaration if instantiating</span><br /><span style="color: rgb(136, 136, 136);">---- any Xilinx primitives in this code.</span><br /><span style="color: rgb(136, 136, 136);">--library UNISIM;</span><br /><span style="color: rgb(136, 136, 136);">--use UNISIM.VComponents.all;</span><br /><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">entity</span> <span>Defaulttext</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span><br />    <span style="color: rgb(0, 136, 0); font-weight: bold;">Port</span> ( <span>clk</span> : <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span>  <span style="color: rgb(51, 51, 153); font-weight: bold;">STD_LOGIC</span>;<br />           <span>d</span> : <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span>  <span style="color: rgb(51, 51, 153); font-weight: bold;">STD_LOGIC</span>;<br />           <span>o</span> : <span style="color: rgb(0, 136, 0); font-weight: bold;">out</span>  <span style="color: rgb(51, 51, 153); font-weight: bold;">STD_LOGIC</span>);<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span>Defaulttext</span>;<br /><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">architecture</span> <span>Behavioral</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">of</span> <span>Defaulttext</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span><br /><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span><br /><br /><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span>Behavioral</span>;</pre><hr width="100%" size="2" /><p /><p /><p>Das musste ich geändert haben: <br />Ich will als Standard-Lib die NUMERIC_STD einbinden, die UNISIM soll raus, und der Header etwas verschlankt werden.<br /><br /><b><font size="4" color="#660000">ISE Version 13</font></b> <br />Hier müssen dazu die beiden TCL-Scripte <br /><font color="#0000CC"><b>C:\Xilinx\ISE_DS\ISE\data\projnav\scripts\dpm_sourceTasks.tcl<br />C:\Xilinx\ISE_DS\ISE\data\testbnch2.tcl</b></font>  <br />angepasst werden.<br /><br />Im Script <font color="#0000CC"><b>dpm_sourceTasks.tcl</b></font> wird die Erzeugung eines neuen VHDL-Sourcecodemodul gesteuert. Hier muss die Prozedur <font color="#0000CC"><b>proc dpm_sourceCreateVHDL</b></font> geändert werden. Hier hat sich im Gegensatz zu früheren Versionen (siehe Beschreibung unten) das <b>$_fs</b> in ein <b>$hFile</b> geändert.<br /><br />Im <font color="#0000CC"><b>testbnch2.tcl</b></font> wird die Generierung der Testbench gesteuert. Hier hat sich einiges getan, und ich musste erst mal die automatische Reset-Suche pensionieren. Auch die Taktgenerierung hat mir nicht gefallen, so dass sich da ebenso einiges geändert hat.<br /><br />Damit die Suche nicht so schwer fällt, gibt es hier meine beiden Templates zum Download: <b><a href="http://www.lothar-miller.de/s9y/uploads/IseTemplates.zip" title="IseTemplates.zip" target="_blank">IseTemplates.zip</a></b><br /><br /><br /><br /><font size="4" color="#660000"><b>ISE Versionen 9 bis 11 </b></font><br />Etwa in der Mitte dieses TCL-Scripts   <br /><font color="#0000cc"><b>C:\Xilinx\data\projnav\scripts\dpm_sourceTasks.tcl</b></font>   <br />findet sich die Stelle, die angepasst werden muss:</p><hr width="100%" size="2" /><p><font face="courier new,courier,monospace" color="#006600">      $_iHdlData GetPorts _portIter<br />      puts $_fs &quot;----------------------------------------------------------&quot;<br />      puts $_fs &quot;-- Engineer: Lothar Miller&quot;<br />      puts $_fs &quot;-- &quot;<br />      puts $_fs &quot;-- Create Date:    $_ts &quot;<br />      puts $_fs &quot;-- Design Name: &quot;<br />      puts $_fs &quot;-- Module Name:    $_entityName - $_archName &quot;<br />      puts $_fs &quot;----------------------------------------------------------&quot;<br />      puts $_fs &quot;library IEEE;&quot;<br />      puts $_fs &quot;use IEEE.STD_LOGIC_1164.ALL;&quot;<br />      puts $_fs &quot;use IEEE.NUMERIC_STD.ALL;&quot;<br />      puts $_fs &quot;&quot;</font></p><hr width="100%" size="2" /><p /><p>Nach der Änderung dieser Datei kommt beim Erzeugen eines neuen Projekts/Sourcefiles der gewünschte Customer-Header.</p><pre><span style="color: rgb(136, 136, 136);"></span></pre><hr width="100%" size="2" /><pre><span style="color: rgb(136, 136, 136);">--------------------------------------------------------</span><br /><span style="color: rgb(136, 136, 136);">-- Engineer: Lothar Miller</span><br /><span style="color: rgb(136, 136, 136);">-- </span><br /><span style="color: rgb(136, 136, 136);">-- Create Date:    11:21:38 01/04/2010 </span><br /><span style="color: rgb(136, 136, 136);">-- Design Name: </span><br /><span style="color: rgb(136, 136, 136);">-- Module Name:    Defaulttext - Behavioral </span><br /><span style="color: rgb(136, 136, 136);"></span><span style="color: rgb(136, 136, 136);"></span><span style="color: rgb(136, 136, 136);">--------------------------------------------------------</span><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">library</span> <span>IEEE</span>;<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> <span>IEEE</span>.<span>STD_LOGIC_1164</span>.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>;<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> <span>IEEE</span>.<span>NUMERIC_STD</span>.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>;<br /><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">entity</span> <span>Defaulttext</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span><br />    <span style="color: rgb(0, 136, 0); font-weight: bold;">Port</span> ( <span>clk</span> : <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span>  <span style="color: rgb(51, 51, 153); font-weight: bold;">STD_LOGIC</span>;<br />           <span>d</span> : <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span>  <span style="color: rgb(51, 51, 153); font-weight: bold;">STD_LOGIC</span>;<br />           <span>o</span> : <span style="color: rgb(0, 136, 0); font-weight: bold;">out</span>  <span style="color: rgb(51, 51, 153); font-weight: bold;">STD_LOGIC</span>);<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span>Defaulttext</span>;<br /><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">architecture</span> <span>Behavioral</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">of</span> <span>Defaulttext</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span><br /><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span><br /><br /><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span>Behavioral</span>;</pre><hr width="100%" size="2" /><br />Für die Voreinstellungen beim Erstellen der Simulationsdatei gilt der Pfad<br /><p><font color="#0000cc"><b>C:\Xilinx\data\testbnch2.tft</b></font><br /><br /><br />
</p>



 
            </div>
        </content>
        
    </entry>
    <entry>
        <link href="http://www.lothar-miller.de/s9y/archives/77-DCF77-Decoder.html" rel="alternate" title="DCF77 Decoder" />
        <author>
            <name>Lothar Miller</name>
                    </author>
    
        <published>2011-01-14T08:20:00Z</published>
        <updated>2011-01-25T14:33:18Z</updated>
        <wfw:comment>http://www.lothar-miller.de/s9y/wfwcomment.php?cid=77</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://www.lothar-miller.de/s9y/rss.php?version=atom1.0&amp;type=comments&amp;cid=77</wfw:commentRss>
    
            <category scheme="http://www.lothar-miller.de/s9y/categories/56-DCF77" label="DCF77" term="DCF77" />
    
        <id>http://www.lothar-miller.de/s9y/archives/77-guid.html</id>
        <title type="html">DCF77 Decoder</title>
        <content type="xhtml" xml:base="http://www.lothar-miller.de/s9y/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                
<p>Ein DCF-Signal besteht aus Impulsfolgen, die pro Sekunde mit unterschiedlich langen High-Pegeln eine 0 (=100ms high) bzw. eine 1 (=200ms high) codieren. Die 59. Sekunde wird zur Synchronisation verwendet und wird mit low-Pegel ausgegeben. Die steigende Flanke nach der 58. skeunde ist daher dann die Sekunde 0. <br /><br />Die<b> Auswertung des DCF-Signals</b> wird also von einem Zähler übernommen, der mit einer steigenden Flanke zurückgesetzt wird. Bei einer fallenden Flanke wird dann entsprechend dem Zählerstand eine '0' (&lt;150ms) oder eine '1' (&gt;150ms) übernommen. <br />Alternativ kann auch beim Zählerstand 150ms einfach der Pegel des DCF-Signals eingelesen werden.<br /><br />Erreicht der Zähler einen Wert größer 1 Sekunde, war das die 59. Sekunde. Bei der der nächsten steigenden Flanke des DCF-Signals werden dann die eingelesenen Bits zur weiteren Verarbeitung über ein Pufferregister bereitgestellt.<br /><br />In dem folgenden Code sollte vor der Synthese eine der beiden Varianten (beide funktionieren gleich gut) der Bit-Auswertung auskommentiert werden <img src="http://www.lothar-miller.de/s9y/templates/default/img/emoticons/smile.png" alt=":-)" style="display: inline; vertical-align: bottom;" class="emoticon" /></p><hr size="2" width="100%" /><pre><span style="color: rgb(0, 136, 0); font-weight: bold;">library</span> IEEE;<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.STD_LOGIC_1164.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>;<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.NUMERIC_STD.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>;<br /><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">entity</span> DCF77 <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span><br />    <span style="color: rgb(0, 136, 0); font-weight: bold;">Generic</span>( fclk : <span style="color: rgb(0, 119, 68); font-weight: bold;">integer</span> := <span style="color: rgb(0, 0, 221); font-weight: bold;">50000000</span> ); <span style="color: rgb(136, 136, 136);">-- 50MHz</span><br />    <span style="color: rgb(0, 136, 0); font-weight: bold;">Port</span>   ( clk       : <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>; <br />             dcf       : <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>;<br />             dcf_sec0  : <span style="color: rgb(0, 136, 0); font-weight: bold;">out</span> <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>;<br />             bitsout   : <span style="color: rgb(0, 136, 0); font-weight: bold;">out</span> <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span> (<span style="color: rgb(0, 0, 221); font-weight: bold;">58</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>) );<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> DCF77;<br /><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">architecture</span> Behavioral <span style="color: rgb(0, 136, 0); font-weight: bold;">of</span> DCF77 <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">constant</span> cntmax    : <span style="color: rgb(0, 119, 68); font-weight: bold;">integer</span> := (<span style="color: rgb(0, 0, 221); font-weight: bold;">11</span>*fclk)/<span style="color: rgb(0, 0, 221); font-weight: bold;">10</span>;   <span style="color: rgb(136, 136, 136);">     -- 1.1 sec</span><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">constant</span> cntsample : <span style="color: rgb(0, 119, 68); font-weight: bold;">integer</span> := (<span style="color: rgb(0, 0, 221); font-weight: bold;">15</span>*fclk)/<span style="color: rgb(0, 0, 221); font-weight: bold;">100</span>;  <span style="color: rgb(136, 136, 136);">     -- 150 ms</span><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> cnt         : <span style="color: rgb(0, 119, 68); font-weight: bold;">integer</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">to</span> cntmax := <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>; <span style="color: rgb(136, 136, 136);">-- Zähler bis 1.1 sec</span><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> dcfsr       : <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(<span style="color: rgb(0, 0, 221); font-weight: bold;">2</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>);<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> bits        : <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(<span style="color: rgb(0, 0, 221); font-weight: bold;">58</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>):= (<span style="color: rgb(0, 136, 0); font-weight: bold;">others</span>=&gt;<span style="color: rgb(0, 68, 221);">'0'</span>);<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span><br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span><br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">until</span> rising_edge(clk);<br />      <span style="color: rgb(136, 136, 136);">-- Einsynchronisieren</span><br />      dcfsr &lt;= dcfsr(<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>) &amp; dcf;<br />   <br />      <span style="color: rgb(136, 136, 136);">-- erst Zaehler hochzählen (sättigend bei 1.1 sec)</span><br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (cnt &lt; cntmax) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span> <br />         cnt &lt;= cnt+<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>; <br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>;<br />      <br />      <span style="color: rgb(136, 136, 136);">-- steigende Flanke vom DCF-Signal</span><br />      dcf_sec0 &lt;= <span style="color: rgb(0, 68, 221);">'0'</span>;             <span style="color: rgb(136, 136, 136);">-- für 1 Taktzyklus bei Sekunde 0 aktiv</span><br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (dcfsr(<span style="color: rgb(0, 0, 221); font-weight: bold;">2</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>)=<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>01</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span> <br />         <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (cnt = cntmax) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span>    <span style="color: rgb(136, 136, 136);">-- Überlauf? ja: Sekunde 59 war da</span><br />            dcf_sec0 &lt;= <span style="color: rgb(0, 68, 221);">'1'</span>;       <span style="color: rgb(136, 136, 136);">-- Sekunde 0 anzeigen</span><br />            bitsout &lt;= bits;       <span style="color: rgb(136, 136, 136);">-- die gesammelten Daten übergeben</span><br />            bits &lt;= (<span style="color: rgb(0, 136, 0); font-weight: bold;">others</span>=&gt;<span style="color: rgb(0, 68, 221);">'0'</span>); <span style="color: rgb(136, 136, 136);">-- Bit-Schiebegregister zuruecksetzen</span><br />         <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>;<br />         cnt &lt;= <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>;<br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>;<br />   <br />      <span style="color: rgb(136, 136, 136);">-- Variante 1: einlesen bei fallender Flanke vom DCF-Signal</span><br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (dcfsr(<span style="color: rgb(0, 0, 221); font-weight: bold;">2</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>)=<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>10</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span> <br />         <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (cnt &lt; cntsample) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span>           <span style="color: rgb(136, 136, 136);">-- kurzer Impuls? Grenze 150ms</span><br />            bits &lt;= <span style="color: rgb(0, 68, 221);">'0'</span> &amp; bits(<span style="color: rgb(0, 0, 221); font-weight: bold;">58</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>); <span style="color: rgb(136, 136, 136);">-- ja: 0 von links einschieben</span><br />         <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span><br />            bits &lt;= <span style="color: rgb(0, 68, 221);">'1'</span> &amp; bits(<span style="color: rgb(0, 0, 221); font-weight: bold;">58</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>); <span style="color: rgb(136, 136, 136);">-- nein: 1 von links einschieben</span><br />         <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>;      <br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>;<br />      <span style="color: rgb(136, 136, 136);">-- --&gt; Ressourcenverbrauch    </span><br />      <span style="color: rgb(136, 136, 136);">-- Number of Slices       88</span><br />      <span style="color: rgb(136, 136, 136);">-- Number of Slice FFs    137</span><br />      <span style="color: rgb(136, 136, 136);">-- Number of 4 input LUTs 104</span><br />      <br />      <span style="color: rgb(136, 136, 136);">-- Variante 2: bei Zeitpunkt &quot;150ms&quot; einlesen   </span><br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (cnt = cntsample) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span>             <span style="color: rgb(136, 136, 136);">-- DCF-Signal einlesen bei 150ms</span><br />          bits &lt;= dcfsr(<span style="color: rgb(0, 0, 221); font-weight: bold;">2</span>) &amp; bits(<span style="color: rgb(0, 0, 221); font-weight: bold;">58</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>); <br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>;<br />      <span style="color: rgb(136, 136, 136);">-- --&gt; Ressourcenverbrauch</span><br />      <span style="color: rgb(136, 136, 136);">-- Number of Slices       87</span><br />      <span style="color: rgb(136, 136, 136);">-- Number of Slice FFs    137</span><br />      <span style="color: rgb(136, 136, 136);">-- Number of 4 input LUTs 103</span><br /><br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span>;<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> Behavioral;</pre><hr size="2" width="100%" /><p>Zusammen mit der Testbench unten ergeben sich folgende Waveforms:</p>
<div class="serendipity_imageComment_center" style="width: 700px;"><div class="serendipity_imageComment_img"><a class="serendipity_image_link" href="http://www.lothar-miller.de/s9y/uploads/Bilder/SimWave11.gif"><!-- s9ymdb:140 --><img height="134" width="700" class="serendipity_image_center" src="http://www.lothar-miller.de/s9y/uploads/Bilder/SimWave11.gif" /></a></div><div class="serendipity_imageComment_txt">Überblick</div></div><br /><br />
<div class="serendipity_imageComment_center" style="width: 700px;"><div class="serendipity_imageComment_img"><a class="serendipity_image_link" href="http://www.lothar-miller.de/s9y/uploads/Bilder/SimWave12.gif"><!-- s9ymdb:141 --><img height="133" width="700" class="serendipity_image_center" src="http://www.lothar-miller.de/s9y/uploads/Bilder/SimWave12.gif" /></a></div><div class="serendipity_imageComment_txt">Detail mit Sekunde 59 und darauffolgender Datenübergabe</div></div>
<br /><p>Hier der DCF77-Decoder incl. Testbench zum Download: <a target="_blank" title="DCF77.zip" href="http://www.lothar-miller.de/s9y/uploads/Bilder/DCF77.zip">DCF77.zip</a></p><p>Mit diesem Decoder werden nur die rohen Daten bereitgestellt. In dem Modul darüber muß dann noch die gesamte Plausibilitätskontrolle (Parity), die Validierung und die weitere Verwaltung der empfangenen Daten realisiert werden.</p> 
            </div>
        </content>
        
    </entry>
    <entry>
        <link href="http://www.lothar-miller.de/s9y/archives/76-BCD-nach-ASCII.html" rel="alternate" title="BCD nach ASCII" />
        <author>
            <name>Lothar Miller</name>
                    </author>
    
        <published>2010-11-25T14:43:53Z</published>
        <updated>2010-11-26T08:31:15Z</updated>
        <wfw:comment>http://www.lothar-miller.de/s9y/wfwcomment.php?cid=76</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://www.lothar-miller.de/s9y/rss.php?version=atom1.0&amp;type=comments&amp;cid=76</wfw:commentRss>
    
            <category scheme="http://www.lothar-miller.de/s9y/categories/44-BCD-Umwandlung" label="BCD Umwandlung" term="BCD Umwandlung" />
    
        <id>http://www.lothar-miller.de/s9y/archives/76-guid.html</id>
        <title type="html">BCD nach ASCII</title>
        <content type="xhtml" xml:base="http://www.lothar-miller.de/s9y/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                
<p>Sollen Zahlen z.B. an ein Display oder über eine serielle Schnittstelle ausgegeben werden, dann ist es naheliegend, sie zuerst in ein BCD-Format und anschliessend in ASCII umzuwandeln. <br />Hier werden mehrere Lösungsmöglichkeiten für die Umwandlung einer BCD-Zahl in ein ASCII-Format aufgezeigt. <br /><br />Der Lösungsansatz bei der Addiererlösung ist folgender:<br /><br /><b><font face="courier new,courier,monospace">Wenn <i>di </i>eine Zahl von 0..9 ist, dann addiere eine ASCII-0 dazu.<br />Wenn <i>di </i>eine Zahl von 10..15 ist, dann subtrahiere 10 und addiere ein ASCII-A dazu.</font></b></p><hr size="2" width="100%" /><pre><span style="color: rgb(0, 136, 0); font-weight: bold;">library</span> IEEE;<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.STD_LOGIC_1164.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>;<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.NUMERIC_STD.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>;<br /><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">entity</span> BCD2ASCII <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span><br />    <span style="color: rgb(0, 136, 0); font-weight: bold;">Port</span> ( di : <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">STD_LOGIC_VECTOR</span> (<span style="color: rgb(0, 0, 221); font-weight: bold;">3</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>);<br />           do : <span style="color: rgb(0, 136, 0); font-weight: bold;">out</span> <span style="color: rgb(0, 119, 68); font-weight: bold;">STD_LOGIC_VECTOR</span> (<span style="color: rgb(0, 0, 221); font-weight: bold;">7</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>));<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> BCD2ASCII;<br /><br /><span style="color: rgb(136, 136, 136);">-- Dierekte Beschreibung als Distributed BROM</span><br /><span style="color: rgb(136, 136, 136);"></span><span style="color: rgb(136, 136, 136);">-- Maximum combinational path delay: 7.276ns</span><br /><span style="color: rgb(136, 136, 136);">-- Number of Slices         3</span><br /><span style="color: rgb(136, 136, 136);">-- Number of 4 input LUTs   6</span><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">architecture</span> Behavioral <span style="color: rgb(0, 136, 0); font-weight: bold;">of</span> BCD2ASCII <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span><br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">type</span> Rom16x8 <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">array</span> (<span style="color: rgb(0, 0, 221); font-weight: bold;">0</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">to</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">15</span>) <span style="color: rgb(0, 136, 0); font-weight: bold;">of</span> <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span> (<span style="color: rgb(0, 0, 221); font-weight: bold;">7</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>);<br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">constant</span> BCDRom : Rom16x8 := ( <br />       <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(to_unsigned(<span style="color: rgb(0, 119, 68); font-weight: bold;">character</span>'pos(<span style="color: rgb(0, 68, 221);">'0'</span>),<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>)),<br />       <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(to_unsigned(<span style="color: rgb(0, 119, 68); font-weight: bold;">character</span>'pos(<span style="color: rgb(0, 68, 221);"></span><span style="color: rgb(0, 68, 221);">'1'</span>),<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>)),<br />       <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(to_unsigned(<span style="color: rgb(0, 119, 68); font-weight: bold;">character</span>'pos(<span style="color: rgb(0, 68, 221);"></span><span style="color: rgb(0, 68, 221);">'2'</span>),<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>)),<br />       <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(to_unsigned(<span style="color: rgb(0, 119, 68); font-weight: bold;">character</span>'pos(<span style="color: rgb(0, 68, 221);"></span><span style="color: rgb(0, 68, 221);">'3'</span>),<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>)),<br />       <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(to_unsigned(<span style="color: rgb(0, 119, 68); font-weight: bold;">character</span>'pos(<span style="color: rgb(0, 68, 221);"></span><span style="color: rgb(0, 68, 221);">'4'</span>),<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>)),<br />       <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(to_unsigned(<span style="color: rgb(0, 119, 68); font-weight: bold;">character</span>'pos(<span style="color: rgb(0, 68, 221);"></span><span style="color: rgb(0, 68, 221);">'5'</span>),<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>)),<br />       <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(to_unsigned(<span style="color: rgb(0, 119, 68); font-weight: bold;">character</span>'pos(<span style="color: rgb(0, 68, 221);"></span><span style="color: rgb(0, 68, 221);">'6'</span>),<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>)),<br />       <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(to_unsigned(<span style="color: rgb(0, 119, 68); font-weight: bold;">character</span>'pos<span style="color: rgb(0, 68, 221);"></span>(<span style="color: rgb(0, 68, 221);">'7'</span>),<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>)),<br />       <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(to_unsigned(<span style="color: rgb(0, 119, 68); font-weight: bold;">character</span>'pos(<span style="color: rgb(0, 68, 221);"></span><span style="color: rgb(0, 68, 221);">'8'</span>),<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>)),<br />       <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(to_unsigned(<span style="color: rgb(0, 119, 68); font-weight: bold;">character</span>'pos(<span style="color: rgb(0, 68, 221);"></span><span style="color: rgb(0, 68, 221);">'9'</span>),<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>)),<br />       <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(to_unsigned(<span style="color: rgb(0, 119, 68); font-weight: bold;">character</span>'pos(<span style="color: rgb(0, 68, 221);"></span><span style="color: rgb(0, 68, 221);">'A'</span>),<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>)),<br />       <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(to_unsigned(<span style="color: rgb(0, 119, 68); font-weight: bold;">character</span>'pos(<span style="color: rgb(0, 68, 221);"></span><span style="color: rgb(0, 68, 221);">'B'</span>),<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>)),<br />       <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(to_unsigned(<span style="color: rgb(0, 119, 68); font-weight: bold;">character</span>'pos(<span style="color: rgb(0, 68, 221);"></span><span style="color: rgb(0, 68, 221);">'C'</span>),<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>)),<br />       <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(to_unsigned(<span style="color: rgb(0, 119, 68); font-weight: bold;">character</span>'pos(<span style="color: rgb(0, 68, 221);"></span><span style="color: rgb(0, 68, 221);">'D'</span>),<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>)),<br />       <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(to_unsigned(<span style="color: rgb(0, 119, 68); font-weight: bold;">character</span>'pos(<span style="color: rgb(0, 68, 221);"></span><span style="color: rgb(0, 68, 221);">'E'</span>),<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>)),<br />       <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(to_unsigned(<span style="color: rgb(0, 119, 68); font-weight: bold;">character</span>'pos(<span style="color: rgb(0, 68, 221);"></span><span style="color: rgb(0, 68, 221);">'F'</span>),<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>)));<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span><br />   do &lt;= BCDRom(to_integer(<span style="color: rgb(0, 119, 68); font-weight: bold;">unsigned</span>(di)));<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> Behavioral;</pre><pre><br /><span style="color: rgb(136, 136, 136);">-- Über eine when-else Anweisung --&gt; es wird ein Distributed BROM instatiiert</span><br /><span style="color: rgb(136, 136, 136);"></span><span style="color: rgb(136, 136, 136);">-- Maximum combinational path delay: 7.276ns</span><br /><span style="color: rgb(136, 136, 136);">-- Number of Slices         3</span><br /><span style="color: rgb(136, 136, 136);">-- Number of 4 input LUTs   6</span><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">architecture</span> Behavioral <span style="color: rgb(0, 136, 0); font-weight: bold;">of</span> BCD2ASCII <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span><br />     do &lt;= x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>30</span><span style="color: rgb(119, 17, 0);">&quot;</span></span> <span style="color: rgb(0, 136, 0); font-weight: bold;">when</span> di=x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>0</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>  <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>  <br />           x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>31</span><span style="color: rgb(119, 17, 0);">&quot;</span></span> <span style="color: rgb(0, 136, 0); font-weight: bold;">when</span> di=x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>1</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>  <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>  <br />           x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>32</span><span style="color: rgb(119, 17, 0);">&quot;</span></span> <span style="color: rgb(0, 136, 0); font-weight: bold;">when</span> di=x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>2</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>  <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>  <br />           x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>33</span><span style="color: rgb(119, 17, 0);">&quot;</span></span> <span style="color: rgb(0, 136, 0); font-weight: bold;">when</span> di=x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>3</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>  <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>  <br />           x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>34</span><span style="color: rgb(119, 17, 0);">&quot;</span></span> <span style="color: rgb(0, 136, 0); font-weight: bold;">when</span> di=x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>4</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>  <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>  <br />           x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>35</span><span style="color: rgb(119, 17, 0);">&quot;</span></span> <span style="color: rgb(0, 136, 0); font-weight: bold;">when</span> di=x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>5</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>  <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>  <br />           x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>36</span><span style="color: rgb(119, 17, 0);">&quot;</span></span> <span style="color: rgb(0, 136, 0); font-weight: bold;">when</span> di=x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>6</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>  <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>  <br />           x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>37</span><span style="color: rgb(119, 17, 0);">&quot;</span></span> <span style="color: rgb(0, 136, 0); font-weight: bold;">when</span> di=x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>7</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>  <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>  <br />           x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>38</span><span style="color: rgb(119, 17, 0);">&quot;</span></span> <span style="color: rgb(0, 136, 0); font-weight: bold;">when</span> di=x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>8</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>  <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>  <br />           x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>39</span><span style="color: rgb(119, 17, 0);">&quot;</span></span> <span style="color: rgb(0, 136, 0); font-weight: bold;">when</span> di=x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>9</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>  <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>  <br />           x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>41</span><span style="color: rgb(119, 17, 0);">&quot;</span></span> <span style="color: rgb(0, 136, 0); font-weight: bold;">when</span> di=x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>A</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>  <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>  <br />           x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>42</span><span style="color: rgb(119, 17, 0);">&quot;</span></span> <span style="color: rgb(0, 136, 0); font-weight: bold;">when</span> di=x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>B</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>  <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>  <br />           x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>43</span><span style="color: rgb(119, 17, 0);">&quot;</span></span> <span style="color: rgb(0, 136, 0); font-weight: bold;">when</span> di=x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>C</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>  <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>  <br />           x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>44</span><span style="color: rgb(119, 17, 0);">&quot;</span></span> <span style="color: rgb(0, 136, 0); font-weight: bold;">when</span> di=x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>D</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>  <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>  <br />           x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>45</span><span style="color: rgb(119, 17, 0);">&quot;</span></span> <span style="color: rgb(0, 136, 0); font-weight: bold;">when</span> di=x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>E</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>  <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>  <br />           x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>46</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>;<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> Behavioral;</pre><pre><br /><span style="color: rgb(136, 136, 136);">-- Mit Addierer, die Konstate 10 wird direkt vom ASCII-Wert 'A' abgezogen (selbe Klammerebene)</span><br /><span style="color: rgb(136, 136, 136);">-- Maximum combinational path delay: 7.276ns</span><br /><span style="color: rgb(136, 136, 136);"></span><span style="color: rgb(136, 136, 136);">-- Number of Slices         3</span><br /><span style="color: rgb(136, 136, 136);">-- Number of 4 input LUTs   6</span><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">architecture</span> Behavioral <span style="color: rgb(0, 136, 0); font-weight: bold;">of</span> BCD2ASCII <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span><br />     do &lt;= <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(resize(<span style="color: rgb(0, 119, 68); font-weight: bold;">unsigned</span>(di),<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>)+to_unsigned(<span style="color: rgb(0, 119, 68); font-weight: bold;">character</span>'pos(<span style="color: rgb(0, 68, 221);"></span><span style="color: rgb(0, 68, 221);">'A'</span>)-<span style="color: rgb(0, 0, 221); font-weight: bold;">10</span>,<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>))  <span style="color: rgb(0, 136, 0); font-weight: bold;">when</span> <span style="color: rgb(0, 119, 68); font-weight: bold;">unsigned</span>(di)&gt;<span style="color: rgb(0, 0, 221); font-weight: bold;">9</span>  <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>  <br />           <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(resize(<span style="color: rgb(0, 119, 68); font-weight: bold;">unsigned</span>(di),<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>)+to_unsigned(<span style="color: rgb(0, 119, 68); font-weight: bold;">character</span>'pos(<span style="color: rgb(0, 68, 221);"></span><span style="color: rgb(0, 68, 221);">'0'</span>),<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>));<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> Behavioral;<br /><br /><span style="color: rgb(136, 136, 136);">-- Wie vorher, die Konstate 10 wird aber auf einer anderen Klammerebene abgezogen --&gt; ein Subtrahierer wird instatiiert!</span><br /><span style="color: rgb(136, 136, 136);"></span><span style="color: rgb(136, 136, 136);">-- Maximum combinational path delay: 10.471ns</span><br /><span style="color: rgb(136, 136, 136);">-- Number of Slices         6</span><br /><span style="color: rgb(136, 136, 136);">-- Number of 4 input LUTs   10</span><br /><span style="color: rgb(136, 136, 136);">--architecture Behavioral of BCD2ASCII is</span><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span><br />     do &lt;= <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(resize(<span style="color: rgb(0, 119, 68); font-weight: bold;">unsigned</span>(di),<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>)+to_unsigned(<span style="color: rgb(0, 119, 68); font-weight: bold;">character</span>'pos(<span style="color: rgb(0, 68, 221);"></span><span style="color: rgb(0, 68, 221);">'A'</span>),<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>)-<span style="color: rgb(0, 0, 221); font-weight: bold;">10</span>)  <span style="color: rgb(0, 136, 0); font-weight: bold;">when</span> <span style="color: rgb(0, 119, 68); font-weight: bold;">unsigned</span>(di)&gt;<span style="color: rgb(0, 0, 221); font-weight: bold;">9</span>  <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span>  <br />           <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(resize(<span style="color: rgb(0, 119, 68); font-weight: bold;">unsigned</span>(di),<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>)+to_unsigned(<span style="color: rgb(0, 119, 68); font-weight: bold;">character</span>'pos(<span style="color: rgb(0, 68, 221);"></span><span style="color: rgb(0, 68, 221);">'0'</span>),<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span>));<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> Behavioral;<br /><span style="color: rgb(136, 136, 136);"></span></pre><hr size="2" width="100%" /><p>Die ersten 3 Lösungen resultieren in gleichem Ressourcenverbrauch und in
 der selben Geschwindigkeit.<br /><br />Sehr interessant ist aber der Unterschied zwischen der (optisch fast gleichen) 3. und 4. Lösung. Dort wurde nur die <b>Subtraktion der Konstante </b>10 etwas verlegt, und XST fügt dann in die Hardware einen Subtrahierer ein. Dadurch wird das Design größer und langsamer!<br /></p>
 
            </div>
        </content>
        
    </entry>
    <entry>
        <link href="http://www.lothar-miller.de/s9y/archives/75-PS2-Tastatur.html" rel="alternate" title="PS/2 Tastatur" />
        <author>
            <name>Lothar Miller</name>
                    </author>
    
        <published>2010-10-26T06:07:18Z</published>
        <updated>2010-10-26T06:59:32Z</updated>
        <wfw:comment>http://www.lothar-miller.de/s9y/wfwcomment.php?cid=75</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://www.lothar-miller.de/s9y/rss.php?version=atom1.0&amp;type=comments&amp;cid=75</wfw:commentRss>
    
            <category scheme="http://www.lothar-miller.de/s9y/categories/55-PS2" label="PS/2" term="PS/2" />
    
        <id>http://www.lothar-miller.de/s9y/archives/75-guid.html</id>
        <title type="html">PS/2 Tastatur</title>
        <content type="xhtml" xml:base="http://www.lothar-miller.de/s9y/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                
<p>Zur Eingabe von Daten bietet sich eine <b>PS/2 Tastatur</b> an. Die Dinger gibts für ein paar Euros und das Protokoll ist in der einfachsten Variante sehr überschaubar.</p><p>Ich habe hier mehrere Implementationen: die Erste ist sehr einfach gehalten und gibt alle empfangenen Scancodes incl. Break und Extended Keycodes einfach mit einem Handshake weiter an ein übergeordnetes Modul:</p><hr size="2" width="100%" /><pre><span style="color: rgb(0, 136, 0); font-weight: bold;">library</span> IEEE;<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.STD_LOGIC_1164.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>;<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.NUMERIC_STD.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>;<br /><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">entity</span> PS2_Keyboard <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span><br />    <span style="color: rgb(0, 136, 0); font-weight: bold;">Port</span> ( PS2_Data    : <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>;<br />           PS2_Clk     : <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>;<br />           RxData      : <span style="color: rgb(0, 136, 0); font-weight: bold;">out</span> <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(<span style="color: rgb(0, 0, 221); font-weight: bold;">7</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>);<br />           RxActive    : <span style="color: rgb(0, 136, 0); font-weight: bold;">out</span> <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>;<br />           DataReady   : <span style="color: rgb(0, 136, 0); font-weight: bold;">out</span> <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>; <span style="color: rgb(136, 136, 136);">-- Handshake-Signal: Daten bereit</span><br />           DataFetched : <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>; <span style="color: rgb(136, 136, 136);">-- Handshake-signal: Daten übernommen</span><br />           CLK         : <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>);<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> PS2_Keyboard;<br /><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">architecture</span> Behavioral <span style="color: rgb(0, 136, 0); font-weight: bold;">of</span> PS2_Keyboard <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> RxTimeout   : <span style="color: rgb(0, 119, 68); font-weight: bold;">integer</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">to</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">500000</span> := <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>; <span style="color: rgb(136, 136, 136);">-- max. 10ms</span><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> RxRegister  : <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(<span style="color: rgb(0, 0, 221); font-weight: bold;">10</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>) := (<span style="color: rgb(0, 136, 0); font-weight: bold;">others</span>=&gt;<span style="color: rgb(0, 68, 221);">'1'</span>);<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> DataSR      : <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>)  := (<span style="color: rgb(0, 136, 0); font-weight: bold;">others</span>=&gt;<span style="color: rgb(0, 68, 221);">'1'</span>);<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> ClkSR       : <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>)  := (<span style="color: rgb(0, 136, 0); font-weight: bold;">others</span>=&gt;<span style="color: rgb(0, 68, 221);">'1'</span>);<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">type</span> PS2RXStateType <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span> (IDLE, RECEIVE, READY); <br /><span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> PS2RXState : PS2RXStateType := IDLE;<br /><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span><br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span><br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">until</span> rising_edge(CLK);<br />      RxTimeout &lt;= RxTimeout+<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>;<br />      <br />      DataSR    &lt;= DataSR(<span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>) &amp; PS2_Data;<br />      ClkSR     &lt;= ClkSR(<span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>)  &amp; PS2_Clk;<br />      <br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (ClkSR = <span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>10</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span> <span style="color: rgb(136, 136, 136);">-- fallende Flanke am PS2_CLK</span><br />         RxRegister &lt;= DataSR(<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>) &amp; RxRegister(<span style="color: rgb(0, 0, 221); font-weight: bold;">10</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>);<br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>;<br /><br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">case</span> PS2RXState <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span><br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">when</span> IDLE =&gt;<br />         RxRegister &lt;= (<span style="color: rgb(0, 136, 0); font-weight: bold;">others</span>=&gt;<span style="color: rgb(0, 68, 221);">'1'</span>);<br />         RxActive   &lt;= <span style="color: rgb(0, 68, 221);">'0'</span>;<br />         DataReady  &lt;= <span style="color: rgb(0, 68, 221);">'0'</span>;<br />         RxTimeout  &lt;= <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>;<br />         <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (DataSR(<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>) = <span style="color: rgb(0, 68, 221);">'0'</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">and</span> ClkSR(<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>) = <span style="color: rgb(0, 68, 221);">'1'</span>) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span> <span style="color: rgb(136, 136, 136);">-- STARTBIT erkannt</span><br />            PS2RXState &lt;= RECEIVE;<br />            RxActive   &lt;= <span style="color: rgb(0, 68, 221);">'1'</span>;       <br />         <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>;<br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">when</span> RECEIVE =&gt;<br />         <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (RxTimeout = <span style="color: rgb(0, 0, 221); font-weight: bold;">500000</span>) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span>     <span style="color: rgb(136, 136, 136);">-- 10 ms</span><br />            PS2RXState &lt;= IDLE;<br />         <span style="color: rgb(0, 136, 0); font-weight: bold;">elsif</span> (RxRegister(<span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>) = <span style="color: rgb(0, 68, 221);">'0'</span>) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span> <span style="color: rgb(136, 136, 136);">-- Startbit ganz durchgeschoben?</span><br />            DataReady  &lt;= <span style="color: rgb(0, 68, 221);">'1'</span>;            <span style="color: rgb(136, 136, 136);">-- SCANCODE empfangen</span><br />            RxData     &lt;= RxRegister(<span style="color: rgb(0, 0, 221); font-weight: bold;">8</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>);<br />            PS2RXState &lt;= READY;<br />         <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>;<br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">when</span> READY =&gt;                       <span style="color: rgb(136, 136, 136);">-- warten, bis Daten abgeholt sind</span><br />         <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (DataFetched=<span style="color: rgb(0, 68, 221);">'1'</span>) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span><br />            PS2RXState &lt;= IDLE;<br />            DataReady  &lt;= <span style="color: rgb(0, 68, 221);">'0'</span>;<br />            RxActive   &lt;= <span style="color: rgb(0, 68, 221);">'0'</span>;            <br />         <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>;<br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">case</span>;<br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span>;<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> Behavioral;</pre><hr size="2" width="100%" /><p><br />Realisiert wurde dieses PS/2 Interface in Form eines 11 Bit breiten Schieberegisters, das zu Beginn im Zustand IDLE mit '1'en vorbelegt wird. Mit jeder fallenden Flanke am PS2-Clk wird dieses Schieberegister um 1 Bit von links her weitergeschoben. In das MSB wird dabei der Zustand des einsynchronisierten PS2-Data Pins eingetragen. <br />Nachdem ein Startbit erkannt wurde, wechselt der Zustand auf RECEIVE und es werden solange Bits eingeschoben, bis das Startbit das rechte Ende (Bit0) des Schieberegisters erreicht hat. Dann werden die Daten in das Pufferregister übernommen und im Zustand READY gewartet, bis die Daten abgeholt sind.<br /><br />Zusammen mit dieser Testbench:</p><hr size="2" width="100%" /><pre><span style="color: rgb(0, 136, 0); font-weight: bold;">LIBRARY</span> ieee;<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">USE</span> ieee.std_logic_1164.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>;<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">USE</span> ieee.numeric_std.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>;<br /> <br /><span style="color: rgb(0, 136, 0); font-weight: bold;">ENTITY</span> PS2_tb <span style="color: rgb(0, 136, 0); font-weight: bold;">IS</span><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">END</span> PS2_tb;<br /> <br /><span style="color: rgb(0, 136, 0); font-weight: bold;">ARCHITECTURE</span> behavior <span style="color: rgb(0, 136, 0); font-weight: bold;">OF</span> PS2_tb <span style="color: rgb(0, 136, 0); font-weight: bold;">IS</span> <br /> <br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">procedure</span> PS2Send( <span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> din :  <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span> <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(<span style="color: rgb(0, 0, 221); font-weight: bold;">7</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>); <br />                      <span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> ps2c : <span style="color: rgb(0, 136, 0); font-weight: bold;">OUT</span> <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>;<br />                      <span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> ps2d : <span style="color: rgb(0, 136, 0); font-weight: bold;">OUT</span> <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>) <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span><br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">variable</span> parity : <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span> := <span style="color: rgb(0, 68, 221);">'1'</span>;<br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span><br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">1</span> ns;<br />      ps2c  &lt;= <span style="color: rgb(0, 68, 221);">'1'</span>;<br />      ps2d  &lt;= <span style="color: rgb(0, 68, 221);">'1'</span>;<br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">5</span>us;<br />      ps2d  &lt;= <span style="color: rgb(0, 68, 221);">'0'</span>;  <span style="color: rgb(136, 136, 136);">-- startbit</span><br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">20</span>us;<br />      ps2c  &lt;= <span style="color: rgb(0, 68, 221);">'0'</span>;<br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">40</span>us;<br />      ps2c  &lt;= <span style="color: rgb(0, 68, 221);">'1'</span>;<br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">20</span>us;<br />      <br />      parity := <span style="color: rgb(0, 68, 221);">'1'</span>;<br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> i <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">to</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">7</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">loop</span><br />         ps2d &lt;= din(i);<br />         <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>(din(i)=<span style="color: rgb(0, 68, 221);">'1'</span>) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span> <br />            parity := <span style="color: rgb(0, 136, 0); font-weight: bold;">not</span> parity; <br />         <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>;<br />         <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">20</span>us;<br />         ps2c  &lt;= <span style="color: rgb(0, 68, 221);">'0'</span>;<br />         <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">40</span>us;<br />         ps2c  &lt;= <span style="color: rgb(0, 68, 221);">'1'</span>;<br />         <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">20</span>us;<br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">loop</span>;<br />      <br />      ps2d &lt;= parity;  <span style="color: rgb(136, 136, 136);">-- parity</span><br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">20</span>us;<br />      ps2c  &lt;= <span style="color: rgb(0, 68, 221);">'0'</span>;<br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">40</span>us;<br />      ps2c  &lt;= <span style="color: rgb(0, 68, 221);">'1'</span>;<br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">20</span>us;<br />   <br />      ps2d &lt;= <span style="color: rgb(0, 68, 221);">'1'</span>;     <span style="color: rgb(136, 136, 136);">-- stopbit</span><br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">20</span>us;<br />      ps2c  &lt;= <span style="color: rgb(0, 68, 221);">'0'</span>;<br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">40</span>us;<br />      ps2c  &lt;= <span style="color: rgb(0, 68, 221);">'1'</span>;<br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">20</span>us;<br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">procedure</span>;<br />   <br />    <span style="color: rgb(136, 136, 136);">-- Component Declaration for the Unit Under Test (UUT)</span><br />    <span style="color: rgb(0, 136, 0); font-weight: bold;">COMPONENT</span> PS2_Keyboard<br />    <span style="color: rgb(0, 136, 0); font-weight: bold;">PORT</span>(<br />         PS2_Data : <span style="color: rgb(0, 136, 0); font-weight: bold;">IN</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>;<br />         PS2_Clk : <span style="color: rgb(0, 136, 0); font-weight: bold;">IN</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>;<br />         RxData : <span style="color: rgb(0, 136, 0); font-weight: bold;">OUT</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(<span style="color: rgb(0, 0, 221); font-weight: bold;">7</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>);<br />         RxActive : <span style="color: rgb(0, 136, 0); font-weight: bold;">OUT</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>;<br />         DataReady : <span style="color: rgb(0, 136, 0); font-weight: bold;">OUT</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>;<br />         DataFetched : <span style="color: rgb(0, 136, 0); font-weight: bold;">IN</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>;<br />         CLK : <span style="color: rgb(0, 136, 0); font-weight: bold;">IN</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span><br />        );<br />    <span style="color: rgb(0, 136, 0); font-weight: bold;">END</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">COMPONENT</span>;<br />    <br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> TxData : <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(<span style="color: rgb(0, 0, 221); font-weight: bold;">7</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>);<br /><br />   <span style="color: rgb(136, 136, 136);">--Inputs</span><br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> PS2_Data : <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span> := <span style="color: rgb(0, 68, 221);">'1'</span>;<br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> PS2_Clk : <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span> := <span style="color: rgb(0, 68, 221);">'1'</span>;<br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> DataFetched : <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span> := <span style="color: rgb(0, 68, 221);">'0'</span>;<br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> CLK : <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span> := <span style="color: rgb(0, 68, 221);">'0'</span>;<br /><br />    <span style="color: rgb(136, 136, 136);">--Outputs</span><br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> RxData : <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(<span style="color: rgb(0, 0, 221); font-weight: bold;">7</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>);<br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> RxActive : <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>;<br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> DataReady : <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic</span>;<br /><br />   <span style="color: rgb(136, 136, 136);">-- Clock period definitions</span><br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">constant</span> CLK_period : <span style="color: rgb(0, 119, 68); font-weight: bold;">time</span> := <span style="color: rgb(0, 0, 221); font-weight: bold;">20</span> ns; <span style="color: rgb(136, 136, 136);">-- 50MHz</span><br /> <br /><span style="color: rgb(0, 136, 0); font-weight: bold;">BEGIN</span><br /> <br />   <span style="color: rgb(136, 136, 136);">-- Instantiate the Unit Under Test (UUT)</span><br />   uut: PS2_Keyboard <span style="color: rgb(0, 136, 0); font-weight: bold;">PORT</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">MAP</span> (<br />          PS2_Data =&gt; PS2_Data,<br />          PS2_Clk =&gt; PS2_Clk,<br />          RxData =&gt; RxData,<br />          RxActive =&gt; RxActive,<br />          DataReady =&gt; DataReady,<br />          DataFetched =&gt; DataFetched,<br />          CLK =&gt; CLK<br />        );<br /><br />   <span style="color: rgb(136, 136, 136);">-- Clock process definitions</span><br />   CLK &lt;= <span style="color: rgb(0, 136, 0); font-weight: bold;">not</span> CLK <span style="color: rgb(0, 136, 0); font-weight: bold;">after</span> CLK_period/<span style="color: rgb(0, 0, 221); font-weight: bold;">2</span>;<br /><br />   <span style="color: rgb(136, 136, 136);">-- Stimulus process</span><br />   DataFetched &lt;= DataReady <span style="color: rgb(0, 136, 0); font-weight: bold;">after</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">10</span> us; <span style="color: rgb(136, 136, 136);">-- fake handshake</span><br />   <br />   stim_proc: <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span><br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span>      <br />      <span style="color: rgb(136, 136, 136);">-- hold reset state for 100 ns.</span><br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">100</span> ns;   <br />      <br />      TXData&lt;=x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>AA</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>;<br />      PS2Send(TXData,PS2_Clk,PS2_Data);<br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">100</span> us;   <br /><br />      TXData&lt;=x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>55</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>;<br />      PS2Send(TXData,PS2_Clk,PS2_Data);<br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">100</span> us;   <br /><br />      TXData&lt;=x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>11</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>;<br />      PS2Send(TXData,PS2_Clk,PS2_Data);<br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">100</span> us;   <br /><br />      TXData&lt;=x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>80</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>;<br />      PS2Send(TXData,PS2_Clk,PS2_Data);<br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">100</span> us;   <br /><br />      TXData&lt;=x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>01</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>;<br />      PS2Send(TXData,PS2_Clk,PS2_Data);<br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">100</span> us;   <br /><br />      TXData&lt;=x<span style="background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);"><span style="color: rgb(119, 17, 0);">&quot;</span><span>C3</span><span style="color: rgb(119, 17, 0);">&quot;</span></span>;<br />      PS2Send(TXData,PS2_Clk,PS2_Data);<br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">for</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">100</span> us;   <br />      <br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span>;<br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span>;<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">END</span>;</pre><hr size="2" width="100%" /><p>ergibt sich dann folgende Waveform:</p><div class="serendipity_imageComment_center" style="width: 750px;"><div class="serendipity_imageComment_img"><!-- s9ymdb:136 --><img height="213" width="750" class="serendipity_image_center" src="http://www.lothar-miller.de/s9y/uploads/Bilder/WF_PS2_Simulation.gif" /></div><div class="serendipity_imageComment_txt">Waveform Simulation PS2 Interface</div></div><br /><p>Hier die zusammengepackte Quelldatei und die passende Testbench: <br />
Download <a target="_blank" title="PS2_Simplest.zip" href="http://www.lothar-miller.de/s9y/uploads/Bilder/PS2_Simplest.zip">PS2_Simplest.zip</a></p><p>In der zweiten Variante werden die Steuerkommandos (Break und Extended Keycode) in Flags umgewandelt: <br />Download <a target="_blank" title="PS2_Simple.zip" href="http://www.lothar-miller.de/s9y/uploads/Bilder/PS2_Simple.zip">PS2_Simple.zip</a></p><p>Die dritte Variante schliesslich erlaubt auch das Senden von Kommandos an die Tastatur. Damit können dann z.B. die LEDs auf der Tastatur an- und ausgeschaltet werden.<br />Download <a target="_blank" title="PS2_Full.zip" href="http://www.lothar-miller.de/s9y/uploads/Bilder/PS2_Full.zip">PS2_Full.zip</a></p>
 
            </div>
        </content>
        
    </entry>
    <entry>
        <link href="http://www.lothar-miller.de/s9y/archives/73-Wurzel-in-VHDL.html" rel="alternate" title="Wurzel in VHDL" />
        <author>
            <name>Lothar Miller</name>
                    </author>
    
        <published>2010-08-03T16:44:00Z</published>
        <updated>2010-08-04T11:44:40Z</updated>
        <wfw:comment>http://www.lothar-miller.de/s9y/wfwcomment.php?cid=73</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://www.lothar-miller.de/s9y/rss.php?version=atom1.0&amp;type=comments&amp;cid=73</wfw:commentRss>
    
            <category scheme="http://www.lothar-miller.de/s9y/categories/24-Rechnen" label="Rechnen " term="Rechnen " />
    
        <id>http://www.lothar-miller.de/s9y/archives/73-guid.html</id>
        <title type="html">Wurzel in VHDL</title>
        <content type="xhtml" xml:base="http://www.lothar-miller.de/s9y/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                
<p>Eine Wurzel zu ziehen kann recht aufwendig sein. Erschwert wird das Ganze, wenn es in VHDL geschehen soll. Hier eine Gegenüberstellung des Ressourcenverbrauchs einer rein kombinatorischen Lösung verglichen mit einer sequentiellen getakteten Variante in einem Xilinx Spartan3 XC3S200 FPGA. <br /><br />Hier als Bezugspunkt die parallel implementierte kombinatorische Lösung:</p><hr size="2" width="100%" /><pre><span style="color: rgb(0, 136, 0); font-weight: bold;">library</span> IEEE;<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.STD_LOGIC_1164.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>;<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.NUMERIC_STD.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>;<br /><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">entity</span> SQRT <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span><br />    <span style="color: rgb(0, 136, 0); font-weight: bold;">Generic</span> ( b  : <span style="color: rgb(0, 119, 68); font-weight: bold;">natural</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">4</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">to</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">32</span> := <span style="color: rgb(0, 0, 221); font-weight: bold;">16</span> ); <span style="color: rgb(136, 136, 136);">-- Breite </span><br />    <span style="color: rgb(0, 136, 0); font-weight: bold;">Port</span> ( value  : <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span>   <span style="color: rgb(0, 119, 68); font-weight: bold;">STD_LOGIC_VECTOR</span> (<span style="color: rgb(0, 0, 221); font-weight: bold;">15</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>);<br />           result : <span style="color: rgb(0, 136, 0); font-weight: bold;">out</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">STD_LOGIC_VECTOR</span> (<span style="color: rgb(0, 0, 221); font-weight: bold;">7</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>));<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> SQRT;<br /><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">architecture</span> Behave <span style="color: rgb(0, 136, 0); font-weight: bold;">of</span> SQRT <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span><br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span> (value)<br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">variable</span> vop  : <span style="color: rgb(0, 119, 68); font-weight: bold;">unsigned</span>(b-<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>);  <br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">variable</span> vres : <span style="color: rgb(0, 119, 68); font-weight: bold;">unsigned</span>(b-<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>);  <br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">variable</span> vone : <span style="color: rgb(0, 119, 68); font-weight: bold;">unsigned</span>(b-<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>);  <br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span><br />      vone := to_unsigned(<span style="color: rgb(0, 0, 221); font-weight: bold;">2</span>**(b-<span style="color: rgb(0, 0, 221); font-weight: bold;">2</span>),b);<br />      vop  := <span style="color: rgb(0, 119, 68); font-weight: bold;">unsigned</span>(value);<br />      vres := (<span style="color: rgb(0, 136, 0); font-weight: bold;">others</span>=&gt;<span style="color: rgb(0, 68, 221);">'0'</span>); <br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">while</span> (vone /= <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>) <span style="color: rgb(0, 136, 0); font-weight: bold;">loop</span><br />         <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (vop &gt;= vres+vone) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span><br />            vop   := vop - (vres+vone);<br />            vres  := vres/<span style="color: rgb(0, 0, 221); font-weight: bold;">2</span> + vone;<br />         <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span><br />            vres  := vres/<span style="color: rgb(0, 0, 221); font-weight: bold;">2</span>;<br />         <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>;<br />         vone := vone/<span style="color: rgb(0, 0, 221); font-weight: bold;">4</span>;<br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">loop</span>;<br />      result &lt;= <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(vres(result<span style="color: rgb(0, 68, 221);">'r</span>ange));<br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span>;<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">end</span>;</pre><hr size="2" width="100%" /><p>Mit diesem Ansatz ergibt sich folgender Ressourcenbedarf:</p><p /><div style="width: 586px;" class="serendipity_imageComment_center"><div class="serendipity_imageComment_img"><!-- s9ymdb:133 --><img height="248" width="586" src="http://www.lothar-miller.de/s9y/uploads/Bilder/Ressourcen_komb.gif" class="serendipity_image_center" /></div><div class="serendipity_imageComment_txt">So eine Wurzel braucht schon Platz...</div></div><br /><p /><p>Und jetzt zum Vergleich die Variante mit der getakteten Berechnung der Wurzel:</p><hr size="2" width="100%" /><pre><span style="color: rgb(0, 136, 0); font-weight: bold;">library</span> IEEE;<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.STD_LOGIC_1164.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>;<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">use</span> IEEE.NUMERIC_STD.<span style="color: rgb(0, 136, 0); font-weight: bold;">ALL</span>;<br /><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">entity</span> SQRT <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span><br />    <span style="color: rgb(0, 136, 0); font-weight: bold;">Generic</span> ( b  : <span style="color: rgb(0, 119, 68); font-weight: bold;">natural</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">4</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">to</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">32</span> := <span style="color: rgb(0, 0, 221); font-weight: bold;">16</span> ); <span style="color: rgb(136, 136, 136);">-- Breite </span><br />    <span style="color: rgb(0, 136, 0); font-weight: bold;">Port</span> ( clk    : <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span>   <span style="color: rgb(0, 119, 68); font-weight: bold;">STD_LOGIC</span>;<br />           start  : <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span>   <span style="color: rgb(0, 119, 68); font-weight: bold;">STD_LOGIC</span>;<br />           value  : <span style="color: rgb(0, 136, 0); font-weight: bold;">in</span>   <span style="color: rgb(0, 119, 68); font-weight: bold;">STD_LOGIC_VECTOR</span> (<span style="color: rgb(0, 0, 221); font-weight: bold;">15</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>);<br />           result : <span style="color: rgb(0, 136, 0); font-weight: bold;">out</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">STD_LOGIC_VECTOR</span> (<span style="color: rgb(0, 0, 221); font-weight: bold;">7</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>);<br />           busy   : <span style="color: rgb(0, 136, 0); font-weight: bold;">out</span>  <span style="color: rgb(0, 119, 68); font-weight: bold;">STD_LOGIC</span>);<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> SQRT;<br /><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">architecture</span> Behave <span style="color: rgb(0, 136, 0); font-weight: bold;">of</span> SQRT <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> op  : <span style="color: rgb(0, 119, 68); font-weight: bold;">unsigned</span>(b-<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>); <span style="color: rgb(136, 136, 136);">-- </span><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> res : <span style="color: rgb(0, 119, 68); font-weight: bold;">unsigned</span>(b-<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>); <span style="color: rgb(136, 136, 136);">-- </span><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> one : <span style="color: rgb(0, 119, 68); font-weight: bold;">unsigned</span>(b-<span style="color: rgb(0, 0, 221); font-weight: bold;">1</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>); <span style="color: rgb(136, 136, 136);">-- </span><br /><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> bits : <span style="color: rgb(0, 119, 68); font-weight: bold;">integer</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">range</span> b <span style="color: rgb(0, 136, 0); font-weight: bold;">downto</span> <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>;<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">type</span> zustaende <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span> (idle, shift, calc, done);<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">signal</span> z : zustaende;<br /><br /><span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span><br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">begin</span><br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">wait</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">until</span> rising_edge(clk);<br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">case</span> z <span style="color: rgb(0, 136, 0); font-weight: bold;">is</span> <br />         <span style="color: rgb(0, 136, 0); font-weight: bold;">when</span> idle =&gt; <br />            <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (start=<span style="color: rgb(0, 68, 221);">'1'</span>) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span> <br />               z &lt;= shift; <br />               busy &lt;= <span style="color: rgb(0, 68, 221);">'1'</span>;<br />            <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>;<br />            one &lt;= to_unsigned(<span style="color: rgb(0, 0, 221); font-weight: bold;">2</span>**(b-<span style="color: rgb(0, 0, 221); font-weight: bold;">2</span>),b);<br />            op  &lt;= <span style="color: rgb(0, 119, 68); font-weight: bold;">unsigned</span>(value);<br />            res &lt;= (<span style="color: rgb(0, 136, 0); font-weight: bold;">others</span>=&gt;<span style="color: rgb(0, 68, 221);">'0'</span>);<br /><br />         <span style="color: rgb(0, 136, 0); font-weight: bold;">when</span> shift =&gt;<br />            <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (one &gt; op) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span><br />               one &lt;= one/<span style="color: rgb(0, 0, 221); font-weight: bold;">4</span>;<br />            <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span><br />               z   &lt;= calc;<br />            <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>;<br /><br />         <span style="color: rgb(0, 136, 0); font-weight: bold;">when</span> calc =&gt;<br />            <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (one /= <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span><br />               <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (op &gt;= res+one) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span><br />                  op   &lt;= op - (res+one);<br />                  res  &lt;= res/<span style="color: rgb(0, 0, 221); font-weight: bold;">2</span> + one;<br />               <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span><br />                  res  &lt;= res/<span style="color: rgb(0, 0, 221); font-weight: bold;">2</span>;<br />               <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>;<br />               one &lt;= one/<span style="color: rgb(0, 0, 221); font-weight: bold;">4</span>;<br />            <span style="color: rgb(0, 136, 0); font-weight: bold;">else</span><br />               z    &lt;= done;<br />            <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>;<br />            <br />         <span style="color: rgb(0, 136, 0); font-weight: bold;">when</span> done =&gt;<br />            busy &lt;= <span style="color: rgb(0, 68, 221);">'0'</span>;<br />            <span style="color: rgb(136, 136, 136);">-- Handshake: wenn nötig warten, bis start='0'</span><br />            <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (start=<span style="color: rgb(0, 68, 221);">'0'</span>) <span style="color: rgb(0, 136, 0); font-weight: bold;">then</span> <br />               z &lt;= idle; <br />            <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span>;<br />      <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">case</span>;<br />   <span style="color: rgb(0, 136, 0); font-weight: bold;">end</span> <span style="color: rgb(0, 136, 0); font-weight: bold;">process</span>;<br />   <br />   result &lt;= <span style="color: rgb(0, 119, 68); font-weight: bold;">std_logic_vector</span>(res(result<span style="color: rgb(0, 68, 221);">'r</span>ange));<br /><span style="color: rgb(0, 136, 0); font-weight: bold;">end</span>;</pre><hr size="2" width="100%" /><p>Das Design Summary zeigt jetzt einen deutlich kleineren Ressourcenverbrauch an, wobei der Verbrauch an Slices insgesamt nicht mal so sehr viel höher ist:</p><p /><div style="width: 655px;" class="serendipity_imageComment_center"><div class="serendipity_imageComment_img"><!-- s9ymdb:134 --><img height="292" width="655" src="http://www.lothar-miller.de/s9y/uploads/Bilder/Ressourcen_synchron.gif" class="serendipity_image_center" /></div><div class="serendipity_imageComment_txt">... aber es geht auch wesentlich kompakter</div></div><p /><hr size="2" width="100%" /><p><br />Die Wurzelberechnung basiert auf diesem C Code:</p><hr size="2" width="100%" /><pre><span style="color: rgb(0, 119, 68); font-weight: bold;">int</span> sqrt(<span style="color: rgb(0, 119, 68); font-weight: bold;">int</span> num) {<br />    <span style="color: rgb(0, 119, 68); font-weight: bold;">int</span> op = num;<br />    <span style="color: rgb(0, 119, 68); font-weight: bold;">int</span> res = <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>;<br />    <span style="color: rgb(0, 119, 68); font-weight: bold;">int</span> one = <span style="color: rgb(0, 0, 221); font-weight: bold;">1</span> &lt;&lt; <span style="color: rgb(0, 0, 221); font-weight: bold;">30</span>; <span style="color: rgb(136, 136, 136);">// The second-to-top bit is set: 1L&lt;&lt;30 for long</span><br /><br />    <span style="color: rgb(136, 136, 136);">// &quot;one&quot; starts at the highest power of four &lt;= the argument.</span><br />    <span style="color: rgb(0, 136, 0); font-weight: bold;">while</span> (one &gt; op)<br />        one &gt;&gt;= <span style="color: rgb(0, 0, 221); font-weight: bold;">2</span>;<br />   <br />    <span style="color: rgb(0, 136, 0); font-weight: bold;">while</span> (one != <span style="color: rgb(0, 0, 221); font-weight: bold;">0</span>) {<br />        <span style="color: rgb(0, 136, 0); font-weight: bold;">if</span> (op &gt;= res + one) {<br />            op -= res + one;<br />            res += <span style="color: rgb(0, 0, 221); font-weight: bold;">2</span> * one;<br />        }<br />        res &gt;&gt;= <span style="color: rgb(0, 0, 221); font-weight: bold;">1</span>;<br />        one &gt;&gt;= <span style="color: rgb(0, 0, 221); font-weight: bold;">2</span>;<br />    }<br />    <span style="color: rgb(0, 136, 0); font-weight: bold;">return</span> res;<br />}</pre><hr size="2" width="100%" /><pre><font face="verdana,arial,geneva,helvetica,sans-serif"></font></pre> 
            </div>
        </content>
        
    </entry>

</feed>
