anas_z15

EE2026 Lab Assignment 4

Mar 7th, 2019
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*Some tips for EE2026 lab assignment 4:
  2. 1) Overview
  3.     Assignment 4 goes 1 step further from assignment 3 by requiring you to display a different character on each 7-segment display (and eventually scroll the text to the left). This guide therefore assumes understanding of the concepts learned in the previous assignment such as dividing a clock to output several slow clocks, using reg arrays to store the binary values describing various characters and changing the characters through the use of a counter (array indices). Since each set of 4 cathodes are connected together across the 4 displays, combinational logic will fail to selectively enable segments on different displays; once a cathode is enabled, it will simultaneously light up across all anodes that are enabled at the same time. Hence, to display a different character on each display, the method that we are going to use would be to force each display (and the corresponding segments) to be enabled for only 1 quarter of the whole time (regardless of chosen frequency or state of auto lock). This means that at time step 0, the leftmost anode (an3) and the corresponding cathodes are enabled, at time step 1, an2 and the corresponding cathodes, at time step 2 an1 and the corresponding cathodes and at time step 4, an0 and the required cathodes.
  4.  
  5. 2) Possible structure of project
  6.     a) clock divider module - This module takes the input 100 MHz clock signal and outputs slower frequencies
  7.     b) dff module - D flip-flop (2 instances for each push button)
  8.     c) anode control module - controls which anode lights up at a particular time step
  9.     d) cathode control module - controls which segments light up at a particular time step
  10.     e) blink module - This module processes the outputs from a) and b) to send the correct enable signals to c) and d) and to the frequency selector LEDs
  11.     f) top module - This is the top-level module that instantiates all the other modules and establishes the connections between them via intermediate wires
  12.  
  13.  
  14. 3) Implementing the logic
  15.     The blink module is where the "heart" of your code lies. Following is a possible way of coding the blink module:
  16.     a) By using a suitably sized anode counter and an always block that is clocked on the rising edge of the chosen frequency, generate the values 0, 1, 2 and 3 over and over again. This counter should be routed to the anode control module, whereby you will determine, based on the counter value, which anode to turn on and which anode to turn off (refer to pg 6 of Lab 4 manual)
  17.  
  18.     b) By using another suitably sized char counter and the SAME always block as a), generate the array indices of the current 4 characters to be displayed. This should then be routed to the cathode control module that has a reg array of all your characters. The cathode control module would then take the corresponding 8-bit binary value at that index and output to the 7-segment display. Supposing the text to be displayed is "LOCKΒ OFF‐ABCD.", the characters and their corresponding indices are therefore:
  19. L 0
  20. O 1
  21. C 2
  22. K 3
  23.   4
  24. O 5
  25. F 6
  26. F 7
  27. - 8
  28. A 9
  29. B 10
  30. C 11
  31. D 12
  32. . 13
  33.  
  34. When the program first starts running, "LOCK" will be displayed, therefore the corresponding characters, anode counter and char counter will be as follows:
  35. Character      L    O    C   K
  36. Anode counter  0    1    2   3
  37. Char Counter   0    1    2   3
  38.  
  39. Suppose we disable the auto-lock to start scrolling, there will come a time where "CK O" will be displayed:
  40. Character      C    K        O
  41. Anode counter  0    1    2   3
  42. Char Counter   2    3    4   5
  43.  
  44. Since the anode counter and char counter are in sync, when one changes, the other will simultaneously change. The difference between them, however, is that the value of the anode counter will always loop through 0, 1, 2 & 3 forever, while the values of the cathode control will loop through 4 array indices for a short time before shifting itself by 1 and continuing, eg. 0,1,2,3...1,2,3,4...2,3,4,5...3,4,5,6... Since the 4 array indices are "fixed" temporarily, you might want to create 4 registers (eg. char0, char1, char2, char3) to hold the values of the 4 array indices, so that at each time step, the char counter will be assigned to the value of the corresponding char.
  45.  
  46.     c)  Create another always block that is clocked at the rising edge of the 2.98 Hz clock. This will be used for the following:
  47.             - shift LEDs 1 to 3 based on button pulses
  48.             - disable auto lock via sw15
  49.             - disable auto lock via btnL & btnR (using a counter)
  50.             - update the 4 chars if auto lock is disabled
  51.    
  52.     d) Use a multiplexer to select the frequency based on the LEDs' on-off status
  53.  
  54.     Anode control and cathode control modules:
  55.     These 2 modules will have an always block that has the corresponding counter set as the sensitivity list, to update the on-off status of the anodes/cathodes. The cathode control module should therefore have a reg array predefined to store all the characters required. Refer to the assignment 3 guide here to check it out: https://pastebin.com/qYa2GP5W
  56.  
  57. 4) Code snippets*/
  58.  
  59.     //shifting LEDs in the blink module
  60.     module blink(
  61.         input ______,
  62.         output _____,
  63.         output reg [4:0] led = 5'b_______  //declare and initialise on-off values of 5 LEDs
  64.     ); 
  65.     .
  66.     .
  67.     .
  68.     if (cond)
  69.         led[3:1] = led[3:1] << 1;  //shift LEDs 1 to 3 to the left by 1
  70.     if (cond)
  71.         led[3:1] = led[3:1] >> 1;  //shift LEDs 1 to 3 to the right by 1
  72.     //Recall that if, else if, else, always and initial blocks do not require begin and end if there is only 1 statement
  73.  
  74. /*Still confused? Then you might want to check out a sample RTL schematic for this project here: https://imgur.com/a/X9Mfe6I?
  75. Thank you for reading this guide and all the best for your assignment!*/
Advertisement