{"id":1619,"date":"2020-12-29T20:19:53","date_gmt":"2020-12-29T20:19:53","guid":{"rendered":"http:\/\/box2281.temp.domains\/~ganzwork\/?page_id=1619"},"modified":"2022-01-29T19:37:47","modified_gmt":"2022-01-29T19:37:47","slug":"uart-tx","status":"publish","type":"page","link":"https:\/\/ganslermike.com\/?page_id=1619","title":{"rendered":"UART TX"},"content":{"rendered":"\n<p>This short <a rel=\"noreferrer noopener\" href=\"https:\/\/www.chipverify.com\/verilog\/verilog-tutorial\" target=\"_blank\">Verilog<\/a> project is intended for basic communications or as a debug tool for other larger projects.  It implements a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Universal_asynchronous_receiver-transmitter\">UART<\/a> transmitter at a selectable <a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/Symbol_rate\" target=\"_blank\">baud rate<\/a>, with the common &#8220;<a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/8-N-1\" target=\"_blank\">8N1<\/a>&#8221; (8 data bits, no parity, 1 stop bit) format.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-logic-analyzer-full-message-ascii-and-bin.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"250\" src=\"https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-logic-analyzer-full-message-ascii-and-bin.png?resize=640%2C250&#038;ssl=1\" alt=\"\" class=\"wp-image-1857\" srcset=\"https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-logic-analyzer-full-message-ascii-and-bin.png?resize=1024%2C400&amp;ssl=1 1024w, https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-logic-analyzer-full-message-ascii-and-bin.png?resize=300%2C117&amp;ssl=1 300w, https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-logic-analyzer-full-message-ascii-and-bin.png?resize=768%2C300&amp;ssl=1 768w, https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-logic-analyzer-full-message-ascii-and-bin.png?resize=1536%2C600&amp;ssl=1 1536w, https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-logic-analyzer-full-message-ascii-and-bin.png?w=1911&amp;ssl=1 1911w, https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-logic-analyzer-full-message-ascii-and-bin.png?w=1280&amp;ssl=1 1280w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>I developed this on a <a rel=\"noreferrer noopener\" href=\"https:\/\/www.terasic.com.tw\/cgi-bin\/page\/archive.pl?Language=English&amp;No=1021\" target=\"_blank\">Terasic DE10-Lite board<\/a>, which has an Altera <a rel=\"noreferrer noopener\" href=\"https:\/\/www.intel.com\/content\/www\/us\/en\/products\/programmable\/fpga\/max-10.html\" target=\"_blank\">MAX10<\/a> FPGA, using the <a rel=\"noreferrer noopener\" href=\"https:\/\/fpgasoftware.intel.com\/?edition=lite\" target=\"_blank\">Quartus Prime 20.1, Light Edition<\/a> toolchain.  Outside of the I\/O mapping, nothing is really specific to this particular board or FPGA part, and the code can be easily adapted to other hardware.<\/p>\n\n\n\n<p>For <a rel=\"noreferrer noopener\" href=\"https:\/\/www.chipverify.com\/verilog\/verilog-tutorial\" target=\"_blank\">Verilog<\/a> beginners, the project has examples of simple <a rel=\"noreferrer noopener\" href=\"https:\/\/verilogguide.readthedocs.io\/en\/latest\/verilog\/fsm.html\" target=\"_blank\">finite state machines<\/a>, <a rel=\"noreferrer noopener\" href=\"https:\/\/www.nandland.com\/verilog\/examples\/example-case-statement.html\" target=\"_blank\">case<\/a> statements, <a rel=\"noreferrer noopener\" href=\"https:\/\/www.nandland.com\/verilog\/examples\/example-concatenation-operator.html\" target=\"_blank\">concatenation<\/a>, a <a rel=\"noreferrer noopener\" href=\"https:\/\/zipcpu.com\/blog\/2017\/10\/20\/cdc.html\" target=\"_blank\">synchronizer<\/a> or two, <a rel=\"noreferrer noopener\" href=\"https:\/\/verilogguide.readthedocs.io\/en\/latest\/verilog\/datatype.html#localparam\" target=\"_blank\">localparams<\/a>, <a href=\"https:\/\/www.chipverify.com\/verilog\/verilog-module-instantiations\">module instantiation &#8220;by name&#8221;<\/a>, and a <a rel=\"noreferrer noopener\" href=\"https:\/\/www.nandland.com\/articles\/synthesizable-vs-non-synthesizable-code-fpga-asic.html\" target=\"_blank\">synthesizable<\/a> test module.  <\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"uart-basics\">UART Basics<\/h3>\n\n\n\n<p>Ample discussions of UART communications can be found on <a rel=\"noreferrer noopener\" href=\"https:\/\/www.allaboutcircuits.com\/technical-articles\/back-to-basics-the-universal-asynchronous-receiver-transmitter-uart\/\" target=\"_blank\">allaboutcircuits.com<\/a>, <a href=\"https:\/\/learn.sparkfun.com\/tutorials\/serial-communication\">Sparkfun<\/a>, and <a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/Universal_asynchronous_receiver-transmitter\" target=\"_blank\">Wikipedia<\/a>, but I&#8217;l also point out a few highlights below.  <\/p>\n\n\n\n<p>For the details on my implementation, the code is well commented so please check it out.  The full Quartus project is up on my <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/ganz125\/uart_transmitter\" target=\"_blank\">GitHub site<\/a> and the two relevant Verilog source files are also included at the bottom of this page.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-bit-framing-cropped.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"62\" src=\"https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-bit-framing-cropped.png?resize=640%2C62&#038;ssl=1\" alt=\"\" class=\"wp-image-1843\" srcset=\"https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-bit-framing-cropped.png?w=964&amp;ssl=1 964w, https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-bit-framing-cropped.png?resize=300%2C29&amp;ssl=1 300w, https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-bit-framing-cropped.png?resize=768%2C74&amp;ssl=1 768w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/figure><\/div>\n\n\n\n<p class=\"has-text-align-center\">Typical UART data framing<\/p>\n\n\n\n<p>A few few interesting <a href=\"https:\/\/en.wikipedia.org\/wiki\/Universal_asynchronous_receiver-transmitter\">UART<\/a> nuances to remember:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>the serial output line (TX) idles HIGH.  For a logic-level UART interface (i.e. not <a href=\"https:\/\/en.wikipedia.org\/wiki\/RS-232\">RS-232<\/a> voltage levels) that means at 3.3V, or 5V, etc based on the I\/O line supply voltage<\/li><li>there must be a START bit.  This ensures that the receiver can detect when data is coming, and synchronize it&#8217;s sampling of the upcoming bits<\/li><li>the data item can be smaller than 8 bits, but 8 is by far the most common size, and what is implemented in this design<\/li><li>a PARITY bit is optional, and not implemented here<\/li><li>one STOP bit is used here.  This means that the complete transmission lasts 10 bit durations:  start bit + 8 data bits + stop bit = 10 bits<\/li><li>Most systems transmit the data byte in reverse order, i.e. <a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/Bit_numbering\" target=\"_blank\">LSBit<\/a> first, <a href=\"https:\/\/en.wikipedia.org\/wiki\/Bit_numbering\">MSBit<\/a> last, which is done in this implementation<\/li><\/ul>\n\n\n\n<div style=\"height:13px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"test-wrapper-not-a-test-bench-per-se\">Test Wrapper (not a Test Bench, per se)<\/h3>\n\n\n\n<p>I didn&#8217;t create a test bench for simulation, but instead created test code that is <a rel=\"noreferrer noopener\" href=\"https:\/\/www.nandland.com\/articles\/synthesizable-vs-non-synthesizable-code-fpga-asic.html\" target=\"_blank\">synthesizable<\/a> and can be run on the board to demo the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Universal_asynchronous_receiver-transmitter\">UART<\/a> transmitter.  The tester code (<strong>uart_tx_tester.v<\/strong>) feeds the UART transmitter module <strong>(<strong>uart_tx.v<\/strong>)<\/strong> with a 16 byte message every few seconds, and monitors the busy signal to correctly pace the data.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-top-level-entity-schematic.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"203\" src=\"https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-top-level-entity-schematic.png?resize=640%2C203&#038;ssl=1\" alt=\"\" class=\"wp-image-1825\" srcset=\"https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-top-level-entity-schematic.png?resize=1024%2C325&amp;ssl=1 1024w, https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-top-level-entity-schematic.png?resize=300%2C95&amp;ssl=1 300w, https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-top-level-entity-schematic.png?resize=768%2C244&amp;ssl=1 768w, https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-top-level-entity-schematic.png?resize=1536%2C487&amp;ssl=1 1536w, https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-top-level-entity-schematic.png?w=1604&amp;ssl=1 1604w, https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-top-level-entity-schematic.png?w=1280&amp;ssl=1 1280w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>I chose to use a Quartus schematic file for the <a rel=\"noreferrer noopener\" href=\"https:\/\/www.intel.com\/content\/www\/us\/en\/programmable\/quartushelp\/13.0\/mergedProjects\/reference\/glossary\/def_top_level.htm\" target=\"_blank\">top level entity<\/a> since it clearly shows the how the I\/O and <a rel=\"noreferrer noopener\" href=\"https:\/\/www.chipverify.com\/verilog\/verilog-tutorial\" target=\"_blank\">Verilog<\/a> modules are connected.  This could have been done programmatically with <a rel=\"noreferrer noopener\" href=\"https:\/\/www.chipverify.com\/verilog\/verilog-tutorial\" target=\"_blank\">Verilog<\/a> as well, but I figured this was clearer to follow.<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"i-o-interface\">I\/O Interface<\/h3>\n\n\n\n<p>The interface to the UART transmitter module (<strong>uart_tx.v<\/strong>) is small:<\/p>\n\n\n\n<p>Inputs:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>single byte for the character to transmit<\/li><li>trigger flag to initiate transmitting<\/li><\/ul>\n\n\n\n<p>  <\/p>\n\n\n\n<p>Outputs:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>serial data, i.e. the transmit (or TX) line that streams out the data<\/li><li>busy flag for handshaking with the module that is providing the bytes to transmit.  This indicates when the transmitter is still shifting out bits for the current byte, and can be used to check if the transmitter is ready for a new byte<\/li><\/ul>\n\n\n\n<div style=\"height:19px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"note\">Note:<\/h3>\n\n\n\n<p>This implementation does not have any <a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/FIFO_(computing_and_electronics)\" target=\"_blank\">FIFO<\/a>&#8216;s or buffers, so the module providing the data needs to pay attention to the busy flag to avoid overruns.  <\/p>\n\n\n\n<p>The full Quartus project including all source files is on my <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/ganz125\/uart_transmitter\" data-type=\"URL\" data-id=\"https:\/\/github.com\/ganz125\/uart_transmitter\" target=\"_blank\">GitHub<\/a>.  The two more interesting Verilog source files are also included below.<\/p>\n\n\n\n<p><strong>Hello World&#8230; anyone listening?<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-hello-world-on-serial-monitor-larger.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-hello-world-on-serial-monitor-larger.png?w=400&#038;ssl=1\" alt=\"\" class=\"wp-image-1863\"  srcset=\"https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-hello-world-on-serial-monitor-larger.png?w=935&amp;ssl=1 935w, https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-hello-world-on-serial-monitor-larger.png?resize=300%2C134&amp;ssl=1 300w, https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-hello-world-on-serial-monitor-larger.png?resize=768%2C343&amp;ssl=1 768w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/figure><\/div>\n\n\n\n<p class=\"has-text-align-center\">Quick test at 57.6Kbaud<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong><span style=\"text-decoration: underline;\">uart_tx_tester.v &#8211; synthesizable test code wrapper<\/span><\/strong><\/p>\n\n\n\n<!-- HTML generated using hilite.me --><div style=\"background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\"><pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #888888\">\/\/  ------------------------------------------------------------------------------<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  uart_tx_tester.v -- synthesizable tester for uart_tx.v<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  Copyright (C) 2020 Michael Gansler<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  This program is free software: you can redistribute it and\/or modify<\/span>\n<span style=\"color: #888888\">\/\/  it under the terms of the GNU General Public License as published by<\/span>\n<span style=\"color: #888888\">\/\/  the Free Software Foundation, either version 3 of the License, or<\/span>\n<span style=\"color: #888888\">\/\/  (at your option) any later version.<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  This program is distributed in the hope that it will be useful,<\/span>\n<span style=\"color: #888888\">\/\/  but WITHOUT ANY WARRANTY; without even the implied warranty of<\/span>\n<span style=\"color: #888888\">\/\/  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<\/span>\n<span style=\"color: #888888\">\/\/  GNU General Public License for more details.<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  You should have received a copy of the GNU General Public License<\/span>\n<span style=\"color: #888888\">\/\/  along with this program.  If not, see &lt;https:\/\/www.gnu.org\/licenses\/&gt;.<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  ------------------------------------------------------------------------------<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  Module:       uart_tx_tester.v<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  Objective:    Synthesaizable tester for uart_tx by feeding it a 16 byte<\/span>\n<span style=\"color: #888888\">\/\/                message every few seconds for testing on hardware <\/span>\n<span style=\"color: #888888\">\/\/                with a scope or logic analyzer.<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  Assumptions:  50 MHz input clock<\/span>\n<span style=\"color: #888888\">\/\/                16 byte long test message<\/span>\n<span style=\"color: #888888\">\/\/                Development done on Terasic DE10-Lite board with Altera MAX10 FPGA<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  Notes:        This is a simple tester module to test uart_tx.v.  This is <\/span>\n<span style=\"color: #888888\">\/\/                synthesizable code which sends a 16 byte ASCII message to <\/span>\n<span style=\"color: #888888\">\/\/                uart_tx every few seconds. It drives the data and trigger <\/span>\n<span style=\"color: #888888\">\/\/                lines while monitoring the busy line to pace the characters.<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/                A full test bench for simulation would also be helpful, but has<\/span>\n<span style=\"color: #888888\">\/\/                not yet been created at this time.<\/span>\n<span style=\"color: #888888\">\/\/                  <\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #003366; font-weight: bold\">`default_nettype<\/span> none                <span style=\"color: #888888\">\/\/ Require all nets to be declared before used.<\/span>\n                                     <span style=\"color: #888888\">\/\/ --&gt; typo'd net names get trapped<\/span>\n\n\n<span style=\"color: #008800; font-weight: bold\">module<\/span> uart_tx_tester\n(\n   <span style=\"color: #008800; font-weight: bold\">input<\/span>                clk_50M,          <span style=\"color: #888888\">\/\/ Input clock, assumed 50 MHz<\/span>\n   <span style=\"color: #008800; font-weight: bold\">input<\/span>                run_test_raw,     <span style=\"color: #888888\">\/\/ HIGH indicates to continuously run test<\/span>\n   <span style=\"color: #008800; font-weight: bold\">input<\/span>                tx_busy,          <span style=\"color: #888888\">\/\/ HIGH indicates transmitter is busy<\/span>\n   \n   <span style=\"color: #008800; font-weight: bold\">output<\/span>  <span style=\"color: #333399; font-weight: bold\">reg<\/span>   [<span style=\"color: #005588; font-weight: bold\">7<\/span><span style=\"color: #333333\">:<\/span><span style=\"color: #005588; font-weight: bold\">0<\/span>]  data_out,         <span style=\"color: #888888\">\/\/ Data byte (8 bits) to transmit<\/span>\n   <span style=\"color: #008800; font-weight: bold\">output<\/span>  <span style=\"color: #333399; font-weight: bold\">reg<\/span>          trigger           <span style=\"color: #888888\">\/\/ Trigger to tell UART module to begin transmission<\/span>\n);\n\n<span style=\"color: #333399; font-weight: bold\">reg<\/span>                     run_test_0   <span style=\"color: #333333\">=<\/span> <span style=\"color: #005588; font-weight: bold\">0<\/span>;           <span style=\"color: #888888\">\/\/ Synchronizer for 'start test' switch input<\/span>\n<span style=\"color: #333399; font-weight: bold\">reg<\/span>                     run_test     <span style=\"color: #333333\">=<\/span> <span style=\"color: #005588; font-weight: bold\">0<\/span>;           <span style=\"color: #888888\">\/\/ Synchronizer for 'start test' switch input<\/span>\n\n<span style=\"color: #333399; font-weight: bold\">reg<\/span>         [<span style=\"color: #005588; font-weight: bold\">5<\/span><span style=\"color: #333333\">:<\/span><span style=\"color: #005588; font-weight: bold\">0<\/span>]       tester_state <span style=\"color: #333333\">=<\/span> <span style=\"color: #005588; font-weight: bold\">0<\/span>;           <span style=\"color: #888888\">\/\/ FSM state variable<\/span>\n\n<span style=\"color: #333399; font-weight: bold\">reg<\/span>        [<span style=\"color: #005588; font-weight: bold\">31<\/span><span style=\"color: #333333\">:<\/span><span style=\"color: #005588; font-weight: bold\">0<\/span>]       byte_index   <span style=\"color: #333333\">=<\/span> (<span style=\"color: #005588; font-weight: bold\">8<\/span><span style=\"color: #333333\">*<\/span><span style=\"color: #005588; font-weight: bold\">16<\/span>)<span style=\"color: #333333\">-<\/span><span style=\"color: #005588; font-weight: bold\">1<\/span>;    <span style=\"color: #888888\">\/\/ Pointer to beginning of next byte to transmit in 16 byte message<\/span>\n\n<span style=\"color: #333399; font-weight: bold\">reg<\/span>        [<span style=\"color: #005588; font-weight: bold\">31<\/span><span style=\"color: #333333\">:<\/span><span style=\"color: #005588; font-weight: bold\">0<\/span>]       pause_delay  <span style=\"color: #333333\">=<\/span> <span style=\"color: #005588; font-weight: bold\">0<\/span>;           <span style=\"color: #888888\">\/\/ Counter for delay between re-transmissions of message<\/span>\n\n<span style=\"color: #333399; font-weight: bold\">reg<\/span>         [<span style=\"color: #005588; font-weight: bold\">5<\/span><span style=\"color: #333333\">:<\/span><span style=\"color: #005588; font-weight: bold\">0<\/span>]       trigger_ctr  <span style=\"color: #333333\">=<\/span> <span style=\"color: #005588; font-weight: bold\">0<\/span>;           <span style=\"color: #888888\">\/\/ Delay to hold trigger high, in clock cycles<\/span>\n\n                                 <span style=\"color: #888888\">\/\/ Byte position:<\/span>\n                                 <span style=\"color: #888888\">\/\/<\/span>\n                                 <span style=\"color: #888888\">\/\/ 111111<\/span>\n                                 <span style=\"color: #888888\">\/\/ 5432109876543210<\/span>\n<span style=\"color: #333399; font-weight: bold\">reg<\/span>  [(<span style=\"color: #005588; font-weight: bold\">8<\/span><span style=\"color: #333333\">*<\/span><span style=\"color: #005588; font-weight: bold\">16<\/span>)<span style=\"color: #333333\">-<\/span><span style=\"color: #005588; font-weight: bold\">1<\/span><span style=\"color: #333333\">:<\/span><span style=\"color: #005588; font-weight: bold\">0<\/span>]       byte_str <span style=\"color: #333333\">=<\/span> <span style=\"background-color: #fff0f0\">\"Hello World!    \"<\/span>;  <span style=\"color: #888888\">\/\/ 16 byte message to transmit<\/span>\n\n<span style=\"color: #008800; font-weight: bold\">localparam<\/span> <span style=\"color: #003366; font-weight: bold\">STATE_IDLE<\/span>       <span style=\"color: #333333\">=<\/span> <span style=\"color: #005588; font-weight: bold\">6'b00_0000<\/span>;           <span style=\"color: #888888\">\/\/ Legal values for tester_state<\/span>\n<span style=\"color: #008800; font-weight: bold\">localparam<\/span> <span style=\"color: #003366; font-weight: bold\">STATE_LOAD<\/span>       <span style=\"color: #333333\">=<\/span> <span style=\"color: #005588; font-weight: bold\">6'b00_0010<\/span>;           <span style=\"color: #888888\">\/\/ Legal values for tester_state<\/span>\n<span style=\"color: #008800; font-weight: bold\">localparam<\/span> <span style=\"color: #003366; font-weight: bold\">STATE_TRIGGER<\/span>    <span style=\"color: #333333\">=<\/span> <span style=\"color: #005588; font-weight: bold\">6'b00_0100<\/span>;           <span style=\"color: #888888\">\/\/ Legal values for tester_state<\/span>\n<span style=\"color: #008800; font-weight: bold\">localparam<\/span> <span style=\"color: #003366; font-weight: bold\">STATE_POLL_BUSY<\/span>  <span style=\"color: #333333\">=<\/span> <span style=\"color: #005588; font-weight: bold\">6'b00_1000<\/span>;           <span style=\"color: #888888\">\/\/ Legal values for tester_state<\/span>\n<span style=\"color: #008800; font-weight: bold\">localparam<\/span> <span style=\"color: #003366; font-weight: bold\">STATE_PAUSE<\/span>      <span style=\"color: #333333\">=<\/span> <span style=\"color: #005588; font-weight: bold\">6'b01_0000<\/span>;           <span style=\"color: #888888\">\/\/ Legal values for tester_state<\/span>\n\n<span style=\"color: #008800; font-weight: bold\">localparam<\/span> <span style=\"color: #003366; font-weight: bold\">MSG_DELAY<\/span>        <span style=\"color: #333333\">=<\/span> <span style=\"color: #005588; font-weight: bold\">32<\/span><span style=\"color: #0000DD; font-weight: bold\">'d100_000_000<\/span>;      <span style=\"color: #888888\">\/\/ Delay between messages re-transmissions, in clk cycles<\/span>\n\n<span style=\"color: #888888\">\/\/     <\/span>\n<span style=\"color: #888888\">\/\/ Synchronizer for \"run_test\" input since, as tested, this comes from a <\/span>\n<span style=\"color: #888888\">\/\/ slide switch on the DE10-Lite board, which is not synchronous with the<\/span>\n<span style=\"color: #888888\">\/\/ clock.  See more on clock domain crossing and metastability to better<\/span>\n<span style=\"color: #888888\">\/\/ understand this topic.<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #008800; font-weight: bold\">always<\/span> @(<span style=\"color: #008800; font-weight: bold\">posedge<\/span>  clk_50M) <span style=\"color: #008800; font-weight: bold\">begin<\/span>\n\n   run_test_0 <span style=\"color: #333333\">&lt;=<\/span> run_test_raw;\n   run_test   <span style=\"color: #333333\">&lt;=<\/span> run_test_0;\n   \n<span style=\"color: #008800; font-weight: bold\">end<\/span>\n\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/ Main Finite State Machine that sequences the test<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #008800; font-weight: bold\">always<\/span> @(<span style=\"color: #008800; font-weight: bold\">posedge<\/span>  clk_50M) <span style=\"color: #008800; font-weight: bold\">begin<\/span>\n\n   <span style=\"color: #008800; font-weight: bold\">case<\/span> (tester_state)\n   \n      <span style=\"color: #888888\">\/\/<\/span>\n      <span style=\"color: #888888\">\/\/ Wait for request to begin test.<\/span>\n      <span style=\"color: #888888\">\/\/<\/span>\n      <span style=\"color: #997700; font-weight: bold\">STATE_IDLE:<\/span> <span style=\"color: #008800; font-weight: bold\">begin<\/span>\n      \n         trigger <span style=\"color: #333333\">&lt;=<\/span> <span style=\"color: #005588; font-weight: bold\">1'b0<\/span>;\n         \n         <span style=\"color: #008800; font-weight: bold\">if<\/span> (run_test) <span style=\"color: #008800; font-weight: bold\">begin<\/span>\n         \n            byte_index   <span style=\"color: #333333\">&lt;=<\/span> (<span style=\"color: #005588; font-weight: bold\">8<\/span><span style=\"color: #333333\">*<\/span><span style=\"color: #005588; font-weight: bold\">16<\/span>)<span style=\"color: #333333\">-<\/span><span style=\"color: #005588; font-weight: bold\">1<\/span>;      <span style=\"color: #888888\">\/\/ Point to 1st bit of 1st byte in message.<\/span>\n            tester_state <span style=\"color: #333333\">&lt;=<\/span> <span style=\"color: #003366; font-weight: bold\">STATE_LOAD<\/span>;    <span style=\"color: #888888\">\/\/ Move on to next state.<\/span>\n            \n         <span style=\"color: #008800; font-weight: bold\">end<\/span>\n         \n      <span style=\"color: #008800; font-weight: bold\">end<\/span>\n      \n      <span style=\"color: #888888\">\/\/<\/span>\n      <span style=\"color: #888888\">\/\/ Output next byte to transmitter module, with trigger still low<\/span>\n      <span style=\"color: #888888\">\/\/ so it won't transmit yet.<\/span>\n      <span style=\"color: #888888\">\/\/<\/span>\n      <span style=\"color: #997700; font-weight: bold\">STATE_LOAD:<\/span> <span style=\"color: #008800; font-weight: bold\">begin<\/span>\n         \n         trigger      <span style=\"color: #333333\">&lt;=<\/span> <span style=\"color: #005588; font-weight: bold\">1'b0<\/span>;                       <span style=\"color: #888888\">\/\/ Make sure trigger is LOW while setting data byte.<\/span>\n         data_out     <span style=\"color: #333333\">&lt;=<\/span> byte_str[byte_index <span style=\"color: #333333\">-:<\/span><span style=\"color: #005588; font-weight: bold\">8<\/span>];   <span style=\"color: #888888\">\/\/ Set data byte to transmit.<\/span>\n         trigger_ctr  <span style=\"color: #333333\">&lt;=<\/span> <span style=\"color: #005588; font-weight: bold\">6<\/span><span style=\"color: #0000DD; font-weight: bold\">'d5<\/span>;                       <span style=\"color: #888888\">\/\/ Init counter which defines trigger HIGH time.<\/span>\n         tester_state <span style=\"color: #333333\">&lt;=<\/span> <span style=\"color: #003366; font-weight: bold\">STATE_TRIGGER<\/span>;              <span style=\"color: #888888\">\/\/ Move on to next state.<\/span>\n         \n      <span style=\"color: #008800; font-weight: bold\">end<\/span>\n      \n      <span style=\"color: #888888\">\/\/<\/span>\n      <span style=\"color: #888888\">\/\/ Now that previous state output'd the next byte to transmit,<\/span>\n      <span style=\"color: #888888\">\/\/ assert the trigger signal to begin the transmission.<\/span>\n      <span style=\"color: #888888\">\/\/ <\/span>\n      <span style=\"color: #997700; font-weight: bold\">STATE_TRIGGER:<\/span> <span style=\"color: #008800; font-weight: bold\">begin<\/span>\n      \n         trigger     <span style=\"color: #333333\">&lt;=<\/span> <span style=\"color: #005588; font-weight: bold\">1'b1<\/span>;                  <span style=\"color: #888888\">\/\/ Assert trigger to begin transmission.<\/span>\n         trigger_ctr <span style=\"color: #333333\">&lt;=<\/span> trigger_ctr <span style=\"color: #333333\">-<\/span> <span style=\"color: #005588; font-weight: bold\">6<\/span><span style=\"color: #0000DD; font-weight: bold\">'d1<\/span>;    <span style=\"color: #888888\">\/\/ Keep trigger high for N cycles to accommodate synchronizer<\/span>\n                                               <span style=\"color: #888888\">\/\/  in uart_tx module.  Handles latency between trigger assertion<\/span>\n                                               <span style=\"color: #888888\">\/\/  here and FSM in uart_tx module beginning transmission and <\/span>\n                                               <span style=\"color: #888888\">\/\/  setting the busy flag.  <\/span>\n         \n         <span style=\"color: #008800; font-weight: bold\">if<\/span> (trigger_ctr<span style=\"color: #333333\">==<\/span><span style=\"color: #005588; font-weight: bold\">0<\/span>)\n            tester_state <span style=\"color: #333333\">&lt;=<\/span> <span style=\"color: #003366; font-weight: bold\">STATE_POLL_BUSY<\/span>;   <span style=\"color: #888888\">\/\/ Move on to next state.<\/span>\n         \n      <span style=\"color: #008800; font-weight: bold\">end<\/span>\n      \n      <span style=\"color: #888888\">\/\/<\/span>\n      <span style=\"color: #888888\">\/\/ Clear trigger signal, and wait until all bits shifted out<\/span>\n      <span style=\"color: #888888\">\/\/ for the current byte.<\/span>\n      <span style=\"color: #888888\">\/\/<\/span>\n      <span style=\"color: #997700; font-weight: bold\">STATE_POLL_BUSY:<\/span> <span style=\"color: #008800; font-weight: bold\">begin<\/span>\n\n         trigger <span style=\"color: #333333\">&lt;=<\/span> <span style=\"color: #005588; font-weight: bold\">1'b0<\/span>;                       <span style=\"color: #888888\">\/\/ Clear trigger flag now that N cycles have passed.<\/span>\n         \n         <span style=\"color: #008800; font-weight: bold\">if<\/span> (<span style=\"color: #333333\">~<\/span>tx_busy) <span style=\"color: #008800; font-weight: bold\">begin<\/span>                    <span style=\"color: #888888\">\/\/ Check to see if uart_tx module still shifting out bits.<\/span>\n         \n            <span style=\"color: #008800; font-weight: bold\">if<\/span> (byte_index<span style=\"color: #333333\">&lt;=<\/span><span style=\"color: #005588; font-weight: bold\">7<\/span>) <span style=\"color: #008800; font-weight: bold\">begin<\/span>            <span style=\"color: #888888\">\/\/ Check to see if just transmitted last byte of message.  7 since that<\/span>\n                                                <span style=\"color: #888888\">\/\/ is the location of the MSbit of the final byte of the message.<\/span>\n               pause_delay  <span style=\"color: #333333\">&lt;=<\/span> <span style=\"color: #005588; font-weight: bold\">32<\/span><span style=\"color: #0000DD; font-weight: bold\">'d0<\/span>;           <span style=\"color: #888888\">\/\/ All done transmitting message, so setup for delay between message transmissions.<\/span>\n               tester_state <span style=\"color: #333333\">&lt;=<\/span> <span style=\"color: #003366; font-weight: bold\">STATE_PAUSE<\/span>;     <span style=\"color: #888888\">\/\/ Move on to next state.<\/span>\n               \n            <span style=\"color: #008800; font-weight: bold\">end<\/span> <span style=\"color: #008800; font-weight: bold\">else<\/span> <span style=\"color: #008800; font-weight: bold\">begin<\/span> \n            \n               byte_index   <span style=\"color: #333333\">&lt;=<\/span> byte_index <span style=\"color: #333333\">-<\/span> <span style=\"color: #005588; font-weight: bold\">32<\/span><span style=\"color: #0000DD; font-weight: bold\">'d8<\/span>;  <span style=\"color: #888888\">\/\/ More bytes to send so point to next byte.<\/span>\n               tester_state <span style=\"color: #333333\">&lt;=<\/span> <span style=\"color: #003366; font-weight: bold\">STATE_LOAD<\/span>;          <span style=\"color: #888888\">\/\/ Move on to next state.<\/span>\n               \n            <span style=\"color: #008800; font-weight: bold\">end<\/span>\n              \n         <span style=\"color: #008800; font-weight: bold\">end<\/span>\n         \n      <span style=\"color: #008800; font-weight: bold\">end<\/span>\n      \n      <span style=\"color: #888888\">\/\/<\/span>\n      <span style=\"color: #888888\">\/\/ Once transmitted full message, pause before <\/span>\n      <span style=\"color: #888888\">\/\/ transmitting message again for testing convenience.<\/span>\n      <span style=\"color: #888888\">\/\/<\/span>\n      <span style=\"color: #997700; font-weight: bold\">STATE_PAUSE:<\/span> <span style=\"color: #008800; font-weight: bold\">begin<\/span>\n      \n         pause_delay <span style=\"color: #333333\">&lt;=<\/span> pause_delay <span style=\"color: #333333\">+<\/span> <span style=\"color: #005588; font-weight: bold\">32<\/span><span style=\"color: #0000DD; font-weight: bold\">'d1<\/span>;\n         \n         <span style=\"color: #008800; font-weight: bold\">if<\/span> (pause_delay<span style=\"color: #333333\">&gt;<\/span><span style=\"color: #003366; font-weight: bold\">MSG_DELAY<\/span>)            <span style=\"color: #888888\">\/\/ Wait for delay to expire.<\/span>\n            tester_state <span style=\"color: #333333\">&lt;=<\/span> <span style=\"color: #003366; font-weight: bold\">STATE_IDLE<\/span>;\n            \n      <span style=\"color: #008800; font-weight: bold\">end<\/span>\n\n      <span style=\"color: #888888\">\/\/<\/span>\n      <span style=\"color: #888888\">\/\/ Should never get here, but if do, return to IDLE<\/span>\n      <span style=\"color: #888888\">\/\/<\/span>\n      <span style=\"color: #008800; font-weight: bold\">default<\/span> <span style=\"color: #333333\">:<\/span> <span style=\"color: #008800; font-weight: bold\">begin<\/span>\n      \n         tester_state <span style=\"color: #333333\">&lt;=<\/span> <span style=\"color: #003366; font-weight: bold\">STATE_IDLE<\/span>;\n         \n      <span style=\"color: #008800; font-weight: bold\">end<\/span>\n      \n   <span style=\"color: #008800; font-weight: bold\">endcase<\/span>\n   \n<span style=\"color: #008800; font-weight: bold\">end<\/span>\n\n<span style=\"color: #008800; font-weight: bold\">endmodule<\/span>\n<\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><strong><span style=\"text-decoration: underline;\">uart_tx.v &#8211; UART transmitter module<\/span><\/strong><\/p>\n\n\n\n<!-- HTML generated using hilite.me --><div style=\"background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\"><pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #888888\">\/\/  ------------------------------------------------------------------------------<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  uart_tx.v -- implements a UART transmitter<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  Copyright (C) 2020 Michael Gansler<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  This program is free software: you can redistribute it and\/or modify<\/span>\n<span style=\"color: #888888\">\/\/  it under the terms of the GNU General Public License as published by<\/span>\n<span style=\"color: #888888\">\/\/  the Free Software Foundation, either version 3 of the License, or<\/span>\n<span style=\"color: #888888\">\/\/  (at your option) any later version.<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  This program is distributed in the hope that it will be useful,<\/span>\n<span style=\"color: #888888\">\/\/  but WITHOUT ANY WARRANTY; without even the implied warranty of<\/span>\n<span style=\"color: #888888\">\/\/  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<\/span>\n<span style=\"color: #888888\">\/\/  GNU General Public License for more details.<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  You should have received a copy of the GNU General Public License<\/span>\n<span style=\"color: #888888\">\/\/  along with this program.  If not, see &lt;https:\/\/www.gnu.org\/licenses\/&gt;.<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  ------------------------------------------------------------------------------<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  Module:       uart_tx.v<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  Objective:    Acts as a UART transmitter, converting 8 bit parallel data to <\/span>\n<span style=\"color: #888888\">\/\/                serial, at user-selected baud rate.<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  Assumptions:  - Data format is 8N1<\/span>\n<span style=\"color: #888888\">\/\/                - 50 MHz input clock<\/span>\n<span style=\"color: #888888\">\/\/                - No clock domain crossings accomodated for, though a synchronizer<\/span>\n<span style=\"color: #888888\">\/\/                  is included on the trigger input.  ** See comments below. **<\/span>\n<span style=\"color: #888888\">\/\/                - Development done on Terasic DE10-Lite board with Altera MAX10 FPGA<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/                NOTE!!! -- If this module were used in an actual situation <\/span>\n<span style=\"color: #888888\">\/\/                with clock domain crossings or asynchronous inputs, <\/span>\n<span style=\"color: #888888\">\/\/                more attention (i.e. code changes) would be necessary to manage <\/span>\n<span style=\"color: #888888\">\/\/                the situation.<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  Notes:        Transmits 8 bits of data, plus start and stop bit, with no<\/span>\n<span style=\"color: #888888\">\/\/                parity bit, at the selected baud rate.  This is, often<\/span>\n<span style=\"color: #888888\">\/\/                refered to as \"8N1\" - 8 data bits, no parity, 1 stop bit.  <\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/                Baud rate is selectable via a localparam.  Explanation of<\/span>\n<span style=\"color: #888888\">\/\/                the calculation and values for a number of common baud rates<\/span>\n<span style=\"color: #888888\">\/\/                are found in the comments elsewhere in this file.  Other <\/span>\n<span style=\"color: #888888\">\/\/                baud rates can of course be used, but have not been tested.<\/span>\n<span style=\"color: #888888\">\/\/ <\/span>\n<span style=\"color: #888888\">\/\/                The trigger signal begins a transmission.  The data byte is also<\/span>\n<span style=\"color: #888888\">\/\/                latched at the trigger event to ensure that if the parent module<\/span>\n<span style=\"color: #888888\">\/\/                modifies the data byte during the transmission, it<\/span>\n<span style=\"color: #888888\">\/\/                has no averse effect on the transmission already in progress.<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/                NOTE!!! -- There is a synchronizer included on the <\/span>\n<span style=\"color: #888888\">\/\/                trigger input.  If this module is being used with an <\/span>\n<span style=\"color: #888888\">\/\/                asynchronous trigger input or certain types of clock domain <\/span>\n<span style=\"color: #888888\">\/\/                crossings, this can help with avoiding metastability.  <\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/                NOTE!!! -- If this module were used in an actual situation with<\/span>\n<span style=\"color: #888888\">\/\/                clock domain crossings or asynchronous inputs, <\/span>\n<span style=\"color: #888888\">\/\/                more attention (i.e. code changes) would be necessary to <\/span>\n<span style=\"color: #888888\">\/\/                manage the situation.<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/                This synchronizer creates latency between assertion of the <\/span>\n<span style=\"color: #888888\">\/\/                trigger_raw input and actual initiation of the transmission.<\/span>\n<span style=\"color: #888888\">\/\/                Monitoring the \"busy\" signal during this latency must be<\/span>\n<span style=\"color: #888888\">\/\/                done with care since monitoring too early could appear<\/span>\n<span style=\"color: #888888\">\/\/                that the transmission is complete (i.e. not busy) even though<\/span>\n<span style=\"color: #888888\">\/\/                it has not begun yet due to the synchronizer latency.<\/span>\n<span style=\"color: #888888\">\/\/                See the tester module \"uart_tx_tester.v\" for an example<\/span>\n<span style=\"color: #888888\">\/\/                of how this is managed using a short stretched HIGH time<\/span>\n<span style=\"color: #888888\">\/\/                for the trigger signal before polling the busy signal.<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/                The busy signal indicates when a transmission is in progress.<\/span>\n<span style=\"color: #888888\">\/\/                This is useful to throttle the parent module that is <\/span>\n<span style=\"color: #888888\">\/\/                sending data to this module, since UART serial<\/span>\n<span style=\"color: #888888\">\/\/                rates are typically slow by present day standards.<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/                Post transmission an additional delay is performed in<\/span>\n<span style=\"color: #888888\">\/\/                the \"cleanup\" state.  Not absolutely necessary, but makes <\/span>\n<span style=\"color: #888888\">\/\/                it easier to interpret on a logic analyzer or oscilloscope.<\/span>\n<span style=\"color: #888888\">\/\/                This comes at the expense of a slower back to back byte <\/span>\n<span style=\"color: #888888\">\/\/                repetition rate.  Many recipients probably can't handle <\/span>\n<span style=\"color: #888888\">\/\/                immediate back to back bytes, so not really a huge limitation.  <\/span>\n<span style=\"color: #888888\">\/\/                This area could be reworked if more performance is necessary.<\/span>\n<span style=\"color: #888888\">\/\/                <\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #003366; font-weight: bold\">`default_nettype<\/span> none                  <span style=\"color: #888888\">\/\/ Require all nets to be declared before used.<\/span>\n                                       <span style=\"color: #888888\">\/\/ --&gt; typo'd net names get trapped<\/span>\n\n<span style=\"color: #008800; font-weight: bold\">module<\/span> uart_tx\n(\n   <span style=\"color: #008800; font-weight: bold\">input<\/span>              clk_50M,         <span style=\"color: #888888\">\/\/ Input clock, assumed 50 MHz<\/span>\n   <span style=\"color: #008800; font-weight: bold\">input<\/span>     [<span style=\"color: #005588; font-weight: bold\">7<\/span><span style=\"color: #333333\">:<\/span><span style=\"color: #005588; font-weight: bold\">0<\/span>]    data_raw,        <span style=\"color: #888888\">\/\/ Data byte (8 bits) to transmit<\/span>\n   <span style=\"color: #008800; font-weight: bold\">input<\/span>              trigger_raw,     <span style=\"color: #888888\">\/\/ Tells module to begin transmission of data_raw byte<\/span>\n   \n   <span style=\"color: #008800; font-weight: bold\">output<\/span> <span style=\"color: #333399; font-weight: bold\">reg<\/span>         busy,            <span style=\"color: #888888\">\/\/ Flag to indicate a transmission is in progress<\/span>\n   <span style=\"color: #008800; font-weight: bold\">output<\/span> <span style=\"color: #333399; font-weight: bold\">reg<\/span>         serial_out       <span style=\"color: #888888\">\/\/ UART output serial datastream<\/span>\n);\n\n\n<span style=\"color: #333399; font-weight: bold\">reg<\/span>          [<span style=\"color: #005588; font-weight: bold\">3<\/span><span style=\"color: #333333\">:<\/span><span style=\"color: #005588; font-weight: bold\">0<\/span>]    tx_state  <span style=\"color: #333333\">=<\/span> <span style=\"color: #005588; font-weight: bold\">0<\/span>;   <span style=\"color: #888888\">\/\/ State variable for main finite state machine<\/span>\n \n<span style=\"color: #333399; font-weight: bold\">reg<\/span>          [<span style=\"color: #005588; font-weight: bold\">9<\/span><span style=\"color: #333333\">:<\/span><span style=\"color: #005588; font-weight: bold\">0<\/span>]    data_aug  <span style=\"color: #333333\">=<\/span> <span style=\"color: #005588; font-weight: bold\">0<\/span>;   <span style=\"color: #888888\">\/\/ Augmented data word to transmit that indludes START bit, data byte, <\/span>\n                                       <span style=\"color: #888888\">\/\/ and STOP BIT.  Note that details of ordering are explained in <\/span>\n                                       <span style=\"color: #888888\">\/\/ additional comments where this variable is used in the state machine.<\/span>\n                                     \n<span style=\"color: #333399; font-weight: bold\">reg<\/span>          [<span style=\"color: #005588; font-weight: bold\">3<\/span><span style=\"color: #333333\">:<\/span><span style=\"color: #005588; font-weight: bold\">0<\/span>]    tx_index  <span style=\"color: #333333\">=<\/span> <span style=\"color: #005588; font-weight: bold\">0<\/span>;   <span style=\"color: #888888\">\/\/ Index of bit currently transmitting<\/span>\n\n<span style=\"color: #333399; font-weight: bold\">reg<\/span>         [<span style=\"color: #005588; font-weight: bold\">31<\/span><span style=\"color: #333333\">:<\/span><span style=\"color: #005588; font-weight: bold\">0<\/span>]    bit_delay <span style=\"color: #333333\">=<\/span> <span style=\"color: #005588; font-weight: bold\">0<\/span>;   <span style=\"color: #888888\">\/\/ Timer to regulate baud rate.  Needs additional width for use in CLEANUP state.<\/span>\n\n<span style=\"color: #333399; font-weight: bold\">reg<\/span>                   trigger_0 <span style=\"color: #333333\">=<\/span> <span style=\"color: #005588; font-weight: bold\">0<\/span>;   <span style=\"color: #888888\">\/\/ Synchronizer on trigger input signal<\/span>\n<span style=\"color: #333399; font-weight: bold\">reg<\/span>                   trigger   <span style=\"color: #333333\">=<\/span> <span style=\"color: #005588; font-weight: bold\">0<\/span>;   <span style=\"color: #888888\">\/\/ Synchronizer on trigger input signal<\/span>\n\n\n<span style=\"color: #008800; font-weight: bold\">localparam<\/span> <span style=\"color: #003366; font-weight: bold\">STATE_IDLE<\/span>           <span style=\"color: #333333\">=<\/span> <span style=\"color: #005588; font-weight: bold\">4'b0000<\/span>; <span style=\"color: #888888\">\/\/ legal values for tx_state<\/span>\n<span style=\"color: #008800; font-weight: bold\">localparam<\/span> <span style=\"color: #003366; font-weight: bold\">STATE_TRANSMITTING<\/span>   <span style=\"color: #333333\">=<\/span> <span style=\"color: #005588; font-weight: bold\">4'b0001<\/span>; <span style=\"color: #888888\">\/\/ legal values for tx_state<\/span>\n<span style=\"color: #008800; font-weight: bold\">localparam<\/span> <span style=\"color: #003366; font-weight: bold\">STATE_CLEANUP<\/span>        <span style=\"color: #333333\">=<\/span> <span style=\"color: #005588; font-weight: bold\">4'b0010<\/span>; <span style=\"color: #888888\">\/\/ legal values for tx_state<\/span>\n\n\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  CLKS_PER_BIT regulates the baud rate.  This is the number of <\/span>\n<span style=\"color: #888888\">\/\/  input clock cycles to hold each each bit before shifting out <\/span>\n<span style=\"color: #888888\">\/\/  the next bit.  <\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  The calculation is as follows:<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/                                                  1<\/span>\n<span style=\"color: #888888\">\/\/     CLKS_PER_BIT =  F_clk [cycles\/sec] * --------------------<\/span>\n<span style=\"color: #888888\">\/\/                                           baud_rate[bit\/sec]<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  Some examples for common baud rates are listed below:<\/span>\n<span style=\"color: #888888\">\/\/  (assuming, 50 MHz input clock)<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/      target           CLKS_PER_BIT            actual<\/span>\n<span style=\"color: #888888\">\/\/    baud rate      (exact)    (rounded)      baud rate*<\/span>\n<span style=\"color: #888888\">\/\/    [bits\/sec]                               [bits\/sec]<\/span>\n<span style=\"color: #888888\">\/\/   -----------------------------------------------------<\/span>\n<span style=\"color: #888888\">\/\/         300      166,667.67   166,667          300.0<\/span>\n<span style=\"color: #888888\">\/\/       9,600        5,208.33     5,208        9,600.6<\/span>\n<span style=\"color: #888888\">\/\/      19,200        2,604.17     2,604       19,201.2   <\/span>\n<span style=\"color: #888888\">\/\/      38,400        1,302.08     1,302       38,402.5<\/span>\n<span style=\"color: #888888\">\/\/      57,600          868.06       868       57,603.7<\/span>\n<span style=\"color: #888888\">\/\/     115,200          434.03       434      115,207.4  <\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  For the baud rates in the table above, the baud rate <\/span>\n<span style=\"color: #888888\">\/\/  errors are less than 0.1%, though for other baud rates, <\/span>\n<span style=\"color: #888888\">\/\/  the errors may be larger.  <\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  300 baud was included on the low low range just to show<\/span>\n<span style=\"color: #888888\">\/\/  how large CLKS_PER_BIT can become for slow baud rates.<\/span>\n<span style=\"color: #888888\">\/\/  Slow baud rates drive the bit width required for the <\/span>\n<span style=\"color: #888888\">\/\/  associated counter variables.  <\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/  *assuming 50 MHz input clock has no error.<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n\n<span style=\"color: #888888\">\/\/localparam CLKS_PER_BIT = 166667;   \/\/     300 baud<\/span>\n<span style=\"color: #888888\">\/\/localparam CLKS_PER_BIT =   5208;   \/\/   9,600 baud<\/span>\n<span style=\"color: #888888\">\/\/localparam CLKS_PER_BIT =   2604;   \/\/  19,200 baud<\/span>\n<span style=\"color: #888888\">\/\/localparam CLKS_PER_BIT =   1302;   \/\/  38,400 baud<\/span>\n<span style=\"color: #008800; font-weight: bold\">localparam<\/span> <span style=\"color: #003366; font-weight: bold\">CLKS_PER_BIT<\/span> <span style=\"color: #333333\">=<\/span>    <span style=\"color: #005588; font-weight: bold\">868<\/span>;   <span style=\"color: #888888\">\/\/  57,600 baud<\/span>\n<span style=\"color: #888888\">\/\/localparam CLKS_PER_BIT =    434;   \/\/ 115,200 baud<\/span>\n\n\n<span style=\"color: #008800; font-weight: bold\">always<\/span> @(<span style=\"color: #008800; font-weight: bold\">posedge<\/span> clk_50M) <span style=\"color: #008800; font-weight: bold\">begin<\/span>\n\n   <span style=\"color: #008800; font-weight: bold\">case<\/span> (tx_state)\n   \n      <span style=\"color: #888888\">\/\/<\/span>\n      <span style=\"color: #888888\">\/\/ Wait for trigger condition indicating it's time to <\/span>\n      <span style=\"color: #888888\">\/\/ transmit a byte.<\/span>\n      <span style=\"color: #888888\">\/\/<\/span>\n      <span style=\"color: #997700; font-weight: bold\">STATE_IDLE:<\/span> <span style=\"color: #008800; font-weight: bold\">begin<\/span>\n      \n         busy       <span style=\"color: #333333\">&lt;=<\/span> <span style=\"color: #005588; font-weight: bold\">1'b0<\/span>;                           <span style=\"color: #888888\">\/\/ Indicate that transmitter is idle.<\/span>\n         serial_out <span style=\"color: #333333\">&lt;=<\/span> <span style=\"color: #005588; font-weight: bold\">1'b1<\/span>;                           <span style=\"color: #888888\">\/\/ Idle output HIGH, per standard UART behavior.<\/span>\n         \n         <span style=\"color: #008800; font-weight: bold\">if<\/span> (trigger) <span style=\"color: #008800; font-weight: bold\">begin<\/span>                            <span style=\"color: #888888\">\/\/ Check if received trigger to TX a byte<\/span>\n         \n            data_aug <span style=\"color: #333333\">&lt;=<\/span> {<span style=\"color: #005588; font-weight: bold\">1'b1<\/span>, data_raw[<span style=\"color: #005588; font-weight: bold\">7<\/span><span style=\"color: #333333\">:<\/span><span style=\"color: #005588; font-weight: bold\">0<\/span>], <span style=\"color: #005588; font-weight: bold\">1'b0<\/span>};   <span style=\"color: #888888\">\/\/ Create augmented byte with start and stop bits, note that the order<\/span>\n                                                       <span style=\"color: #888888\">\/\/   is: STOP bit, data MSB to LSB, START bit.   <\/span>\n                                                       <span style=\"color: #888888\">\/\/   Shifting this 10 bit word out then from LSB to MSB will<\/span>\n                                                       <span style=\"color: #888888\">\/\/   create a data stream that has the START and STOP bits in the <\/span>\n                                                       <span style=\"color: #888888\">\/\/   correct location and adheres the common convention<\/span>\n                                                       <span style=\"color: #888888\">\/\/   of the shifting the data byte out \"reversed\", i.e. LSB first.<\/span>\n                                                       <span style=\"color: #888888\">\/\/ This also has the benefit of latching in the data at the instant<\/span>\n                                                       <span style=\"color: #888888\">\/\/ this module is triggered.  As a result, if the parent module were <\/span>\n                                                       <span style=\"color: #888888\">\/\/ to change data_raw while this module is still shifting out the bits,<\/span>\n                                                       <span style=\"color: #888888\">\/\/ this module would not be adversely affected.<\/span>\n                                                       \n            busy      <span style=\"color: #333333\">&lt;=<\/span>  <span style=\"color: #005588; font-weight: bold\">1'b1<\/span>;                        <span style=\"color: #888888\">\/\/ Indicate that transmitter is busy.<\/span>\n            bit_delay <span style=\"color: #333333\">&lt;=<\/span> <span style=\"color: #005588; font-weight: bold\">32'b0<\/span>;                        <span style=\"color: #888888\">\/\/ Clear timer used to track duration of each bit, in clk cycles.<\/span>\n            tx_index  <span style=\"color: #333333\">&lt;=<\/span>  <span style=\"color: #005588; font-weight: bold\">4<\/span><span style=\"color: #0000DD; font-weight: bold\">'d0<\/span>;                        <span style=\"color: #888888\">\/\/ Point to first bit of data_aug to TX, namely the start bit<\/span>\n            tx_state  <span style=\"color: #333333\">&lt;=<\/span> <span style=\"color: #003366; font-weight: bold\">STATE_TRANSMITTING<\/span>;           <span style=\"color: #888888\">\/\/ move on to next state<\/span>\n            \n         <span style=\"color: #008800; font-weight: bold\">end<\/span>\n      <span style=\"color: #008800; font-weight: bold\">end<\/span>\n      \n      <span style=\"color: #888888\">\/\/<\/span>\n      <span style=\"color: #888888\">\/\/ Transmit all 10 bits in following order:<\/span>\n      <span style=\"color: #888888\">\/\/<\/span>\n      <span style=\"color: #888888\">\/\/   START   data   data   data   data   data   data   data   data   STOP<\/span>\n      <span style=\"color: #888888\">\/\/   BIT       0      1      2      3      4      5      6      7    BIT<\/span>\n      <span style=\"color: #888888\">\/\/<\/span>\n      <span style=\"color: #888888\">\/\/ with proper the proper duration per bit based on the slected baud rate.<\/span>\n      <span style=\"color: #888888\">\/\/<\/span>\n      <span style=\"color: #997700; font-weight: bold\">STATE_TRANSMITTING:<\/span> <span style=\"color: #008800; font-weight: bold\">begin<\/span>\n      \n         serial_out <span style=\"color: #333333\">&lt;=<\/span> data_aug[tx_index];    <span style=\"color: #888888\">\/\/ Set ouput based on current bit to transmit.<\/span>\n         bit_delay  <span style=\"color: #333333\">&lt;=<\/span> bit_delay <span style=\"color: #333333\">+<\/span> <span style=\"color: #005588; font-weight: bold\">32<\/span><span style=\"color: #0000DD; font-weight: bold\">'d1<\/span>;     <span style=\"color: #888888\">\/\/ Keep track of duration to hold this bit (i.e. regulates baud rate).<\/span>\n         \n         <span style=\"color: #008800; font-weight: bold\">if<\/span> (bit_delay<span style=\"color: #333333\">&gt;<\/span><span style=\"color: #003366; font-weight: bold\">CLKS_PER_BIT<\/span>) <span style=\"color: #008800; font-weight: bold\">begin<\/span>    <span style=\"color: #888888\">\/\/ Check if bit duration has expired.<\/span>\n         \n            <span style=\"color: #008800; font-weight: bold\">if<\/span> (tx_index<span style=\"color: #333333\">==<\/span><span style=\"color: #005588; font-weight: bold\">9<\/span>) <span style=\"color: #008800; font-weight: bold\">begin<\/span>            <span style=\"color: #888888\">\/\/ Check if just transmitted the final bit, i.e. the STOP bit.<\/span>\n            \n               tx_state <span style=\"color: #333333\">&lt;=<\/span> <span style=\"color: #003366; font-weight: bold\">STATE_CLEANUP<\/span>;     <span style=\"color: #888888\">\/\/ Move on to next state.<\/span>\n               \n            <span style=\"color: #008800; font-weight: bold\">end<\/span> <span style=\"color: #008800; font-weight: bold\">else<\/span> <span style=\"color: #008800; font-weight: bold\">begin<\/span>\n            \n               tx_index  <span style=\"color: #333333\">&lt;=<\/span> tx_index <span style=\"color: #333333\">+<\/span> <span style=\"color: #005588; font-weight: bold\">4<\/span><span style=\"color: #0000DD; font-weight: bold\">'d1<\/span>;  <span style=\"color: #888888\">\/\/ Still more bits to send so, point to next bit.<\/span>\n               bit_delay <span style=\"color: #333333\">&lt;=<\/span> <span style=\"color: #005588; font-weight: bold\">32<\/span><span style=\"color: #0000DD; font-weight: bold\">'d0<\/span>;            <span style=\"color: #888888\">\/\/ Clear counter used to regulate baud rate.<\/span>\n               \n            <span style=\"color: #008800; font-weight: bold\">end<\/span>\n            \n         <span style=\"color: #008800; font-weight: bold\">end<\/span> \n         \n      <span style=\"color: #008800; font-weight: bold\">end<\/span>\n      \n      <span style=\"color: #888888\">\/\/<\/span>\n      <span style=\"color: #888888\">\/\/ Pause for a few bit durations after full byte transmitted.  <\/span>\n      <span style=\"color: #888888\">\/\/ Not absolutely necessary, but makes it easier to interpret on a<\/span>\n      <span style=\"color: #888888\">\/\/ logic analyzer or oscilloscope.  This comes at the expense of <\/span>\n      <span style=\"color: #888888\">\/\/ a slower back to back byte repetition rate.  Many recipients <\/span>\n      <span style=\"color: #888888\">\/\/ probably can't handle immediate back to back bytes, so not a <\/span>\n      <span style=\"color: #888888\">\/\/ huge limitation.  This area could be reworked if more performance <\/span>\n      <span style=\"color: #888888\">\/\/ is necessary.<\/span>\n      <span style=\"color: #888888\">\/\/<\/span>\n      <span style=\"color: #997700; font-weight: bold\">STATE_CLEANUP:<\/span> <span style=\"color: #008800; font-weight: bold\">begin<\/span>\n   \n         bit_delay <span style=\"color: #333333\">&lt;=<\/span> bit_delay <span style=\"color: #333333\">+<\/span> <span style=\"color: #005588; font-weight: bold\">32<\/span><span style=\"color: #0000DD; font-weight: bold\">'d1<\/span>;      <span style=\"color: #888888\">\/\/ keep track of how long been in cleanup state.<\/span>\n         \n         <span style=\"color: #008800; font-weight: bold\">if<\/span> (bit_delay<span style=\"color: #333333\">&gt;<\/span><span style=\"color: #005588; font-weight: bold\">5<\/span><span style=\"color: #333333\">*<\/span><span style=\"color: #003366; font-weight: bold\">CLKS_PER_BIT<\/span>) <span style=\"color: #008800; font-weight: bold\">begin<\/span>  <span style=\"color: #888888\">\/\/ if paused HIGH long enough, then return to idle state.<\/span>\n         \n            tx_state <span style=\"color: #333333\">&lt;=<\/span> <span style=\"color: #003366; font-weight: bold\">STATE_IDLE<\/span>;           \n            \n         <span style=\"color: #008800; font-weight: bold\">end<\/span>      \n         \n      <span style=\"color: #008800; font-weight: bold\">end<\/span>\n      \n      <span style=\"color: #888888\">\/\/<\/span>\n      <span style=\"color: #888888\">\/\/ Should never get here, but if do, return to IDLE<\/span>\n      <span style=\"color: #888888\">\/\/<\/span>\n      <span style=\"color: #008800; font-weight: bold\">default<\/span><span style=\"color: #333333\">:<\/span> <span style=\"color: #008800; font-weight: bold\">begin<\/span>\n      \n         tx_state <span style=\"color: #333333\">&lt;=<\/span> <span style=\"color: #003366; font-weight: bold\">STATE_IDLE<\/span>;\n         \n      <span style=\"color: #008800; font-weight: bold\">end<\/span>\n      \n   <span style=\"color: #008800; font-weight: bold\">endcase<\/span>\n   \n<span style=\"color: #008800; font-weight: bold\">end<\/span>\n\n<span style=\"color: #888888\">\/\/     <\/span>\n<span style=\"color: #888888\">\/\/ Synchronizer for trigger input.  If this module is being used with an <\/span>\n<span style=\"color: #888888\">\/\/ asynchronous trigger input or certain types of clock domain<\/span>\n<span style=\"color: #888888\">\/\/ crossings, this can help with avoiding metastability.  <\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/ NOTE!!! -- If this module were used in an actual situation with<\/span>\n<span style=\"color: #888888\">\/\/            clock domain crossings or asynchronous inputs, <\/span>\n<span style=\"color: #888888\">\/\/            more attention (i.e. code changes) would be necessary to <\/span>\n<span style=\"color: #888888\">\/\/            manage the situation.<\/span>\n<span style=\"color: #888888\">\/\/                  <\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/ Visual depiction of the \"double flop\" synchronizer below:<\/span>\n<span style=\"color: #888888\">\/\/                      ___                   ___<\/span>\n<span style=\"color: #888888\">\/\/    trigger raw      |   |    trigger_0    |   |   trigger<\/span>\n<span style=\"color: #888888\">\/\/    -----------------|D Q|-----------------|D Q|----------------&gt;<\/span>\n<span style=\"color: #888888\">\/\/                     |   |                 |   |<\/span>\n<span style=\"color: #888888\">\/\/                   ,-|&gt;  |               ,-|&gt;  |<\/span>\n<span style=\"color: #888888\">\/\/                   |  ---                |  ---<\/span>\n<span style=\"color: #888888\">\/\/                   |                     |<\/span>\n<span style=\"color: #888888\">\/\/    clk ---------------------------------'<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n<span style=\"color: #888888\">\/\/ NOTE!!!  -- This synchronizer creates latency between assertion of the<\/span>\n<span style=\"color: #888888\">\/\/             trigger_raw input and actual initiation of the transmission.<\/span>\n<span style=\"color: #888888\">\/\/<\/span>\n\n<span style=\"color: #008800; font-weight: bold\">always<\/span> @(<span style=\"color: #008800; font-weight: bold\">posedge<\/span> clk_50M) <span style=\"color: #008800; font-weight: bold\">begin<\/span>\n\n   trigger_0 <span style=\"color: #333333\">&lt;=<\/span> trigger_raw;\n   trigger   <span style=\"color: #333333\">&lt;=<\/span> trigger_0;\n   \n<span style=\"color: #008800; font-weight: bold\">end<\/span>\n\n\n<span style=\"color: #008800; font-weight: bold\">endmodule<\/span>\n<\/pre><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This short Verilog project is intended for basic communications or as a debug tool for other larger projects. It implements a UART transmitter at a selectable baud rate, with the common &#8220;8N1&#8221; (8 data bits, no parity, 1 stop bit) format. I developed this on a Terasic DE10-Lite board, which<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1602,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"nf_dc_page":"","footnotes":""},"class_list":["post-1619","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>UART TX - ganslermike.com<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ganslermike.com\/?page_id=1619\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"UART TX - ganslermike.com\" \/>\n<meta property=\"og:description\" content=\"This short Verilog project is intended for basic communications or as a debug tool for other larger projects. It implements a UART transmitter at a selectable baud rate, with the common &#8220;8N1&#8221; (8 data bits, no parity, 1 stop bit) format. I developed this on a Terasic DE10-Lite board, which\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ganslermike.com\/?page_id=1619\" \/>\n<meta property=\"og:site_name\" content=\"ganslermike.com\" \/>\n<meta property=\"article:modified_time\" content=\"2022-01-29T19:37:47+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-logic-analyzer-full-message-ascii-and-bin-1024x400.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"16 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ganslermike.com\\\/?page_id=1619\",\"url\":\"https:\\\/\\\/ganslermike.com\\\/?page_id=1619\",\"name\":\"UART TX - ganslermike.com\",\"isPartOf\":{\"@id\":\"http:\\\/\\\/ganslermike.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ganslermike.com\\\/?page_id=1619#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ganslermike.com\\\/?page_id=1619#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/ganslermike.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/uart-tx-logic-analyzer-full-message-ascii-and-bin-1024x400.png\",\"datePublished\":\"2020-12-29T20:19:53+00:00\",\"dateModified\":\"2022-01-29T19:37:47+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ganslermike.com\\\/?page_id=1619#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ganslermike.com\\\/?page_id=1619\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ganslermike.com\\\/?page_id=1619#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/ganslermike.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/uart-tx-logic-analyzer-full-message-ascii-and-bin.png?fit=1911%2C746&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/ganslermike.com\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/uart-tx-logic-analyzer-full-message-ascii-and-bin.png?fit=1911%2C746&ssl=1\",\"width\":1911,\"height\":746},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ganslermike.com\\\/?page_id=1619#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\\\/\\\/ganslermike.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"FPGA\",\"item\":\"https:\\\/\\\/ganslermike.com\\\/?page_id=1602\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"UART TX\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\\\/\\\/ganslermike.com\\\/#website\",\"url\":\"http:\\\/\\\/ganslermike.com\\\/\",\"name\":\"ganslermike.com\",\"description\":\"electronics, flightsim, robots, and stuff\",\"publisher\":{\"@id\":\"http:\\\/\\\/ganslermike.com\\\/#\\\/schema\\\/person\\\/032aad67c31c143c210499ce1b84aa9e\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\\\/\\\/ganslermike.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\\\/\\\/ganslermike.com\\\/#\\\/schema\\\/person\\\/032aad67c31c143c210499ce1b84aa9e\",\"name\":\"mike.t.gansler\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/da4019a2041637d5c64d000774fccc108efe76eb985bf03f6fdae3985bf4e273?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/da4019a2041637d5c64d000774fccc108efe76eb985bf03f6fdae3985bf4e273?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/da4019a2041637d5c64d000774fccc108efe76eb985bf03f6fdae3985bf4e273?s=96&d=mm&r=g\",\"caption\":\"mike.t.gansler\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/da4019a2041637d5c64d000774fccc108efe76eb985bf03f6fdae3985bf4e273?s=96&d=mm&r=g\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"UART TX - ganslermike.com","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ganslermike.com\/?page_id=1619","og_locale":"en_US","og_type":"article","og_title":"UART TX - ganslermike.com","og_description":"This short Verilog project is intended for basic communications or as a debug tool for other larger projects. It implements a UART transmitter at a selectable baud rate, with the common &#8220;8N1&#8221; (8 data bits, no parity, 1 stop bit) format. I developed this on a Terasic DE10-Lite board, which","og_url":"https:\/\/ganslermike.com\/?page_id=1619","og_site_name":"ganslermike.com","article_modified_time":"2022-01-29T19:37:47+00:00","og_image":[{"url":"http:\/\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-logic-analyzer-full-message-ascii-and-bin-1024x400.png","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"16 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/ganslermike.com\/?page_id=1619","url":"https:\/\/ganslermike.com\/?page_id=1619","name":"UART TX - ganslermike.com","isPartOf":{"@id":"http:\/\/ganslermike.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ganslermike.com\/?page_id=1619#primaryimage"},"image":{"@id":"https:\/\/ganslermike.com\/?page_id=1619#primaryimage"},"thumbnailUrl":"https:\/\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-logic-analyzer-full-message-ascii-and-bin-1024x400.png","datePublished":"2020-12-29T20:19:53+00:00","dateModified":"2022-01-29T19:37:47+00:00","breadcrumb":{"@id":"https:\/\/ganslermike.com\/?page_id=1619#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ganslermike.com\/?page_id=1619"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ganslermike.com\/?page_id=1619#primaryimage","url":"https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-logic-analyzer-full-message-ascii-and-bin.png?fit=1911%2C746&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ganslermike.com\/wp-content\/uploads\/2021\/01\/uart-tx-logic-analyzer-full-message-ascii-and-bin.png?fit=1911%2C746&ssl=1","width":1911,"height":746},{"@type":"BreadcrumbList","@id":"https:\/\/ganslermike.com\/?page_id=1619#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/ganslermike.com\/"},{"@type":"ListItem","position":2,"name":"FPGA","item":"https:\/\/ganslermike.com\/?page_id=1602"},{"@type":"ListItem","position":3,"name":"UART TX"}]},{"@type":"WebSite","@id":"http:\/\/ganslermike.com\/#website","url":"http:\/\/ganslermike.com\/","name":"ganslermike.com","description":"electronics, flightsim, robots, and stuff","publisher":{"@id":"http:\/\/ganslermike.com\/#\/schema\/person\/032aad67c31c143c210499ce1b84aa9e"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/ganslermike.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"http:\/\/ganslermike.com\/#\/schema\/person\/032aad67c31c143c210499ce1b84aa9e","name":"mike.t.gansler","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/da4019a2041637d5c64d000774fccc108efe76eb985bf03f6fdae3985bf4e273?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/da4019a2041637d5c64d000774fccc108efe76eb985bf03f6fdae3985bf4e273?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/da4019a2041637d5c64d000774fccc108efe76eb985bf03f6fdae3985bf4e273?s=96&d=mm&r=g","caption":"mike.t.gansler"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/da4019a2041637d5c64d000774fccc108efe76eb985bf03f6fdae3985bf4e273?s=96&d=mm&r=g"}}]}},"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ganslermike.com\/index.php?rest_route=\/wp\/v2\/pages\/1619","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ganslermike.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/ganslermike.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/ganslermike.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ganslermike.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1619"}],"version-history":[{"count":5,"href":"https:\/\/ganslermike.com\/index.php?rest_route=\/wp\/v2\/pages\/1619\/revisions"}],"predecessor-version":[{"id":4043,"href":"https:\/\/ganslermike.com\/index.php?rest_route=\/wp\/v2\/pages\/1619\/revisions\/4043"}],"up":[{"embeddable":true,"href":"https:\/\/ganslermike.com\/index.php?rest_route=\/wp\/v2\/pages\/1602"}],"wp:attachment":[{"href":"https:\/\/ganslermike.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}