Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.53 KB | None | 0 0
  1.  
  2. LIBRARY ieee;
  3. USE ieee.std_logic_1164.ALL;
  4. USE ieee.numeric_std.ALL;
  5.  
  6. ENTITY LogicalStep_Lab5_top IS
  7. PORT
  8. (
  9. clkin_50 : in std_logic; -- The 50 MHz FPGA Clockinput
  10. rst_n : in std_logic; -- The RESET input (ACTIVE LOW)
  11. pb : in std_logic_vector(3 downto 0); -- The push-button inputs (ACTIVE LOW)
  12. sw : in std_logic_vector(7 downto 0); -- The switch inputs
  13. leds : out std_logic_vector(7 downto 0); -- for displaying the switch content
  14. seg7_data : out std_logic_vector(6 downto 0); -- 7-bit outputs to a 7-segment
  15. seg7_char1 : out std_logic; -- seg7 digi selectors
  16. seg7_char2 : out std_logic -- seg7 digi selectors
  17. );
  18. END LogicalStep_Lab5_top;
  19.  
  20. ARCHITECTURE SimpleCircuit OF LogicalStep_Lab5_top IS
  21.  
  22.  
  23. component cycle_generator port (
  24. clkin : in std_logic;--input clock
  25. rst_n : in std_logic;--reset
  26. modulo : in integer; -- the modulo value that determines output clock speed
  27. strobe_out : out std_logic;--strobe out
  28. full_cycle_out : out std_logic --full cycle out
  29. );
  30. end component;
  31.  
  32. component segment7_mux port (
  33. clk : in std_logic := '0';--input clock
  34. DIN0 : in std_logic_vector(6 downto 0); --input dig0
  35. DIN1 : in std_logic_vector(6 downto 0);-- input dig1
  36. DOUT : out std_logic_vector(6 downto 0);
  37. DIG1 : out std_logic;--output0
  38. DIG2 : out std_logic--output1
  39. );
  40. end component;
  41.  
  42. component Moore_SM
  43. port (
  44. rst_n: in std_logic;
  45. clkin: in std_logic; --input clock
  46. skipNS: in std_logic; --if NS sensor triggered
  47. skipEW: in std_logic; -- if EW sensor triggered
  48. nightMode : in std_logic; --if nightmode active
  49. reducedMode: in std_logic; --if reduced mode active
  50. outputState : OUT std_logic_vector(4 downto 0) --4 bit out
  51. );
  52. end component;
  53.  
  54. component BasicSynchronizer
  55. port (
  56. DATA_INPUT: in std_logic; -- input
  57. CLOCK : in std_logic; --clock to synchronize to
  58. DATA_OUTPUT : out std_logic -- sychronized output
  59. );
  60. end component;
  61.  
  62. component Latch1
  63. port(
  64. synchronized_Input: in std_logic;--latch input
  65. LATCH_CLEAR : in std_logic; --if latch is to be cleared
  66. CLOCK: in std_logic; --input clock
  67. enable : in std_logic;--if latch enabled
  68. LatchOut : out std_logic-- latch output
  69. );
  70. end component;
  71. ----------------------------------------------------------------------------------------------------
  72. CONSTANT SIM : boolean := False;
  73. CONSTANT CLK_DIV_SIZE : INTEGER := 24;
  74.  
  75. SIGNAL Main_CLK : STD_LOGIC;
  76. SIGNAL bin_counter : UNSIGNED(CLK_DIV_SIZE-1 downto 0);
  77.  
  78.  
  79. CONSTANT CNTR1_modulo : integer := 25000000; -- modulo count for cycle generator 1 with 50Mhz clocking input
  80. CONSTANT CNTR2_modulo : integer := 5000000; -- modulo count for cycle generator 2 with 50Mhz clocking input
  81. CONSTANT CNTR1_modulo_sim : integer := 200; -- modulo count for cycle generator 1 during simulation
  82. CONSTANT CNTR2_modulo_sim : integer := 40; -- modulo count for cycle generator 2 during simulation
  83.  
  84. SIGNAL CNTR1_modulo_value : integer ; -- modulo count for cycle generator 1
  85. SIGNAL CNTR2_modulo_value : integer ; -- modulo count for cycle generator 2
  86.  
  87. SIGNAL clken1,clken2 : STD_LOGIC; -- clock enables 1 & 2
  88.  
  89. SIGNAL strobe1, strobe2 : std_logic; -- strobes 1 & 2 with each one being 50% Duty Cycle
  90.  
  91.  
  92. SIGNAL EW : STD_LOGIC_VECTOR(6 downto 0);
  93. Signal lightStatus : STD_LOGIC_VECTOR(4 downto 0); -- signals for inputs into seg7_mux.
  94. signal NS : STD_LOGIC_VECTOR (6 downto 0);
  95.  
  96.  
  97. signal current : std_logic_Vector(6 downto 0); --current state
  98.  
  99. signal basicOutputNS : std_logic;--synchronizer output for NS
  100. signal basicOutputEW : std_logic;-- synchronizer output for EW
  101. signal clearNS : std_logic; --if clear NS
  102. signal clearEW: std_logic; -- if clear EW
  103. signal latchNSOut : std_logic; --latch outputs
  104. signal latchEWOut : std_logic; --latch outputs
  105.  
  106. ---------------------------------------
  107. signal temp:std_logic_vector(6 downto 0); --temp to store data for latch boolean equations
  108.  
  109. BEGIN
  110. ----------------------------------------------------------------------------------------------------
  111. BinCLK: PROCESS(clkin_50, rst_n) is
  112. BEGIN
  113. IF (rising_edge(clkin_50)) THEN -- binary counter increments on rising clock edge
  114. bin_counter <= bin_counter + 1;
  115. END IF;
  116. END PROCESS;
  117.  
  118. Clock_Source:
  119. Main_Clk <=
  120. clkin_50 when sim = TRUE else -- for simulations only
  121. std_logic(bin_counter(23));
  122.  
  123.  
  124.  
  125. MODULO_1_SELECTION: CnTR1_modulo_value <= CNTR1_modulo when SIM = FALSE else CNTR1_modulo_sim;
  126.  
  127. MODULO_2_SELECTION: CNTR2_modulo_value <= CNTR2_modulo when SIM = FALSE else CNTR2_modulo_sim;
  128.  
  129.  
  130. ----------------------------------------------------------------------------------------------------
  131. -- Component Hook-up:
  132.  
  133. GEN1: cycle_generator port map(clkin_50, rst_n, CNTR1_modulo_value, strobe1, clken1);
  134.  
  135. GEN2: cycle_generator port map(clkin_50, rst_n, CNTR2_modulo_value, strobe2, clken2);
  136.  
  137.  
  138.  
  139.  
  140.  
  141. --create instance ofinput synchronizer
  142. InputSyncNS: BasicSynchronizer port map (not pb(0),clkin_50,basicOutputNS);
  143. InputSyncEW: BasicSynchronizer port map (not pb(1),clkin_50,basicOutputEW);
  144.  
  145. --clear at 14 on nS and 6 at EW
  146. with lightStatus select
  147. clearNS <='1' when "01110",
  148. '0' when others;
  149.  
  150. with lightStatus select
  151. clearEW <='1' when "00110",
  152. '0' when others;
  153.  
  154. --create latches for NW and EW
  155. LatchNS: Latch1 port map (basicOutputNS,clearNS,clkin_50,clken2,latchNSOut);
  156.  
  157.  
  158. LatchEW: Latch1 port map (basicOutputEW,clearEW,clkin_50,clken2,latchEWOut);
  159.  
  160.  
  161. --night sw 0
  162. --reduced mode sw 1
  163. SM: Moore_SM port map(rst_n, strobe1, latchNSOut,latchEWOut,sw(0),sw(1), lightStatus);
  164.  
  165.  
  166. --convert state machine output to seven seg signals
  167. with lightStatus select -----------------------------------G flash
  168. NS <= "000"& strobe2 &"000" when "00000", -- [0]
  169. "000"& strobe2 &"000" when "00001", -- [1]
  170. --------------------------------------G solid
  171. "0001000" when "00010", -- [2]
  172. "0001000" when "00011", -- [3]
  173. "0001000" when "00100", -- [4]
  174. "0001000" when "00101", -- [5]
  175. --------------------------------------A solid
  176. "1000000" when "00110", -- [6]
  177. "1000000" when "00111", -- [7]
  178. ----------------------------R Solid
  179. "0000001" when "01000", -- [8]
  180. "0000001" when "01001", -- [9]
  181. "0000001" when "01010", -- [A]
  182. "0000001" when "01011", -- [b]
  183. "0000001" when "01100", -- [c]
  184. "0000001" when "01101", -- [d]
  185. "0000001" when "01110", -- [E]
  186. "0000001" when "01111", -- [F]
  187. "0001000" WHEN "10000",
  188. strobe1 & "000000" WHEN others; --"10001";
  189.  
  190. with lightStatus select ----------------------------R Solid
  191. EW <= "0000001" when "00000", -- [0]
  192. "0000001" when "00001", -- [1]
  193. "0000001" when "00010", -- [2]
  194. "0000001" when "00011", -- [3]
  195. "0000001" when "00100", -- [4]
  196. "0000001" when "00101", -- [5]
  197. "0000001" when "00110", -- [6]
  198. "0000001" when "00111", -- [7]
  199. -----------------------------------G flash
  200. "000"& strobe2 & "000" when "01000", -- [8]
  201. "000"& strobe2 & "000" when "01001", -- [9]
  202. --------------------------------------G solid
  203. "0001000" when "01010", -- [A]
  204. "0001000" when "01011", -- [b]
  205. "0001000" when "01100", -- [c]
  206. "0001000" when "01101", -- [d]
  207. --------------------------------------A solid
  208. "1000000" when "01110", -- [E]
  209. "1000000" when "01111", -- [F]
  210. "0000001" WHEN "10000",
  211. "000000" & strobe1 when others;--"10001";
  212.  
  213. --mux for seven seg
  214. MUX: segment7_mux port map(clkin_50, NS,EW, seg7_data, seg7_char1, seg7_char2);
  215.  
  216.  
  217. --output for the leds
  218. leds(0) <= Strobe2;
  219. leds(1) <= Strobe1;
  220. leds(5 downto 2)<=lightStatus(3 downto 0);
  221. leds (6)<= sw(0) or sw(1);
  222. leds (7)<= latchNSOut or latchEWOut;
  223.  
  224.  
  225. -- used for simulations
  226. -- leds(0) <= clken1;
  227. -- leds(1) <= Strobe1;
  228. -- leds(2) <= clken2;
  229. -- leds(3) <= Strobe2;
  230. -- leds(7 downto 4) <= Stae Machine state numbers
  231.  
  232.  
  233. END SimpleCircuit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement