我想实现这样一个逻辑功能 用4位2进制信号cin来控制一个输出信号 当0000时输出一个10进制数字并且这个数字是最小数字 当1111输出一个10进制数字 这个数字是最大数字 当cin在0000和1111之间时输出从最小数到最大中间的任意一个从小到大的数 具体的大家看我的程序 大家有没什么问题 谢谢了 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; use ieee.std_logic_arith.all;
entity yindiao is port (clk : in std_logic; cin : in std_logic_vector(3 downto 0); q : out integer range 0 to 10204 ); end yindiao;
architecture behave of yindiao is begin process(clk) variable cnt1:integer range 0 to 150000; begin if clk'event and clk='1' then if cnt1<150000 then --此数值控制每一个音的长短 cnt1:=cnt1+1; else cnt1:=0; case cin is when "0000" =>q<=638; when "0001" =>q<=1275; when "0010" =>q<=1913; when "0011" =>q<=2550; when "0100" =>q<=3186;
when "0101" =>q<=3823; when "0110" =>q<=4460; when "0111" =>q<=5098; when "1000" =>q<=5700; when "1001" =>q<=6300; when "1010" =>q<=6900; when "1011" =>q<=7600; when "1100" =>q<=8200; when "1101" =>q<=8890; when "1110" =>q<=9500; when "1111" =>q<=10204; end case; end if; end if; end process; end behave; |