{"id":667,"date":"2015-05-04T08:12:11","date_gmt":"2015-05-04T16:12:11","guid":{"rendered":"http:\/\/www.beyond-circuits.com\/wordpress\/?page_id=667"},"modified":"2016-09-23T14:44:42","modified_gmt":"2016-09-23T22:44:42","slug":"discussion","status":"publish","type":"page","link":"https:\/\/www.beyond-circuits.com\/wordpress\/tutorial\/tutorial18\/part2\/discussion\/","title":{"rendered":"Tutorial 18, Part 2: Discussion"},"content":{"rendered":"<h1>Spoiler alert!<\/h1>\n<p>Don&#8217;t read any further unless you have gotten your design working for part two of tutorial 18. Well, at least the spirit of tutorial 18 is that you should really try to work it out on your own. This section will walk through some code examples in detail.<\/p>\n<h1>The literal implementation<\/h1>\n<p>You can go to the block diagram and just literally code everything that appears there. First we have the module declaration:<\/p>\n<pre><code>`timescale 1ns\/1ns\r\nmodule i2s_receive2a\r\n  (\r\n   input sck,\r\n   input ws,\r\n   input sd,\r\n   output reg [31:0] data_left,\r\n   output reg [31:0] data_right\r\n   );\r\n<\/code><\/pre>\n<p>Next, we need to implement the two flip-flops which delay the <em>WS<\/em> signal by a clock. The part of the diagram that implements this is shown to the right.<a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright wp-image-668 size-medium\" src=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail1-300x116.png\" alt=\"I2S_receiver2_detail1\" width=\"300\" height=\"116\" srcset=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail1-300x116.png 300w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail1-500x194.png 500w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail1.png 719w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a> We will of course need two register values. One is called <em>wsd<\/em>, presumably for <em>WS<\/em> delayed. The second has no name in the figure and I just called it <em>wsdd<\/em>, for <em>wsd<\/em> delayed. I have also chosen to initialize <em>wsd<\/em> to zero. The code for this is really quite simple.<\/p>\n<pre><code>  reg wsd = 0;\r\n  always @(posedge sck)\r\n    wsd &lt;= ws;\r\n\r\n  reg wsdd;\r\n  always @(posedge sck)\r\n    wsdd &lt;= wsd;\r\n<\/code><\/pre>\n<p>We also need a combinational XOR of <em>wsd<\/em> and <em>wsdd<\/em> and call that <em>wsp<\/em>. I do that like this:<\/p>\n<pre><code>wire wsp = wsd ^ wsdd;<\/code><\/pre>\n<p>This uses the Verilog exclusive OR operator <code>^<\/code>. We could also write it like this:<\/p>\n<pre><code>wire wsp = wsd != wsdd;<\/code><\/pre>\n<p>This might be a little more expressive of our intent. We want a single clock pulse when the two signals are different. Ne<img loading=\"lazy\" decoding=\"async\" class=\" wp-image-672 size-medium alignright\" src=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail2-300x228.png\" alt=\"I2S_receiver2_detail2\" width=\"300\" height=\"228\" srcset=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail2-300x228.png 300w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail2-395x300.png 395w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail2.png 627w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/>xt, we see that we need 32 enable signals for the flip-flops that capture the <em>SD<\/em> data input. Actually, if you look at the counter, you see that we need an additional one for when the counter is 32 to keep it from counting further.<\/p>\n<p>Let&#8217;s declare those:<\/p>\n<pre><code>wire en0;\r\nwire en1;\r\nwire en2;\r\n<\/code>...<code>\r\nwire en31;\r\nwire en32;\r\n<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-672 size-medium alignright\" src=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail2-300x228.png\" alt=\"I2S_receiver2_detail2\" width=\"300\" height=\"228\" srcset=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail2-300x228.png 300w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail2-395x300.png 395w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail2.png 627w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/>Next, we&#8217;ll\u00a0focus on the counter. It needs to count from zero to 32. We declare this to be a 6-bit register. Remember, six bits are needed to represent 0 to 32. Here is the counter. Also notice that it is clocked on the negative edge of <em>SCK:<\/em><\/p>\n<pre><code>  reg [5:0] counter;\r\n  always @(negedge sck)\r\n    if (wsp)\r\n      counter &lt;= 0;\r\n    else if (!en32)\r\n      counter &lt;= counter+1;\r\n<\/code><\/pre>\n<p>Then we need to also assign to the enable signals. Here is that code:<\/p>\n<pre><code>  assign en0 = counter == 0;\r\n  assign en1 = counter == 1;\r\n  assign en2 = counter == 2;\r\n  <\/code>...<code>\r\n  assign en31 = counter == 31;\r\n  assign en32 = counter == 32;\r\n<\/code><\/pre>\n<p>Next, let&#8217;s focus on the register that captures the data. In the previous example, the register was called <em>shift<\/em>. We will stick with that name, even though it&#8217;s no longer technically a shift register. It still kind of functions that way, so I think the name still makes sense. <img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-673\" src=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail3-1024x276.png\" alt=\"I2S_receiver2_detail3\" width=\"584\" height=\"157\" srcset=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail3-1024x276.png 1024w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail3-300x81.png 300w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail3-500x135.png 500w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail3-900x242.png 900w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail3.png 1073w\" sizes=\"auto, (max-width: 584px) 100vw, 584px\" \/>Notice that EN0 enables the most significant bit to be written. and EN31 enables the least significant bit. That means we naturally want the MSB of shift to be bit zero and the LSB of shift to be bit 31. So we declare shift as follows.<\/p>\n<pre><code>reg [0:31] shift;<\/code><\/pre>\n<p>Also, notice that bit zero is different from the other bits. It has no reset input while the others do. Let&#8217;s code that bit first:<\/p>\n<pre><code>always @(posedge sck)\r\n  if (en0)\r\n    shift[0] &lt;= sd;\r\n<\/code><\/pre>\n<p>And for the other registers which are reset by <em>wsp<\/em>, we have the following code:<\/p>\n<pre><code>always @(posedge sck)\r\n  if (wsp)\r\n    shift[1] &lt;= 0;\r\n  else if (en1)\r\n    shift[1] &lt;= sd;\r\n  <\/code>...<code>\r\n  always @(posedge sck)\r\n    if (wsp)\r\n      shift[31] &lt;= 0;\r\n    else if (en31)\r\n      shift[31] &lt;= sd;\r\n<\/code><\/pre>\n<p>The final part of the design is to write to the <em>data_left<\/em> and <em>data_right<\/em> output registers. Here is the relevant portion of the diagram. Basically the <em>wsp<\/em> signal indicates that one of the two registers should be written and <em>wsd<\/em> indicates which one should be written. When <em>wsp<\/em> is high, the left register is written, and when <em>wsp<\/em> is low, the right register is written.<a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-675\" src=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail4-1024x157.png\" alt=\"I2S_receiver2_detail4\" width=\"584\" height=\"90\" srcset=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail4-1024x157.png 1024w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail4-300x46.png 300w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail4-500x76.png 500w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail4-900x138.png 900w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/05\/I2S_receiver2_detail4.png 1170w\" sizes=\"auto, (max-width: 584px) 100vw, 584px\" \/><\/a><\/p>\n<p>Here is the code for that:<\/p>\n<pre><code>always @(posedge sck)\r\n  if (wsd &amp;&amp; wsp)\r\n    data_left &lt;= shift;\r\n\r\nalways @(posedge sck)\r\n  if (!wsd &amp;&amp; wsp)\r\n    data_right &lt;= shift;\r\n<\/code><\/pre>\n<p>Don&#8217;t forget the <code>endmodule<\/code> to close it off.<\/p>\n<h1>Thoughts<\/h1>\n<p>So there you have it. 296\u00a0lines of Verilog code to implement our I2S receiver. Are you happy with it? Probably half of all FPGA designers would pat themselves on the back for a job well done and go on to the next assignment. But really, didn&#8217;t you think while typing all those lines of code that it was really repetitive? Didn&#8217;t it seem like you should have a computer program to help you type all those lines of code which are almost all the same? Those are signs that we can do a better job.<\/p>\n<h1>The Rev B Design<\/h1>\n<p>OK, well first we have 33 nets called <em>en<strong>n<\/strong><\/em>. That is just silly. The first thing we need to do is to make that be a vector. Let&#8217;s change the declaration to this.<\/p>\n<pre><code>wire [32:0] en;<\/code><\/pre>\n<p>We also need to change all the places that have <em>en<b>n<\/b><\/em> to <em>en[<b>n<\/b>]<\/em>. By my count that gets us down to 264 lines. Still not too much in terms of removing the repetitive nature of things.<\/p>\n<h1>The Power of <em>for<\/em> Loops<\/h1>\n<p>Many logic designers don&#8217;t understand that you can use Verilog <strong>for<\/strong> loops in synthesized RTL code. There is just one simple restriction on their use. The loop you write has to be able to be completely unrolled. What that means is that the loop essentially needs to be run when the code is parsed. It has to take a fixed number of iterations through the loop. The number of iterations has to be known when the code is synthesized.<\/p>\n<h1>The Rev C Design<\/h1>\n<p>Let&#8217;s attack those 33 lines where we make the assignment to the enable bits. First, the enable assignments were continuous assignments to <em>en<\/em>\u00a0which was declared as a <strong>wire<\/strong>. We first need to change that to a reg so we can assign to it in a combinational always block.<\/p>\n<pre><code>reg [32:0] en;<\/code><\/pre>\n<p>Now, if we don&#8217;t use the loop, we would need to code the assignments to <em>EN<\/em> like this.<\/p>\n<pre><code>always @(*)\r\n  en[0] = count == 0;\r\n\r\nalways @(*)\r\n  en[1] = count == 1;\r\n\r\n...\r\n\r\nalways @(*)\r\n  en[32] = count == 32;\r\n<\/code><\/pre>\n<p>Even more lines of code! But with a <b>for<\/b> loop we can code them like this.<\/p>\n<pre><code>integer i;\r\nalways @(*)\r\n  for(i=0; i&lt;=32; i=i+1)\r\n    en[i] = counter == i;\r\n<\/code><\/pre>\n<p>That&#8217;s it. A big space savings. And it has some other advantages we will discuss later. Let&#8217;s attack those assignments to <em>shift<\/em> while we&#8217;re at it.<\/p>\n<p>Bit zero of shift has no reset so it is different. We will leave that alone. But bits 1 through 32 will get written using a <strong>for<\/strong> loop.<\/p>\n<pre><code>  always @(posedge sck)\r\n    for (i=1; i&lt;32; i=i+1)\r\n      if (wsp)\r\n\tshift[i] &lt;= 0;\r\n      else if (en[i])\r\n\tshift[i] &lt;= sd;\r\n<\/code><\/pre>\n<p>Note that we don&#8217;t need to declare <em>i<\/em> again. We are using the same <em>i<\/em> variable as the previous <strong>for<\/strong> loop.<\/p>\n<p>This reduces our design down to 44 lines of Verilog code. That&#8217;s a real improvement. But our improvements aren&#8217;t over yet.<\/p>\n<h1>Parameterization<\/h1>\n<p>Notice that the width of our module is hardwired to 32 bits. In the first two designs that is not really an issue because our code was hardwired to 32 bits as well. You couldn&#8217;t change the number without adding lines of code to the enable and shift assignments. But with the improvements in version C we now just have numbers scattered around the code which we <em>can<\/em> derive from a parameter.<\/p>\n<p>In general, I believe you should try to always write your code such that it is parameterized. This more than any other rule will guide you to writing good Verilog code. You should go ahead and change the design to take a parameter called <em>width<\/em> with a default value of 32.<\/p>\n<p>Remember to use the <strong>$clog2<\/strong> function to determine the number of bits needed for the counter. It might take a little thought to get the expression for the width of the counter exactly right. For a width of 32 the counter should be six bits wide. But if width is 31 the counter should only be five bits. If width is 63 then the counter should still only be six bits.<\/p>\n<p>We will call this version D of the design. But there are more improvements to come.<\/p>\n<h1>A Better Encoder<\/h1>\n<p>If you run a simulation of the previous design and look at the <em>counter<\/em> value and the <em>en<\/em> value you will notice that <em>en<\/em> is just two raised to the <em>counter<\/em>. In other words they have the following relationship.<\/p>\n<div class=\"table-responsive\"><table  style=\"width:100%; \"  class=\"easy-table easy-table-default \" border=\"0\">\n<thead>\r\n<tr><th ><em>counter<\/em><\/th>\n<th ><em>en<\/em><\/th>\n<th ><em>en<\/em>(binary)<\/th>\n<\/tr>\n<\/thead>\n<tbody>\r\n<tr><td >0<\/td>\n<td >1<\/td>\n<td >000000001<sub>2<\/sub><\/td>\n<\/tr>\n\r\n<tr><td >1<\/td>\n<td >2<\/td>\n<td >000000010<sub>2<\/sub><\/td>\n<\/tr>\n\r\n<tr><td >2<\/td>\n<td >4<\/td>\n<td >000000100<sub>2<\/sub><\/td>\n<\/tr>\n\r\n<tr><td >3<\/td>\n<td >8<\/td>\n<td >000001000<sub>2<\/sub><\/td>\n<\/tr>\n\r\n<tr><td >4<\/td>\n<td >16<\/td>\n<td >000010000<sub>2<\/sub><\/td>\n<\/tr>\n\r\n<tr><td >5<\/td>\n<td >32<\/td>\n<td >000100000<sub>2<\/sub><\/td>\n<\/tr>\n\r\n<tr><td >6<\/td>\n<td >64<\/td>\n<td >001000000<sub>2<\/sub><\/td>\n<\/tr>\n\r\n<tr><td >7<\/td>\n<td >128<\/td>\n<td >010000000<sub>2<\/sub><\/td>\n<\/tr>\n\r\n<tr><td >8<\/td>\n<td >256<\/td>\n<td >100000000<sub>2<\/sub><\/td>\n<\/tr>\n<\/tbody><\/table><\/div>\n<p>A common way to implement a decoder like this is to just shift 1 left by the <em>count<\/em> amount. So we can replace our <strong>for<\/strong> loop with just the following.<\/p>\n<pre><code>always @(*)\r\n  en = 1&lt;&lt;counter;\r\n<\/code><\/pre>\n<h1>Simplifying the <em>shift<\/em> Assignment<\/h1>\n<p>Getting back to the D version of the design, you may recall that we had two always blocks to assign to the <em>shift<\/em> variable. One used a for loop to assign to bits 1 through 31 because they needed a reset. And a separate one to assign to bit zero where there was no reset. Here is the code for that again.<\/p>\n<pre><code>  reg [0:width-1] shift;\r\n  always @(posedge sck)\r\n    if (en[0]) shift[0] &lt;= sd;\r\n\r\n  integer i;\r\n  always @(posedge sck)\r\n    for (i=1; i&lt;width; i=i+1)\r\n      if (wsp)\r\n\tshift[i] &lt;= 0;\r\n      else if (en[i])\r\n\tshift[i] &lt;= sd;\r\n<\/code><\/pre>\n<p>We can actually merge these two always blocks. If you look at a timing diagram from an existing simulation you will see that wsp is only true then counter is equal to zero. Why? Because wsp actually resets counter. This means when <em>wsp<\/em> is high, <em>en<\/em>[0] is also high. If another bit of <em>en<\/em> is set, then <em>wsp<\/em> must be low. This means we can remove the <strong>else<\/strong> from the second always block. It also means that we can extend the for loop to include index zero now. In the zero case we reset <em>shift<\/em>[0] in the first <strong>if<\/strong>, but we immediately write <em>sd<\/em> into it with the second <strong>if<\/strong>. This has the effect of not resetting it at all. So the new code looks like this.<\/p>\n<pre><code>  reg [0:width-1] shift;\r\n  integer i;\r\n  always @(posedge sck)\r\n    for (i=0; i&lt;width; i=i+1)\r\n      begin\r\n\tif (wsp)\r\n\t  shift[i] &lt;= 0;\r\n\tif (en[i])\r\n\t  shift[i] &lt;= sd;\r\n      end\r\n<\/code><\/pre>\n<h1>Another Option for the Enable<\/h1>\n<p>Instead of shifting 1 left there is another way we can implement the <em>en<\/em> signal. Let&#8217;s change it back into a reg signal and think about the following. As we showed in the last section if you write to the same bit multiple times in an <strong>always<\/strong> block it is the last write that actually takes effect. We can make an <strong>always<\/strong> block which sets the <em>en<\/em> value to zero and then just sets the bit indexed by <em>counter<\/em> to one. That code looks like this.<\/p>\n<pre><code>  always @(*)\r\n    begin\r\n      en = 0;\r\n      en[counter] = 1;\r\n    end\r\n<\/code><\/pre>\n<h1>The Biggest Leap<\/h1>\n<p>Now let&#8217;s out the thinking from the last insight to work for the final thoughts on setting the <em>shift<\/em> value. First, let&#8217;s look at what en is really telling us. Bit <em>n<\/em> of <em>en<\/em> is true if <em>counter<\/em> equals <em>n<\/em>. So, let&#8217;s rewrite the always block where we assign shift to just use the expression for the active bit in <em>en<\/em>.<\/p>\n<pre><code>  reg [0:width-1] shift;\r\n  integer i;\r\n  always @(posedge sck)\r\n    for (i=0; i&lt;width; i=i+1)\r\n      begin\r\n\tif (wsp)\r\n\t  shift[i] &lt;= 0;\r\n\tif (counter == i)\r\n\t  shift[i] &lt;= sd;\r\n      end\r\n<\/code><\/pre>\n<p>Next, let&#8217;s factor the reset value for shift to outside the <strong>for<\/strong> loop.<\/p>\n<pre><code>  reg [0:width-1] shift;\r\n  integer i;\r\n  always @(posedge sck)\r\n    begin\r\n      if (wsp) shift &lt;= 0;\r\n      for (i=0; i&lt;width; i=i+1)\r\n\tif (counter == i)\r\n\t  shift[i] &lt;= sd;\r\n    end\r\n<\/code><\/pre>\n<p>Now, if you look at that for loop it should look like one of the dumbest loops ever written. Why is it a loop at all? Let&#8217;s fix that once and for all.<\/p>\n<pre><code>  reg [0:width-1] shift;\r\n  always @(posedge sck)\r\n    begin\r\n      if (wsp) shift &lt;= 0;\r\n      shift[counter] &lt;= sd;\r\n    end\r\n<\/code><\/pre>\n<p>Notice that we don&#8217;t even need the <em>en<\/em> signal at all any more.<\/p>\n<h1>A Very Subtle Problem<\/h1>\n<p>There is a very subtle problem with this design however. It has to do with synthesis. What happens when <em>counter<\/em> is equal to 32? Well, <em>shift<\/em> only has bits 0 through 31. So, from an RTL perspective we are assigning to a nonexistent bit. Unfortunately, there is a bug in the Vivado synthesis tool through at least version 2015.1 where this is not what happens. Because of this bug, the <em>counter<\/em> value is essentially truncated and will set bit zero of <em>shift<\/em> when <em>counter<\/em> is 32.\u00a0<span style=\"color: #000000;\"><em>You must be extremely careful when indexing into bit vectors and arrays (RAMs) that you don&#8217;t exceed the bounds of the vector or array. The synthesis tool will happily wrap those accesses such that they actually modify the vector or array.<\/em><\/span><\/p>\n<p>You can test this by running the simulation using the synthesized results. You will see that in about half of the cases where the sample size is greater than 32 bits the test will fail.<\/p>\n<p>So we must modify that final always block just a little bit. Here is a fix for the issue.<\/p>\n<pre><code>  reg [0:width-1] shift;\r\n  always @(posedge sck)\r\n    begin\r\n      if (wsp) shift &lt;= 0;\r\n      if (counter &lt; width) shift[counter] &lt;= sd;\r\n    end\r\n<\/code><\/pre>\n<p>This will synthesize correctly since we have explicitly added the check which the synthesis tool should have done automatically.<\/p>\n<h1>Synthesis<\/h1>\n<p>Speaking of synthesis, I have synthesized each of these designs to see how they compared size wise. Here are the results.<\/p>\n<div class=\"table-responsive\"><table  style=\"width:100%; \"  class=\"easy-table easy-table-default \" border=\"0\">\n<thead>\r\n<tr><th >module<\/th>\n<th > cells<\/th>\n<th > ports<\/th>\n<th > nets<\/th>\n<th > luts<\/th>\n<th > registers<\/th>\n<\/tr>\n<\/thead>\n<tbody>\r\n<tr><td >i2s_receive2a<\/td>\n<td >218<\/td>\n<td >67<\/td>\n<td >223<\/td>\n<td >42<\/td>\n<td >104<\/td>\n<\/tr>\n\r\n<tr><td >i2s_receive2b<\/td>\n<td >241<\/td>\n<td >67<\/td>\n<td >246<\/td>\n<td >54<\/td>\n<td >104<\/td>\n<\/tr>\n\r\n<tr><td >i2s_receive2c<\/td>\n<td >218<\/td>\n<td >67<\/td>\n<td >223<\/td>\n<td >42<\/td>\n<td >104<\/td>\n<\/tr>\n\r\n<tr><td >i2s_receive2d<\/td>\n<td >218<\/td>\n<td >67<\/td>\n<td >223<\/td>\n<td >42<\/td>\n<td >104<\/td>\n<\/tr>\n\r\n<tr><td >i2s_receive2e<\/td>\n<td >218<\/td>\n<td >67<\/td>\n<td >223<\/td>\n<td >42<\/td>\n<td >104<\/td>\n<\/tr>\n\r\n<tr><td >i2s_receive2f<\/td>\n<td >230<\/td>\n<td >67<\/td>\n<td >235<\/td>\n<td >48<\/td>\n<td >104<\/td>\n<\/tr>\n\r\n<tr><td >i2s_receive2g<\/td>\n<td >230<\/td>\n<td >67<\/td>\n<td >235<\/td>\n<td >48<\/td>\n<td >104<\/td>\n<\/tr>\n\r\n<tr><td >i2s_receive2h<\/td>\n<td >241<\/td>\n<td >67<\/td>\n<td >246<\/td>\n<td >54<\/td>\n<td >104<\/td>\n<\/tr>\n\r\n<tr><td >i2s_receive2*<\/td>\n<td >222<\/td>\n<td >67<\/td>\n<td >227<\/td>\n<td >44<\/td>\n<td >104<\/td>\n<\/tr>\n\r\n<tr><td >i2s_receive2<\/td>\n<td >230<\/td>\n<td >67<\/td>\n<td >235<\/td>\n<td >48<\/td>\n<td >104<\/td>\n<\/tr>\n<\/tbody><\/table><\/div>\n<p>The design with the asterisk is the final design without the bounds check. The final design is a little larger, but I like the RTL code. It is pretty clean with no for loops and it is quite short. But it is not the smallest in terms of area.<\/p>\n<p>I have linked to each of the designs below.<\/p>\n<ul>\n<li><a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/tutorials\/tutorial18\/i2s_receive2a.v\">i2s_receive2a.v<\/a><\/li>\n<li><a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/tutorials\/tutorial18\/i2s_receive2b.v\">i2s_receive2b.v<\/a><\/li>\n<li><a href=\"https:\/\/www.beyond-circuits.com\/repos\/tutorial\/trunk\/rtl\/i2s_receive2c.v\">i2s_receive2c.v<\/a><\/li>\n<li><a href=\"https:\/\/www.beyond-circuits.com\/repos\/tutorial\/trunk\/rtl\/i2s_receive2d.v\">i2s_receive2d.v<\/a><\/li>\n<li><a href=\"https:\/\/www.beyond-circuits.com\/repos\/tutorial\/trunk\/rtl\/i2s_receive2e.v\">i2s_receive2e.v<\/a><\/li>\n<li><a href=\"https:\/\/www.beyond-circuits.com\/repos\/tutorial\/trunk\/rtl\/i2s_receive2f.v\">i2s_receive2f.v<\/a><\/li>\n<li><a href=\"https:\/\/www.beyond-circuits.com\/repos\/tutorial\/trunk\/rtl\/i2s_receive2g.v\">i2s_receive2g.v<\/a><\/li>\n<li><a href=\"https:\/\/www.beyond-circuits.com\/repos\/tutorial\/trunk\/rtl\/i2s_receive2.v\">i2s_receive2.v<\/a><\/li>\n<\/ul>\n<p>You can follow next part of this tutorial <a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/tutorial\/tutorial18\/part3\/\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spoiler alert! Don&#8217;t read any further unless you have gotten your design working for part two of tutorial 18. Well, at least the spirit of tutorial 18 is that you should really try to work it out on your own. &hellip; <a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/tutorial\/tutorial18\/part2\/discussion\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":649,"menu_order":1,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-667","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/pages\/667","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/comments?post=667"}],"version-history":[{"count":21,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/pages\/667\/revisions"}],"predecessor-version":[{"id":1092,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/pages\/667\/revisions\/1092"}],"up":[{"embeddable":true,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/pages\/649"}],"wp:attachment":[{"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/media?parent=667"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}