{"id":264,"date":"2015-01-24T17:30:23","date_gmt":"2015-01-25T01:30:23","guid":{"rendered":"http:\/\/www.beyond-circuits.com\/wordpress\/?page_id=264"},"modified":"2016-02-16T14:29:15","modified_gmt":"2016-02-16T22:29:15","slug":"tutorial4","status":"publish","type":"page","link":"https:\/\/www.beyond-circuits.com\/wordpress\/tutorial\/tutorial4\/","title":{"rendered":"Tutorial 4: Driving the Seven Segment Display"},"content":{"rendered":"<h1>Overview<\/h1>\n<p>In this tutorial, we will use the switch inputs to drive a seven segment display. The display is the PmodSSD from Digilent. You will need to connect the PmodSSD to the ZedBoard as shown in the photo below if you want to use the same pin constraints that I use in this\u00a0tutorial.<\/p>\n<p><a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/01\/ZedBoard-PmodSSD-connection.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-268\" src=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/01\/ZedBoard-PmodSSD-connection-300x225.jpg\" alt=\"ZedBoard-PmodSSD-connection\" width=\"300\" height=\"225\" srcset=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/01\/ZedBoard-PmodSSD-connection-300x225.jpg 300w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/01\/ZedBoard-PmodSSD-connection-1024x768.jpg 1024w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/01\/ZedBoard-PmodSSD-connection-400x300.jpg 400w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/01\/ZedBoard-PmodSSD-connection.jpg 1280w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<h1>The First Digit<\/h1>\n<h2>Ports<\/h2>\n<p>The two-digit display uses seven pins to control the seven segments of each display and one pin to select which display to drive. To display using both digits, you need to alternate between the two digits faster than the eye can perceive. This makes it look like both digits are displayed at the same time. For our purposes, we&#8217;ll start by\u00a0displaying just one digit. We will need to add some new output pins to our design: a seven bit bus called <em>ssd<\/em>, and a single bit output to control the digit select. This line\u00a0connects the cathode of the display, so we will call it <em>ssdcat<\/em>. The module declaration should look like this.<\/p>\n<pre><code>`timescale 1ns\/1ns\r\nmodule top (\r\n  input clk,\r\n  input [7:0] switch,\r\n  output reg [7:0] led,\r\n  output reg [6:0] ssd,\r\n  output reg ssdcat\r\n);<\/code><\/pre>\n<h2>LED Mapping<\/h2>\n<p>Each digit has seven LEDs, labeled A through G, shown in the figure below:<\/p>\n<p><a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/01\/SevenSegment.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-269\" src=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/01\/SevenSegment-300x226.png\" alt=\"SevenSegment\" width=\"300\" height=\"226\" srcset=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/01\/SevenSegment-300x226.png 300w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/01\/SevenSegment-398x300.png 398w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/01\/SevenSegment.png 527w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nTo make the digits, we activate the LED values according to the figure below:<\/p>\n<p><a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/01\/SevenSegmentDigits.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-270\" src=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/01\/SevenSegmentDigits-300x217.png\" alt=\"SevenSegmentDigits\" width=\"300\" height=\"217\" srcset=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/01\/SevenSegmentDigits-300x217.png 300w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/01\/SevenSegmentDigits.png 379w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>We will add a pattern for 0 as well, and we also can add patterns for the hex digits A, b, C, d, E and F. Note that we can&#8217;t make uppercase versions of B and D because they would appear\u00a0the same as the numbers 8 and 0. For the output value, I am connecting the most significant bit to LED A, and the least significant bit to LED G. The Verilog notation for binary numbers is to use a width value, followed by an apostrophe (tick), followed by the letter &#8220;b&#8221;, followed by the binary digits.<\/p>\n<div class=\"table-responsive\"><table  style=\"width:100%; \"  class=\"easy-table easy-table-default \" border=\"0\">\n<thead>\r\n<tr><th >Input Valut<\/th>\n<th > Segments Lit<\/th>\n<th > Output Value<\/th>\n<\/tr>\n<\/thead>\n<tbody>\r\n<tr><td >0<\/td>\n<td > A B C D E F<\/td>\n<td > 7'b1111110<\/td>\n<\/tr>\n\r\n<tr><td >1<\/td>\n<td > B C<\/td>\n<td > 7'b0110000<\/td>\n<\/tr>\n\r\n<tr><td >2<\/td>\n<td > A B D E G<\/td>\n<td > 7'b1101101<\/td>\n<\/tr>\n\r\n<tr><td >3<\/td>\n<td > A B C D G<\/td>\n<td > 7'b1111001<\/td>\n<\/tr>\n\r\n<tr><td >4<\/td>\n<td > B C F G<\/td>\n<td > 7'b0110011<\/td>\n<\/tr>\n\r\n<tr><td >5<\/td>\n<td > A C D F G<\/td>\n<td > 7'b1011011<\/td>\n<\/tr>\n\r\n<tr><td >6<\/td>\n<td > A C D E F G<\/td>\n<td > 7'b1011111<\/td>\n<\/tr>\n\r\n<tr><td >7<\/td>\n<td > A B C<\/td>\n<td > 7'b1110000<\/td>\n<\/tr>\n\r\n<tr><td >8<\/td>\n<td > A B C D E F G<\/td>\n<td > 7'b1111111<\/td>\n<\/tr>\n\r\n<tr><td >9<\/td>\n<td > A B C F G<\/td>\n<td > 7'b1110011<\/td>\n<\/tr>\n\r\n<tr><td >A<\/td>\n<td > A B C E F G<\/td>\n<td > 7'b1110111<\/td>\n<\/tr>\n\r\n<tr><td >b<\/td>\n<td > C D E F G<\/td>\n<td > 7'b0011111<\/td>\n<\/tr>\n\r\n<tr><td >C<\/td>\n<td > A D E F<\/td>\n<td > 7'b1001110<\/td>\n<\/tr>\n\r\n<tr><td >d<\/td>\n<td > B C D E G<\/td>\n<td > 7'b0111101<\/td>\n<\/tr>\n\r\n<tr><td >E<\/td>\n<td > A D E F G<\/td>\n<td > 7'b1001111<\/td>\n<\/tr>\n\r\n<tr><td >F<\/td>\n<td > A E F G<\/td>\n<td > 7'b1000111<\/td>\n<\/tr>\n<\/tbody><\/table><\/div>\n<p>We will use the four low bits of the <em>switch<\/em> input to drive the LED digit, as well as the Verilog <b>case<\/b> construct to implement our table. Your code should look something like this:<\/p>\n<pre><code>  always @(posedge clk)\r\n    case (switch[3:0])\r\n      0: ssd &lt;= 7'b1111110;\r\n      1: ssd &lt;= 7'b0110000;\r\n      2: ssd &lt;= 7'b1101101;\r\n      3: ssd &lt;= 7'b1111001;\r\n      4: ssd &lt;= 7'b0110011;\r\n      5: ssd &lt;= 7'b1011011;\r\n      6: ssd &lt;= 7'b1011111;\r\n      7: ssd &lt;= 7'b1110000;\r\n      8: ssd &lt;= 7'b1111111;\r\n      9: ssd &lt;= 7'b1110011;\r\n      10: ssd &lt;= 7'b1110111;\r\n      11: ssd &lt;= 7'b0011111;\r\n      12: ssd &lt;= 7'b1001110;\r\n      13: ssd &lt;= 7'b0111101;\r\n      14: ssd &lt;= 7'b1001111;\r\n      15: ssd &lt;= 7'b1000111;\r\n    endcase<\/code><\/pre>\n<p>We also need to drive the <em>ssdcat<\/em> output as well. For now, let&#8217;s just set it to zero.<\/p>\n<pre><code>always @(*) ssdcat = 0;<\/code><\/pre>\n<p>Of course, let&#8217;s not\u00a0forget to end our\u00a0module with the <code>endmodule<\/code> keyword.<\/p>\n<h2>Constraints<\/h2>\n<p><a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/01\/Tutorial4_JA_JB_Detail.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-medium wp-image-276 alignright\" src=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/01\/Tutorial4_JA_JB_Detail-232x300.png\" alt=\"Tutorial4_JA_JB_Detail\" width=\"232\" height=\"300\" srcset=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/01\/Tutorial4_JA_JB_Detail-232x300.png 232w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/01\/Tutorial4_JA_JB_Detail.png 371w\" sizes=\"auto, (max-width: 232px) 100vw, 232px\" \/><\/a> Since we have declared new outputs, we need to add some new constraints. If we look at the schematic for the ZedBoard, we see that the JA1 and JB1 connectors that we&#8217;ve plugged our PmodSSD into are connected into the 3.3V bank 13. So, we&#8217;ll have to constrain those pins as 3.3V IO.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<pre><code>set_property IOSTANDARD LVCMOS33 [get_ports ssd]\r\nset_property IOSTANDARD LVCMOS33 [get_ports ssdcat]<\/code><\/pre>\n<p><a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/01\/PmodSSD_Connection.png\"><img loading=\"lazy\" decoding=\"async\" class=\" size-medium wp-image-277 alignright\" src=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/01\/PmodSSD_Connection-300x278.png\" alt=\"PmodSSD_Connection\" width=\"300\" height=\"278\" srcset=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/01\/PmodSSD_Connection-300x278.png 300w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/01\/PmodSSD_Connection-324x300.png 324w, https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/2015\/01\/PmodSSD_Connection.png 524w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a>We also need to figure out the pin assignments. To do this, we need both the schematic for the ZedBoard, as well as the pinout for the PmodSSD. If you look on the ZedBoard where the PmodSSD connects, you can see which pins on the JA and JB connectors correspond with which pins on the PmodSSD. Pins JA1, JA2, JA3, and JA4 match with pins AA, AB, AC, and AD, respectively, while pins JB1, JB2, JB3, and JB4 match with pins AE, AF, AG, and CAT. Following all the connections leaves us with the following constraints:<\/p>\n<pre><code>set_property PACKAGE_PIN Y11 [get_ports {ssd[6]}]\r\nset_property PACKAGE_PIN AA11 [get_ports {ssd[5]}]\r\nset_property PACKAGE_PIN Y10 [get_ports {ssd[4]}]\r\nset_property PACKAGE_PIN AA9 [get_ports {ssd[3]}]\r\nset_property PACKAGE_PIN W12 [get_ports {ssd[2]}]\r\nset_property PACKAGE_PIN W11 [get_ports {ssd[1]}]\r\nset_property PACKAGE_PIN V10 [get_ports {ssd[0]}]\r\nset_property PACKAGE_PIN W8 [get_ports ssdcat]\r\n<\/code><\/pre>\n<h1>Files<\/h1>\n<ul>\n<li><a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/tutorials\/tutorial4\/top.v\">top.v<\/a><\/li>\n<li><a title=\"top.xdc\" href=\"https:\/\/www.beyond-circuits.com\/wordpress\/wp-content\/uploads\/tutorials\/tutorial4\/top.xdc\">top.xdc<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Overview In this tutorial, we will use the switch inputs to drive a seven segment display. The display is the PmodSSD from Digilent. You will need to connect the PmodSSD to the ZedBoard as shown in the photo below if &hellip; <a href=\"https:\/\/www.beyond-circuits.com\/wordpress\/tutorial\/tutorial4\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":226,"menu_order":4,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-264","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/pages\/264","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=264"}],"version-history":[{"count":24,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/pages\/264\/revisions"}],"predecessor-version":[{"id":894,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/pages\/264\/revisions\/894"}],"up":[{"embeddable":true,"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/pages\/226"}],"wp:attachment":[{"href":"https:\/\/www.beyond-circuits.com\/wordpress\/wp-json\/wp\/v2\/media?parent=264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}