找回密码
 注册会员
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

关于VHDL的loadable shift register

[复制链接]
admin 发表于 2012-9-4 12:57:57 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
各位大大,这是我写的vhdl,不知道中间哪错了,用modelsim simulate到140ns的时候就停住了。


复制代码
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. entity loadable_shift_register is
  4. generic(
  5. DATA_WIDTH : natural := 12);
  6. port(
  7. data_in : in std_logic_vector(DATA_WIDTH-1 downto 0);
  8. ld : in std_logic;
  9. clk : in std_logic;
  10. rsh : in std_logic;
  11. rst_L : in std_logic;
  12. data_out: out std_logic_vector(DATA_WIDTH-1 downto 0));
  13. end entity loadable_shift_register;
  14. architecture bhv of loadable_shift_register is
  15. begin
  16. process (clk, rst_L, ld, data_in, rsh)
  17. variable data : std_logic_vector(DATA_WIDTH-1 downto 0);
  18. begin
  19. if rst_L = '0' then
  20. data := (others => '0');
  21. elsif clk'event and clk = '1' then
  22. if rsh = '1' then
  23. for i in 0 to (DATA_WIDTH-1) loop
  24. data(i) := data(i+1);
  25. end loop;
  26. data(DATA_WIDTH-1) := '0';
  27. elsif ld = '1' then
  28. data := data_in;
  29. end if;
  30. else
  31. data := data;
  32. end if;
  33. data_out <= data;
  34. end process;
  35. end architecture bhv;
  36. -------------------------------------------------------------------------------
  37. -- TEST BENCH FOR LOADABLE SHIFT REGISTER
  38. -------------------------------------------------------------------------------
  39. library ieee;
  40. use ieee.std_logic_1164.all;
  41. entity loadable_shift_register_tben is
  42. end loadable_shift_register_tben;
  43. architecture tben of loadable_shift_register_tben is
  44. component loadable_shift_register
  45. generic (
  46. DATA_WIDTH : natural);
  47. port (
  48. data_in : in std_logic_vector(DATA_WIDTH-1 downto 0);
  49. ld : in std_logic;
  50. rsh : in std_logic;
  51. clk : in std_logic;
  52. rst_L : in std_logic;
  53. data_out : out std_logic_vector(DATA_WIDTH-1 downto 0));
  54. end component;
  55. signal data_in : std_logic_vector(11 downto 0) := "000000000000";
  56. signal ld : std_logic := '0';
  57. signal rsh : std_logic := '0';
  58. signal clk : std_logic := '0';
  59. signal rst_L : std_logic := '0';
  60. signal data_out : std_logic_vector(11 downto 0);
  61. begin -- tben
  62. -- Instantiation of device under test
  63. DUT : loadable_shift_register
  64. generic map (DATA_WIDTH => 12)
  65. port map (data_in => data_in,
  66. ld => ld,
  67. rsh => rsh,
  68. clk => clk,
  69. rst_L => rst_L,
  70. data_out => data_out);
  71. -- DUT stimulus
  72. -- generates a periodic clock with T_clk = 40 ns
  73. process
  74. begin -- process clk_gen
  75. wait for 20 ns;
  76. clk <= not(clk);
  77. end process;
  78. -- models the reset signal (starts at '0')
  79. rst_L <= '1' after 15 ns;
  80. -- models the signals data_in, ld and rsh for each period of clk
  81. process (clk, rst_L)
  82. variable clk_ticks : natural := 0; -- keeps track of number of clk ticks
  83. begin -- process
  84. if rst_L = '0' then -- asynchronous reset (active low)
  85. clk_ticks := 0;
  86. data_in <= "000000000000" after 5 ns;
  87. ld <= '0' after 5 ns;
  88. rsh <= '0' after 5 ns;
  89. elsif clk'event and clk = '1' then -- rising clock edge
  90. clk_ticks := clk_ticks+1;
  91. if clk_ticks = 1 then
  92. data_in <= "000011110000" after 5 ns;
  93. ld <= '1' after 5 ns;
  94. rsh <= '0' after 5 ns;
  95. elsif clk_ticks = 2 then
  96. data_in <= "111111111111" after 5 ns;
  97. ld <= '0' after 5 ns;
  98. rsh <= '0' after 5 ns;
  99. elsif clk_ticks = 3 then
  100. data_in <= "111111111111" after 5 ns;
  101. ld <= '0' after 5 ns;
  102. rsh <= '1' after 5 ns;
  103. elsif clk_ticks = 4 then
  104. data_in <= "111111111111" after 5 ns;
  105. ld <= '1' after 5 ns;
  106. rsh <= '1' after 5 ns;
  107. elsif clk_ticks = 5 then
  108. data_in <= "111111111111" after 5 ns;
  109. ld <= '1' after 5 ns;
  110. rsh <= '0' after 5 ns;
  111. else
  112. data_in <= "XXXXXXXXXXXX" after 5 ns;
  113. ld <= '0' after 5 ns;
  114. rsh <= '0' after 5 ns;
  115. end if;
  116. end if;
  117. end process;
  118. end tben;
复制代码
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-11-24 00:23 , Processed in 0.056596 second(s), 12 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表