You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
2.7 KiB

2 years ago
2 years ago
  1. -- This design should display incrementing binary numbers
  2. -- at LED1-LED8 of the GateMate FPGA Starter Kit.
  3. library ieee ;
  4. use ieee.std_logic_1164.all;
  5. use ieee.numeric_std.all;
  6. library gatemate;
  7. use gatemate.components.all;
  8. entity blink is
  9. generic (
  10. SIM : natural := 0
  11. );
  12. port (
  13. clk_i : in std_logic; -- 10 MHz clock
  14. rst_n_i : in std_logic; -- SW3 button
  15. led_n_o : out std_logic_vector(7 downto 0) -- LED1..LED8
  16. );
  17. end entity blink;
  18. architecture rtl of blink is
  19. subtype t_clk_cnt is unsigned(19 downto 0);
  20. signal s_clk_cnt : t_clk_cnt;
  21. signal s_clk_cnt_end : t_clk_cnt;
  22. signal s_pll_clk : std_logic;
  23. signal s_pll_lock : std_logic;
  24. signal s_clk_en : boolean;
  25. signal s_rst_n : std_logic;
  26. signal s_cfg_end : std_logic;
  27. signal s_sys_rst_n : std_logic;
  28. begin
  29. pll : CC_PLL
  30. generic map (
  31. REF_CLK => "10",
  32. OUT_CLK => "2",
  33. PERF_MD => "ECONOMY"
  34. )
  35. port map (
  36. CLK_REF => clk_i,
  37. CLK_FEEDBACK => '0',
  38. USR_CLK_REF => '0',
  39. USR_LOCKED_STDY_RST => '0',
  40. USR_PLL_LOCKED_STDY => open,
  41. USR_PLL_LOCKED => s_pll_lock,
  42. CLK270 => open,
  43. CLK180 => open,
  44. CLK0 => s_pll_clk,
  45. CLK90 => open,
  46. CLK_REF_OUT => open
  47. );
  48. cfg_end_inst : CC_CFG_END
  49. port map (
  50. CFG_END => s_cfg_end
  51. );
  52. -- This works
  53. s_rst_n <= rst_n_i and s_pll_lock and s_cfg_end;
  54. -- This doesn't work.
  55. -- The reset module seems to be removed during Yosys flatten pass, even
  56. -- when the output is connected with an output port, WHY does this happen?
  57. -- 2.5. Executing FLATTEN pass (flatten design).
  58. -- Deleting now unused module reset_sync_c4ea21bb365bbeeaf5f2c654883e56d11e43c44e.
  59. -- <suppressed ~1 debug messages>
  60. reset : entity work.reset_sync
  61. generic map (
  62. POLARITY => '0'
  63. )
  64. port map (
  65. clk_i => s_pll_clk,
  66. rst_i => rst_n_i and s_pll_lock and s_cfg_end,
  67. rst_o => s_sys_rst_n
  68. );
  69. s_clk_cnt_end <= 20x"FFFFF" when SIM = 0 else -- synthesis
  70. 20x"000FF"; -- simulation
  71. process (s_pll_clk, s_rst_n) is
  72. begin
  73. if (not s_rst_n) then
  74. s_clk_cnt <= (others => '0');
  75. elsif (rising_edge(s_pll_clk)) then
  76. if (s_clk_cnt = s_clk_cnt_end) then
  77. s_clk_cnt <= (others => '0');
  78. else
  79. s_clk_cnt <= s_clk_cnt + 1;
  80. end if;
  81. end if;
  82. end process;
  83. s_clk_en <= s_clk_cnt = s_clk_cnt_end;
  84. process (s_pll_clk, s_rst_n) is
  85. begin
  86. if (not s_rst_n) then
  87. led_n_o <= x"FE";
  88. elsif (rising_edge(s_pll_clk)) then
  89. if (s_clk_en) then
  90. led_n_o <= led_n_o(6 downto 0) & led_n_o(7);
  91. end if;
  92. end if;
  93. end process;
  94. end architecture;