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

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

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

<item>
    <title>RS232 IO</title>
    <link>http://www.lothar-miller.de/s9y/archives/60-RS232-IO.html</link>
            <category>RS232 IO</category>
    
    <comments>http://www.lothar-miller.de/s9y/archives/60-RS232-IO.html#comments</comments>
    <wfw:comment>http://www.lothar-miller.de/s9y/wfwcomment.php?cid=60</wfw:comment>

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

    <author>nospam@example.com (Lothar Miller)</author>
    <content:encoded>
    
&lt;p&gt;Ein CPLD eignet sich glänzend, um eine &lt;b&gt;serielle-IO Schnittstelle&lt;/b&gt; zu implementieren. Hier werden über ein Xilinx XC9536 &lt;b&gt;8 Ausgänge&lt;/b&gt; und &lt;b&gt;8 Eingänge&lt;/b&gt; an die RS232 Schnittstelle z.B. eines PCs angeschlossen. Über ein Terminalprogramm oder ein selbst geschriebenes Programm kann dann auf diese Ports zugegriffen werden.&lt;/p&gt;&lt;p&gt;Die (von mir getesteten) &lt;b&gt;Übertragungsdaten &lt;/b&gt;sind: Baudrate 9600, 8 Datenbits, keine Parity, 1 Stopbit.&lt;br /&gt;Die &lt;b&gt;Takterzeugung &lt;/b&gt;erfolgte bei Testaufbau recht rustikal über einen CMOS-Timer ICM7555, der auf einen Takt von 8*9600 = 76800 Hz eingestellt wird.&lt;/p&gt;&lt;p&gt;Schreiben der &lt;b&gt;Ausgänge&lt;/b&gt;: jedes über RS232 gesendete Bit wird sofort nach der Übertragung auf den entsprechenden Ausgang abgebildet. So werden 8 FFs gespart, die sonst für die Zwischenpufferung in einem Schieberegister nötig wären.&lt;br /&gt;Lesen der &lt;b&gt;Eingänge&lt;/b&gt;: beim Erkennen eines Startbits auf der RXD-Leitung wird die Übertragung der Eingänge angestoßen. Die 8 Eingänge können also nur über das Senden eines Zeichens über die RS232 Schnittstelle abgefragt werden.&lt;/p&gt;&lt;p&gt;Hier der VHDL-Code:
&lt;/p&gt;&lt;hr size=&quot;2&quot; width=&quot;100%&quot; /&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;library&lt;/span&gt; &lt;span&gt;IEEE&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;use&lt;/span&gt; &lt;span&gt;IEEE&lt;/span&gt;.&lt;span&gt;STD_LOGIC_1164&lt;/span&gt;.&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;ALL&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;use&lt;/span&gt; &lt;span&gt;IEEE&lt;/span&gt;.&lt;span&gt;NUMERIC_STD&lt;/span&gt;.&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;ALL&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;entity&lt;/span&gt; &lt;span&gt;RS232IO&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;is&lt;/span&gt;&lt;br /&gt;    &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;Port&lt;/span&gt; ( &lt;span&gt;clk&lt;/span&gt;  : &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;in&lt;/span&gt;  &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;STD_LOGIC&lt;/span&gt;;&lt;br /&gt;           &lt;span&gt;TXD&lt;/span&gt;  : &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;out&lt;/span&gt; &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;STD_LOGIC&lt;/span&gt; := &lt;span style=&quot;color: rgb(0, 68, 221);&quot;&gt;&#039;1&#039;&lt;/span&gt;;&lt;br /&gt;           &lt;span&gt;RXD&lt;/span&gt;  : &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;in&lt;/span&gt;  &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;STD_LOGIC&lt;/span&gt;;&lt;br /&gt;           &lt;span&gt;din&lt;/span&gt;  : &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;in&lt;/span&gt;  &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;STD_LOGIC_VECTOR&lt;/span&gt; (&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;7&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;);&lt;br /&gt;           &lt;span&gt;dout&lt;/span&gt; : &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;out&lt;/span&gt; &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;STD_LOGIC_VECTOR&lt;/span&gt; (&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;7&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;) := &lt;span style=&quot;background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);&quot;&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;00000000&lt;/span&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;);&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span&gt;RS232IO&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;architecture&lt;/span&gt; &lt;span&gt;Behavioral&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;of&lt;/span&gt; &lt;span&gt;RS232IO&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;is&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;signal&lt;/span&gt; &lt;span&gt;prescaler&lt;/span&gt; : &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt;(&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;2&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;) := &lt;span style=&quot;background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);&quot;&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;000&lt;/span&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;;            &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- clk = 8*Baudrate&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;signal&lt;/span&gt; &lt;span&gt;txsr&lt;/span&gt;      : &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt;(&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;8&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;) := &lt;span style=&quot;background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);&quot;&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;111111111&lt;/span&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;;  &lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;signal&lt;/span&gt; &lt;span&gt;rxd_sr&lt;/span&gt;    : &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;std_logic_vector&lt;/span&gt; (&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;3&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;) := &lt;span style=&quot;background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);&quot;&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;1111&lt;/span&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;;  &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- Flankenerkennung und Eintakten&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;signal&lt;/span&gt; &lt;span&gt;start  &lt;/span&gt;   : &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;std_logic&lt;/span&gt; := &lt;span style=&quot;color: rgb(0, 68, 221);&quot;&gt;&#039;0&#039;&lt;/span&gt;; &lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;signal&lt;/span&gt; &lt;span&gt;rxdat&lt;/span&gt;     : &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;std_logic_vector&lt;/span&gt; (&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;8&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;) := &lt;span style=&quot;background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);&quot;&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;000000000&lt;/span&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;; &lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;signal&lt;/span&gt; &lt;span&gt;rxbitcnt&lt;/span&gt;  : &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;integer&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;range&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;to&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;9&lt;/span&gt; := &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;9&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;begin&lt;/span&gt;&lt;br /&gt;   &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- Senden&lt;/span&gt;&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;process&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;begin&lt;/span&gt;&lt;br /&gt;      &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;until&lt;/span&gt; &lt;span&gt;rising_edge&lt;/span&gt;(&lt;span&gt;clk&lt;/span&gt;);&lt;br /&gt;      &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt; (&lt;span&gt;start&lt;/span&gt; = &lt;span style=&quot;color: rgb(0, 68, 221);&quot;&gt;&#039;1&#039;&lt;/span&gt;) &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;then&lt;/span&gt;                      &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- fallende Flanke Startbit erkannt&lt;/span&gt;&lt;br /&gt;         &lt;span&gt;txsr&lt;/span&gt; &amp;lt;= &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;unsigned&lt;/span&gt;(&lt;span&gt;din&lt;/span&gt;) &amp;amp; &lt;span style=&quot;color: rgb(0, 68, 221);&quot;&gt;&#039;0&#039;&lt;/span&gt;;            &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- MSB zuerst: Stopbit, 8 Datenbits, Startbit&lt;/span&gt;&lt;br /&gt;      &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;elsif&lt;/span&gt; (&lt;span&gt;prescaler&lt;/span&gt;=&lt;span style=&quot;background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);&quot;&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;000&lt;/span&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;) &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;then&lt;/span&gt;&lt;br /&gt;         &lt;span&gt;txsr&lt;/span&gt; &amp;lt;= &lt;span style=&quot;color: rgb(0, 68, 221);&quot;&gt;&#039;1&#039;&lt;/span&gt; &amp;amp; &lt;span&gt;txsr&lt;/span&gt;(&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;8&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;);         &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- MSB zuerst --&amp;gt; nach rechts schieben&lt;/span&gt;&lt;br /&gt;      &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt;;&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;process&lt;/span&gt;;&lt;br /&gt;   &lt;span&gt;TXD&lt;/span&gt; &amp;lt;= &lt;span&gt;txsr&lt;/span&gt;(&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;   &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- Empfangen&lt;/span&gt;&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;process&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;begin&lt;/span&gt;&lt;br /&gt;      &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;wait&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;until&lt;/span&gt; &lt;span&gt;rising_edge&lt;/span&gt;(&lt;span&gt;CLK&lt;/span&gt;);&lt;br /&gt;      &lt;span&gt;prescaler&lt;/span&gt; &amp;lt;= &lt;span&gt;prescaler&lt;/span&gt;+&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;;&lt;br /&gt;      &lt;span&gt;rxd_sr&lt;/span&gt; &amp;lt;= &lt;span&gt;rxd_sr&lt;/span&gt;(&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;2&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;) &amp;amp; &lt;span&gt;RXD&lt;/span&gt;;&lt;br /&gt;      &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt; (&lt;span&gt;rxd_sr&lt;/span&gt; = &lt;span style=&quot;background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);&quot;&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;1000&lt;/span&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;and&lt;/span&gt; &lt;span&gt;rxbitcnt&lt;/span&gt;=&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;9&lt;/span&gt;) &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;then&lt;/span&gt;   &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- fallende Flanke = Startbit&lt;/span&gt;&lt;br /&gt;         &lt;span&gt;start&lt;/span&gt; &amp;lt;= &lt;span style=&quot;color: rgb(0, 68, 221);&quot;&gt;&#039;1&#039;&lt;/span&gt;;                           &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- 1 FF nötig wegen evtl. Glitches auf Kombinatorik&lt;/span&gt;&lt;br /&gt;      &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt;; &lt;br /&gt;      &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt; (&lt;span&gt;rxbitcnt&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;9&lt;/span&gt;) &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;then&lt;/span&gt;                       &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- Empfang läuft&lt;/span&gt;&lt;br /&gt;         &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt; (&lt;span&gt;prescaler&lt;/span&gt;=&lt;span style=&quot;background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);&quot;&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;100&lt;/span&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;) &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;then&lt;/span&gt;               &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- In der Bitmitte abtasten&lt;/span&gt;&lt;br /&gt;            &lt;span&gt;rxdat&lt;/span&gt;(&lt;span&gt;rxbitcnt&lt;/span&gt;) &amp;lt;= &lt;span&gt;rxd_sr&lt;/span&gt;(&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;3&lt;/span&gt;);        &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- Jedes Bit wird sofort nach Empfang ausgegeben --&amp;gt; kein Schieberegister nötig, MUX spart FFs&lt;/span&gt;&lt;br /&gt;            &lt;span&gt;rxbitcnt&lt;/span&gt; &amp;lt;= &lt;span&gt;rxbitcnt&lt;/span&gt;+&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;;&lt;br /&gt;         &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt;;&lt;br /&gt;      &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;else&lt;/span&gt;                                       &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- warten auf Startbit&lt;/span&gt;&lt;br /&gt;         &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt; (&lt;span&gt;start&lt;/span&gt; = &lt;span style=&quot;color: rgb(0, 68, 221);&quot;&gt;&#039;1&#039;&lt;/span&gt;) &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;then&lt;/span&gt;                   &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- fallende Flanke Startbit erkannt&lt;/span&gt;&lt;br /&gt;            &lt;span&gt;prescaler&lt;/span&gt; &amp;lt;= &lt;span style=&quot;background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);&quot;&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;001&lt;/span&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;;                  &lt;span style=&quot;color: rgb(136, 136, 136);&quot;&gt;-- erst mal nur halbe Bitzeit abwarten&lt;/span&gt;&lt;br /&gt;            &lt;span&gt;rxbitcnt&lt;/span&gt;  &amp;lt;= &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0&lt;/span&gt;;&lt;br /&gt;            &lt;span&gt;start  &lt;/span&gt;   &amp;lt;= &lt;span style=&quot;color: rgb(0, 68, 221);&quot;&gt;&#039;0&#039;&lt;/span&gt;;&lt;br /&gt;         &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt;;&lt;br /&gt;      &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;if&lt;/span&gt;;&lt;br /&gt;   &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;process&lt;/span&gt;;&lt;br /&gt;   &lt;span&gt;dout&lt;/span&gt; &amp;lt;= &lt;span&gt;rxdat&lt;/span&gt;(&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;8&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;downto&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;1&lt;/span&gt;);  &lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;end&lt;/span&gt; &lt;span&gt;Behavioral&lt;/span&gt;;&lt;/pre&gt;&lt;hr size=&quot;2&quot; width=&quot;100%&quot; /&gt;&lt;p&gt;Der RXD-Eingang wird zuerst über ein 4 stufiges Schieberegister &lt;font face=&quot;courier new,courier,monospace&quot; color=&quot;#0000cc&quot;&gt;rxd_sr&lt;/font&gt; eingetaktet. dieses Schieberegister wird auch zur Flankenerkennung für das Startbit verwendet. Der Zähler &lt;font face=&quot;courier new,courier,monospace&quot; color=&quot;#0000cc&quot;&gt;prescaler &lt;/font&gt;teilt den achtfachen Takt auf einen Bittakt herunter. Beim Erkennen der fallenden Flanke des Startbits am RXD-Eingang wird der &lt;font face=&quot;courier new,courier,monospace&quot; color=&quot;#0033cc&quot;&gt;prescaler &lt;/font&gt;zurückgesetzt und später immer die Mitte eines Bits abgetastet. Nach 9 übertragenen Bits ist der Empfang beendet, es wird die Erkennung des nächsten Startbits aktiviert.&lt;br /&gt;Achtung: die Bitreihenfolge ist vertauscht, das MSB ist also in &lt;font face=&quot;courier new,courier,monospace&quot;&gt;&lt;font color=&quot;#0000cc&quot;&gt;rxdat(1)&lt;/font&gt; &lt;/font&gt;und damit in &lt;font face=&quot;courier new,courier,monospace&quot; color=&quot;#0000cc&quot;&gt;dout(0)&lt;/font&gt;. Wenn das stört, kann bei der Zuweisung an &lt;font face=&quot;courier new,courier,monospace&quot; color=&quot;#0000cc&quot;&gt;dout&lt;/font&gt; die Bitreihenfolge getauscht werden. Das könnte z.B. mit bitweiser Zuweisung &lt;font face=&quot;courier new,courier,monospace&quot; color=&quot;#0000cc&quot;&gt;dout(0) &amp;lt;= rxdat(8) ... dout(7) &amp;lt;= rxdat(1)&lt;/font&gt; oder einer &lt;font face=&quot;courier new,courier,monospace&quot; color=&quot;#0000cc&quot;&gt;for&lt;/font&gt;-Schleife oder einem kleinen Quick-And-Dirty-Trick passieren:&lt;/p&gt;&lt;pre&gt;   &lt;span&gt;dout&lt;/span&gt; : &lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;out&lt;/span&gt; &lt;span style=&quot;color: rgb(51, 68, 153); font-weight: bold;&quot;&gt;STD_LOGIC_VECTOR&lt;/span&gt; (&lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;0 &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;to&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 0, 221); font-weight: bold;&quot;&gt;7&lt;/span&gt;) := &lt;span style=&quot;background-color: rgb(255, 240, 240); color: rgb(221, 34, 0);&quot;&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;00000000&lt;/span&gt;&lt;span style=&quot;color: rgb(119, 17, 0);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;);&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 136, 0); font-weight: bold;&quot;&gt;&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;Auf diese Art passiert das Tauschen der Bits implizit und quasi automatisch... &lt;img src=&quot;http://www.lothar-miller.de/s9y/templates/default/img/emoticons/smile.png&quot; alt=&quot;:-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt; &lt;/p&gt;&lt;p&gt;Das Senden wird über die fallende Flanke eines Startbits am RXD-Eingang ausgelöst. Mit &lt;font face=&quot;courier new,courier,monospace&quot; color=&quot;#0000cc&quot;&gt;start=&#039;1&#039;&lt;/font&gt; wird das Sendeschieberegister &lt;font face=&quot;courier new,courier,monospace&quot; color=&quot;#0000cc&quot;&gt;txsr &lt;/font&gt;geladen und anschliessend mit jedem Nulldurchgang des &lt;font face=&quot;courier new,courier,monospace&quot; color=&quot;#0000cc&quot;&gt;prescaler&lt;/font&gt; um eine Stelle weitergeschoben und dabei von links mit Nullen aufgefüllt. Nachdem das Stopbit hinausgeschoben wurde, steht im Schieberegister der Wert &amp;quot;111111111&amp;quot;. Damit ist die Übertragung beendet und es wird auf den nächsten Start gewartet.&lt;/p&gt;&lt;p&gt;Im erweiterten Eintrag finden sich die Sourcecodes und die verwendete ucf-Datei. &lt;/p&gt; &lt;br /&gt;&lt;a href=&quot;http://www.lothar-miller.de/s9y/archives/60-RS232-IO.html#extended&quot;&gt;&quot;RS232 IO&quot; vollständig lesen&lt;/a&gt;
    </content:encoded>

    <pubDate>Mon, 28 Sep 2009 20:21:00 +0200</pubDate>
    <guid isPermaLink="false">http://www.lothar-miller.de/s9y/archives/60-guid.html</guid>
    
</item>

</channel>
</rss>
