{"id":733,"date":"2014-01-26T14:09:58","date_gmt":"2014-01-26T14:09:58","guid":{"rendered":"http:\/\/retroramblings.net\/?p=733"},"modified":"2014-01-26T14:09:58","modified_gmt":"2014-01-26T14:09:58","slug":"bringing-up-a-new-board-3","status":"publish","type":"post","link":"http:\/\/retroramblings.net\/?p=733","title":{"rendered":"Bringing up a new board"},"content":{"rendered":"<p><strong>Part 3: Clocking<\/strong><\/p>\n<p>The EMS11-BB21 board I received a few weeks ago has a Spartan 6 FPGA which the board provides with a 50MHz clock.\u00a0 In the examples so far I&#8217;ve used that clock directly &#8211; but FPGAs generally have the ability to be much more flexible where clocking&#8217;s concerned, and the Spartan 6 is no exception.<!--more--><\/p>\n<p>For the Altera versions of these projects, I&#8217;ve used a &#8220;Megafunction Wizard&#8221; to generate a component which configures one of the FPGA&#8217;s PLLs (Phase Lock Loop) to generate the clocks I need.\u00a0 These can take an input clock, generate a much faster clock, then divide that by a selectable divisor.\u00a0 So while you can&#8217;t get an arbitrary output frequency from a PLL, you can get close enough within reasonable limits for practical purposes.<\/p>\n<p>Naturally I started looking for the Xilinx equivalent of the Megafunction Wizard in ISE, and didn&#8217;t have far to look.\u00a0 Simply go to Project -&gt; New Source, and select &#8220;IP (Core generator and Architecture Wizard)&#8221;<\/p>\n<p>Once you&#8217;ve picked a location and filename for the component, in the list of functions that appears unfold &#8220;FPGA Features and Design&#8221;, then &#8220;Clocking&#8221;, then &#8220;Clocking Wizard&#8221;.\u00a0 (If you&#8217;ve ticked the &#8220;Only IP compatible with chosen part&#8221; checkbox, then that will be the only entry under Clocking.&#8221;<\/p>\n<p>Click through to the end of the Wizard, and wait &#8211; after a short pause the Clocking Wizard itself will appear.<a href=\"http:\/\/retroramblings.net\/wp-content\/uploads\/2014\/01\/ClockingWizard.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-734\" alt=\"ClockingWizard\" src=\"http:\/\/retroramblings.net\/wp-content\/uploads\/2014\/01\/ClockingWizard.png\" width=\"1280\" height=\"993\" srcset=\"http:\/\/retroramblings.net\/wp-content\/uploads\/2014\/01\/ClockingWizard.png 1280w, http:\/\/retroramblings.net\/wp-content\/uploads\/2014\/01\/ClockingWizard-300x232.png 300w, http:\/\/retroramblings.net\/wp-content\/uploads\/2014\/01\/ClockingWizard-1024x794.png 1024w, http:\/\/retroramblings.net\/wp-content\/uploads\/2014\/01\/ClockingWizard-386x300.png 386w\" sizes=\"auto, (max-width: 1280px) 100vw, 1280px\" \/><\/a><\/p>\n<p>Our input clock frequency in this case is 50MHz, so we&#8217;d change the 100 that&#8217;s there by default.\u00a0 Since I don&#8217;t intend to use the 50MHz clock for anything other than running the clock generator, we can also uncheck &#8220;Phase alignment&#8221;.\u00a0 We&#8217;d leave that selected if we were going to run part of the design from the 50MHz clock and needed to transfer data between the clock domains.\u00a0 Having made those two changes, we can click &#8220;Next&#8221;.<a href=\"http:\/\/retroramblings.net\/wp-content\/uploads\/2014\/01\/ClockingWizard2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-735\" alt=\"ClockingWizard2\" src=\"http:\/\/retroramblings.net\/wp-content\/uploads\/2014\/01\/ClockingWizard2.png\" width=\"799\" height=\"373\" srcset=\"http:\/\/retroramblings.net\/wp-content\/uploads\/2014\/01\/ClockingWizard2.png 799w, http:\/\/retroramblings.net\/wp-content\/uploads\/2014\/01\/ClockingWizard2-300x140.png 300w, http:\/\/retroramblings.net\/wp-content\/uploads\/2014\/01\/ClockingWizard2-500x233.png 500w\" sizes=\"auto, (max-width: 799px) 100vw, 799px\" \/><\/a><\/p>\n<p>Here we can choose our output clocks.\u00a0 They don&#8217;t have to be the same frequency, but not all combinations of frequencies are possible &#8211; the &#8220;actual&#8221; column shows you the closest achievable frequency to what you&#8217;ve requested.<\/p>\n<p>In this case we&#8217;re simply generating a pair of 100MHz clocks &#8211; one to serve as a system clock for the design, and the other to run an SDRAM chip.\u00a0 For reasons explained in my post about timing constraints its useful to have the SDRAM&#8217;s clock phase-shifted with respect to the main system clock.<\/p>\n<p>Having generated the clocking core (which takes a couple of minutes) we need to instantiate it.\u00a0 Here we hit a limitation of the Spartan 6 &#8211; we can&#8217;t just take a random clock and send it to an output pin of the FPGA &#8211; if we try, we&#8217;re given an error message when place-and-routing the design.\u00a0 It&#8217;s possible to override the message, but if we do that we&#8217;re likely to incur unpredictable routing delays which will screw up the SDRAM timings.<\/p>\n<p>Instead we have to use an &#8220;ODDR2&#8221; component to &#8220;forward&#8221; the clock to the appropriate pin.\u00a0 This is done like so:<\/p>\n<pre>library UNISIM;\r\nuse UNISIM.vcomponents.all;\r\n\r\n---- &lt;entity and architecture definitions&gt; ----\r\n\r\nmyclock : entity work.EMS11_BB21_sysclock\r\nport map(\r\n\u00a0\u00a0 \u00a0CLK_IN1 =&gt; CLK50,\r\n\u00a0\u00a0 \u00a0RESET =&gt; '0',\r\n\u00a0\u00a0 \u00a0CLK_OUT1 =&gt; sysclk,\r\n\u00a0\u00a0 \u00a0CLK_OUT2 =&gt; sdram_clk,  -- N.B. This is an internal signal, not the output SDRAM Clock pin\r\n\u00a0\u00a0 \u00a0LOCKED =&gt; clklocked\r\n);\r\n\r\nsdram_clk_inv &lt;= not sdram_clk;  -- We need an inverted copy of the SDRAM clock for the clock-forwarding component.\r\n\r\nODDR2_inst : ODDR2\r\ngeneric map(\r\n\u00a0\u00a0 \u00a0DDR_ALIGNMENT =&gt; \"NONE\",\r\n\u00a0\u00a0 \u00a0INIT =&gt; '0',\r\n\u00a0\u00a0 \u00a0SRTYPE =&gt; \"SYNC\")\r\nport map (\r\n\u00a0\u00a0 \u00a0Q =&gt; DR_CLK_O, -- The output clock pin\r\n\u00a0\u00a0 \u00a0C0 =&gt; sdram_clk, -- The internal SDRAM clock signal\r\n\u00a0\u00a0 \u00a0C1 =&gt; sdram_clk_inv, -- The inverted copy of the internal SDRAM clock signal\r\n\u00a0\u00a0 \u00a0CE =&gt; '1',\r\n\u00a0\u00a0 \u00a0D0 =&gt; '0',\r\n\u00a0\u00a0 \u00a0D1 =&gt; '1',\r\n\u00a0\u00a0 \u00a0R =&gt; '0',\u00a0\u00a0\u00a0 -- 1-bit reset input\r\n\u00a0\u00a0 \u00a0S =&gt; '0'\u00a0\u00a0\u00a0\u00a0 -- 1-bit set input\r\n);\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Part 3: Clocking The EMS11-BB21 board I received a few weeks ago has a Spartan 6 FPGA which the board provides with a 50MHz clock.\u00a0 In the examples so far I&#8217;ve used that clock directly &#8211; but FPGAs generally have &hellip; <a href=\"http:\/\/retroramblings.net\/?p=733\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-733","post","type-post","status-publish","format-standard","hentry","category-fpga"],"_links":{"self":[{"href":"http:\/\/retroramblings.net\/index.php?rest_route=\/wp\/v2\/posts\/733","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/retroramblings.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/retroramblings.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/retroramblings.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/retroramblings.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=733"}],"version-history":[{"count":3,"href":"http:\/\/retroramblings.net\/index.php?rest_route=\/wp\/v2\/posts\/733\/revisions"}],"predecessor-version":[{"id":738,"href":"http:\/\/retroramblings.net\/index.php?rest_route=\/wp\/v2\/posts\/733\/revisions\/738"}],"wp:attachment":[{"href":"http:\/\/retroramblings.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/retroramblings.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=733"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/retroramblings.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}