VHDL傻人音阶制作操作

来源:互联网 发布:招商黄金分析软件 编辑:程序博客网 时间:2024/04/29 06:16

小学期要求做数字逻辑实验,其中一个要求做一个电子钟,我为了做出电子钟报时的时候有不同的声音看了许多别人的报告,但都一知半解,于是自己想了一个很土的办法把七个音阶分出来了。这里写出来搞笑一下,随便希望有大佬肯教一下真正标准的方法。
试验台提供的有1hz、10hz、1khz、10khz、100khz的脉冲信号。然而中音1是523hz、中音2是587hz、中音3是659hz、中音4是698hz,中音5是784hz,中音6是880hz,中音7是987hz。
于是我就想10khz是0.0001秒来一个脉冲,523hz是1/523hz来一个脉冲,也就大约0.0019秒来一个脉冲,我只要对10khz来的脉冲进行计数,计数到19再归零,也就是每19个脉冲就输出一个脉冲,不就是523hz,于是我就写了如下的代码:

library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity fenpin isport(clk:in std_logic;--10khzclk1,clk2,clk3,clk4,clk5,clk6,clk7:out std_logic);end fenpin;architecture artfp of fenpin issignal count1,count2:std_logic_vector(4 downto 0);signal count3,count4,count5,count6,count7:std_logic_vector(3 downto 0);beginprocess(clk)beginif(clk='1')then  if(count1="10011")then     count1<="00000";     clk1<='1';  else     count1<=count1+1;     clk1<='0';    end if;  if(count2="10001")then     count2<="00000";     clk2<='1';  else     count2<=count2+1;     clk2<='0';  end if;  if(count3="1111")then     count3<="0000";     clk3<='1';  else     count3<=count3+1;     clk3<='0';  end if;  if(count4="1110")then     count4<="0000";     clk4<='1';  else     count4<=count4+1;     clk4<='0';  end if;  if(count5="1100")then     count5<="0000";     clk5<='1';  else     count5<=count5+1;     clk5<='0';  end if;  if(count6="1011")then     count6<="0000";     clk6<='1';  else     count6<=count6+1;     clk6<='0';  end if;  if(count7="1010")then     count7<="0000";     clk7<='1';  else     count7<=count7+1;     clk7<='0';  end if;end if;end process;end artfp;

自我感觉还不错,如果有哪位大佬发现了错误,还请大佬帮忙指出,我也好早日修改。

原创粉丝点击