{"id":691,"date":"2015-05-15T10:35:01","date_gmt":"2015-05-15T18:35:01","guid":{"rendered":"http:\/\/www.beyond-circuits.com\/wordpress\/?page_id=691"},"modified":"2016-09-23T14:57:06","modified_gmt":"2016-09-23T22:57:06","slug":"part3","status":"publish","type":"page","link":"https:\/\/www.beyond-circuits.com\/wordpress\/tutorial\/tutorial18\/part3\/","title":{"rendered":"Tutorial 18: I2S Receiver, part three"},"content":{"rendered":"<h1>Clocking<\/h1>\n<p>Until now, we have just been using the <em>sck<\/em> signal, which is sent by the I2S master. This has kept things simple, but is probably not what we want to do in real life.<\/p>\n<p>Inside an FPGA, there may be tens of thousands (or even hundreds of thousands) of flip-flops all running off a single clock. The clock has to arrive at each of those flip-flops at pretty much exactly the same time. By &#8220;pretty much exactly&#8221;, I mean down-to-the-nanosecond exactly. The FPGA achieves this by using special clock distribution networks within the FPGA. There&#8217;s a finite number of these networks\u2013 really, only a handful. So, it&#8217;s kind of a big deal to make a signal a clock. In addition, multiple clocks increase the complexity of the static timing analysis which\u00a0needs to occur when synthesizing the device. This can lead to subtle bugs in the design. In short, you really want to minimize the number of clocks in a design.<\/p>\n<p>But what can we do? The I2S interface uses a clock. Doesn&#8217;t that mean we need to use that clock signal? Not really. The <em>sck<\/em> signal is really pretty slow in reality. Normally it is 48 times the audio sample rate, which is, at most, 48KHz. That is 2.3MHz. Maybe in a crazy world where you have 32 bit samples and a 96KHz sample rate you might get it up to the blazing speed of 6.144MHz. Not really all that fast, by FPGA standards.<\/p>\n<div id=\"attachment_785\" style=\"width: 310px\" class=\"wp-caption alignright\"><a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/04\/tutorial18_clk_detect_bd.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-785\" class=\"size-medium wp-image-785\" src=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/04\/tutorial18_clk_detect_bd-300x118.png\" alt=\"SCK edge detect circuit\" width=\"300\" height=\"118\" srcset=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/04\/tutorial18_clk_detect_bd-300x118.png 300w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/04\/tutorial18_clk_detect_bd.png 737w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/04\/tutorial18_clk_detect_bd-500x197.png 500w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-785\" class=\"wp-caption-text\">SCK edge detect circuit<\/p><\/div>\n<p>We can fix this by sampling the sck signal with a much faster FPGA clock. This will be more convenient for us to use. Since <em>sck<\/em> is an asynchronous signal, it is critical that it only go to one flip-flop in our design. If <em>sck<\/em> went to two flip-flops, if it rose at the same time as <em>clk<\/em>, it might get clocked in to one flip-flop but not the other. The circuit shown to the right safely samples the <em>sck<\/em> signal and produces two signals in the <em>clk<\/em> clock domain which pulse whenever <em>sck<\/em> rises or falls.<\/p>\n<p>We can now use those signals as enables to condition the always blocks we had before. In other words, we used to have this always block:<\/p>\n<pre><code>always @(posedge sck)\r\n  wsd &lt;= ws;\r\n<\/code><\/pre>\n<p>We could now use this one:<\/p>\n<pre><code>always @(posedge clk)\r\n  if (sck_rise) wsd &lt;= ws;\r\n<\/code><\/pre>\n<p>As long as our new clock <em>clk<\/em> is more than twice as fast as <em>sck<\/em>, the logic will still work.<\/p>\n<h1>Files<\/h1>\n<p>Here is the test for this version of the receiver.<\/p>\n<ul>\n<li><a href=\"https:\/\/www.beyond-circuits.com\/repos\/tutorial\/trunk\/tests\/i2s_receive3_test.v\">i2s_receive3_test.v<\/a><\/li>\n<\/ul>\n<p>In our <a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/tutorial\/tutorial18\/part4\/\">next<\/a> tutorial, we will add an AXI4 Streaming interface, so we can use our block in the Vivado IP Integrator tool.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Clocking Until now, we have just been using the sck signal, which is sent by the I2S master. This has kept things simple, but is probably not what we want to do in real life. Inside an FPGA, there may &hellip; <a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/tutorial\/tutorial18\/part3\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":638,"menu_order":3,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-691","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/pages\/691","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=691"}],"version-history":[{"count":6,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/pages\/691\/revisions"}],"predecessor-version":[{"id":1094,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/pages\/691\/revisions\/1094"}],"up":[{"embeddable":true,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/pages\/638"}],"wp:attachment":[{"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/media?parent=691"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}