找回密码
 注册
搜索
查看: 948|回复: 2

[FPGA资料] 乐曲演奏电路的设计,请高手指教

[复制链接]
发表于 2007-3-27 14:00:33 | 显示全部楼层 |阅读模式
程序如下:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity pulse is
  port ( clk: In std_logic;
        d : IN std_logic_vector(13 downto 0);
        fout: out std_logic);
end pulse;
architecture behav of pulse is
  signal count : std_logic_vector (13 downto 0);
  signal cao, cao1,cao2,load: std_logic;
begin
   process(clk,load,d)
   begin
     if clk'event and clk = '1' then
     if load = '1' then count <=d;
     else count <= count - 1;
     end if;
   end if;
end process;
process(count)
begin
if count = 0 then cao <= '1';
else cao <='0'; end if;
load <= cao;
end process;
process(clk)
begin
  if clk'event and clk = '1' then
cao1 <=cao;
  end if;
end process;
process(cao1)
begin
  if cao1'event and cao1 = '1' then
   
   cao2 <= not cao2;
end if;
fout <= cao2;
end process;
end behav;
library ieee;
use ieee.std_logic.1164.all;
entity table is
port ( clk : in std_logic;
   af: out integer range 0 to 16#3FFF# );
end;
architecture one of table is
   constant low_3: integer:=9100;
   constant low_5: integer:=7652;
   constant low_6: integer:=6817;
   constant low_7: integer:=6073;
   constant mid_1: integer:=5732;
   constant mid_2: integer:=5107;
   constant mid_3: integer:=4550;
   constant mid_5: integer:=3826;
   constant mid_6: integer:=3408;
   constant high1: integer:=2996;
   constant stop : integer:=0;
   signal counter[/COLOR] : integer range 0 to 138;
begin
  process(clk)
  begin
   if  counter =138 then counter <=0;
   elsif (clk'event and clk = '1') then
    counter <= counter + 1 ;
    end if;
end process;
process(counter)
begin
case counter is
  when 00 => af <= low_3;
  when 01 => af <= low_3;
  when 02 => af <= low_3;
  when 03 => af <= low_3;
when 04 => af <= low_5;      
when 05 => af <= low_5;
when 06 => af <= low_5;
when 07 => af <= low_6;
when 08 => af <= mid_1;
when 09 => af <= mid_1;
when 10 => af <= mid_1;
when 11 => af <= mid_2;
when 12 => af <= low_6;
when 13 => af <= mid_1;
when 14 => af <= low_5;
when 15 => af <= low_5;
when 16 => af <= mid_5;
when 17 => af <= mid_5;
when 18 => af <= mid_5;
when 19 => af <= hig_1;
when 20 => af <= mid_6;
when 21 => af <= mid_5;
when 22 => af <= mid_3;
when 23 => af <= mid_5;
when 24 => af <= mid_2;
when 25 => af <= mid_2;
when 26 => af <= mid_2;
when 27 => af <= mid_2;
when 28 => af <= mid_2;
when 29 => af <= mid_2;
when 30 => af <= mid_2;
when 31 => af <= stop;
when 32 => af <= mid_2;
when 33 => af <= mid_2;
when 34 => af <= mid_2;
when 35 => af <= mid_3;
when 36 => af <= low_7;
when 37 => af <= low_7;
when 38 => af <= low_6;
when 39 => af <= low_6;
when 40 => af <= low_5;
when 41 => af <= low_5;
when 42 => af <= low_5;
when 43 => af <= low_6;
when 44 => af <= mid_1;
when 45 => af <= mid_1;
when 46 => af <= mid_2;
when 47 => af <= mid_2;
when 48 => af <= low_3;
when 49 => af <= low_3;
when 50 => af <= mid_1:
when 51 => af <= mid_1:
when 52 => af <= low_6:
when 53 => af <= low_5:
when 54 => af <= low_6:
when 55 => af <= low_1:
when 56 => af <= low_5:
when 57 => af <= low_5:
when 58 => af <= low_5:
when 59 => af <= low_5:
when 60 => af <= low_5:
when 61 => af <= low_5:
when 62 => af <= low_5:
when 63 => af <= low_5:
when 64 => af <= mid_3:
when 65 => af <= mid_3:
when 66 => af <= mid_3:
when 67 => af <= mid_5:
when 68 => af <= low_7:
when 69 => af <= low_7:
when 70 => af <= mid_2;
when 71 => af <= mid_2;
when 72 => af <= low_6;
when 73 => af <= mid_1;
when 74 => af <= low_5;
when 75 => af <= low_5;
when 76 => af <= low_5;
when 77 => af <= low_5;
when 78 => af <= low_5;
when 79 => af <= low_5;
when 80 => af <= low_3;
when 81 => af <= low_5;
when 82 => af <= low_3;
when 83 => af <= low_3;
when 84 => af <= low_5;
when 85 => af <= low_6;
when 86 => af <= low_7;
when 87 => af <= mid_2;
when 88 => af <= low_6;
when 89 => af <= low_6;
when 90 => af <= low_6;
when 91 => af <= low_6;
when 92 => af <= low_6;
when 93 => af <= low_6;
when 94 => af <= low_5;
when 95 => af <= low_6;
when 96 => af <= mid_1;
when 97 => af <= mid_1;
when 98 => af <= mid_1;
when 99 => af <= mid_2;
when 100 => af <= mid_5;
when 101=> af <= mid_5;
when 102=> af <= mid_5;
when 103=> af <= mid_3;
when 104=> af <= mid_2;
when 105=> af <= mid_2;
when 106=> af <= mid_3;
when 107=> af <= mid_2;
when 108=> af <= mid_1;
when 109=> af <= mid_1;
when 110=> af <= low_6;
when 111=> af <= low_5;
when 112=> af <= low_3;
when 113=> af <= low_3;
when 114=> af <= low_3;
when 115=> af <= low_3;
when 116=> af <= mid_1;
when 117=> af <= mid_1;
when 118=> af <= mid_1;
when 119=> af <= mid_1;
when 120=> af <= low_6;
when 121=> af <= mid_1;
when 122=> af <= low_6;
when 123=> af <= low_5;
when 124=> af <= low_3;
when 125=> af <= low_5;
when 126=> af <= low_6;
when 127=> af <= mid_1;
when 128=> af <= mid_5;
when 129=> af <= mid_5;
when 130=> af <= mid_5;
when 131=> af <= mid_5;
when 132=> af <= mid_5;
when 133=> af <= mid_5;
when 134=> af <= mid_5;
when 135=> af <= mid_5;
when 136=> af <= stop;
when 137=> af <= stop;
when 138=> af <= stop;
when 139 => af <= stop;
when 140 => af <= stop;
when others => null;
     end case;
  end process;
end;
编译后,在上面兰色部分出现counter  未定义变量,不知道如何改,望遇高人,不吝赐教,感激万分!这个题目是本人的毕业设计,程序是在网站上找的,我看了半天也没有看出错误!
 楼主| 发表于 2007-3-27 14:01:57 | 显示全部楼层
附注,本人联系方法: fydym@126.com,QQ:263771799
点评回复

使用道具 举报

发表于 2007-4-2 23:33:05 | 显示全部楼层
counter定义的是0到138,但是后来CASE语句里counter从00开始到140,超出定义范围了
点评回复

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies

本版积分规则

Archiver|手机版|小黑屋|52RD我爱研发网 ( 沪ICP备2022007804号-2 )

GMT+8, 2024-11-24 12:05 , Processed in 0.046140 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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