菜鸟求助FPGA音乐播放不了
使用EP1C6Q240C8不能播放以下程序!老师要答辩,根本不能用啊
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY music IS
PORT ( CLK_50M: IN STD_LOGIC;
SPK : OUT STD_LOGIC; --乐曲输出信号
S1: INSTD_LOGIC; --拨码开关的输入端口 通过改变拨码开关来选择乐曲一
S2: INSTD_LOGIC; --拨码开关的输入端口 通过改变拨码开关来选择乐曲二
S3: IN STD_LOGIC; --拨码开关的输入端口 通过改变拨码开关来选择乐曲三
LEDOUT: OUTSTD_LOGIC_VECTOR(8 DOWNTO 0)--LED灯的显示
);
END music;
ARCHITECTURE music OF music IS
SIGNAL FULL: STD_LOGIC;
SIGNAL CNT_14: INTEGER RANGE 0 TO 16384;
SIGNAL CLK_12M: STD_LOGIC;
SIGNAL CLK_3M: STD_LOGIC;
SIGNAL CLK_4HZ: STD_LOGIC;
SIGNAL q1: STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL q2: STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL q3: integer range 0 to 4200000;
SIGNAL i: INTEGER RANGE 0 TO 500;
TYPE SONG1 IS ARRAY (1 TO 192)OFinteger; --第一首乐曲 《送别》的音符预置数组
CONSTANT DATA1:SONG1:=
(12566,12566,12566,12566,11858,11858,12566,12566,13553,13553,13553,13553,13553,13553,13553,13553,
12974,12974,12974,12974,13553,13553,13553,13553,13553,12566,12566,12566,12566,12566,12566,12566,
12566,12566,12566,12566,10723,10723,11324,11324,11858,11858,11858,11858,11324,11324,10723,10723,
11324,11324,11324,11324,11324,11324,11324,11324,16383,16383,16383,16383,16383,16383,16383,16383,
12566,12566,12566,12566,11858,11858,12566,12566,13553,13553,13553,13553,13337,13337,13337,13337,
12974,12974,12974,12974,13553,13553,13553,13553,13553,12566,12566,12566,12566,12566,12566,12566,
12566,12566,12566,12566,11324,11324,11858,11858,12116,12116,12116,12116,12116,12116,10286,10286,
10723,10723,10723,10723,10723,10723,10723,10723,16383,16383,16383,16383,16383,16383,16383,16383,
12974,12974,12974,12974,13553,13553,13553,13553,13553,13553,13553,13553,13553,13553,13553,13553,
13337,13337,13337,13337,12974,12974,13337,13337,13553,13553,13553,13553,13553,13553,13553,13553,
12974,12974,13337,13337,13553,13553,12974,12974,12974,12974,12566,12566,11858,11858,10723,10723,
11324,11324,11324,11324,11324,11324,11324,11324,16383,16383,16383,16383,16383,16383,16383,16383);
TYPE SONG2 IS ARRAY (1 TO 128)OFINTEGER ; --第二首乐曲 《梁祝》的音符预置数组
CONSTANT DATA2:SONG2:=
(7347,7347,7347,7347,7347,7347,7347,7347,8749,8749,8749,8749,8749,8749,9565,9565,
10723,10723,10723,10723,10723,10723,11324,11324,9565,9565,10723,10723,8749,8749,8749,8749,
12566,12566,12566,12566,12566,12566,13553,13553,12974,12974,12553,12553,11858,11858,12566,12566,
11324,11324,11324,11324,11324,11324,11324,11324,11324,11324,11324,11324,11324,11324,11324,11324,
11324,11324,11324,11324,11324,11324,11858,11858,10286,10286,10286,10286,9565,9565,9565,9565,
12566,12566,12566,12566,12566,12566,9565,9565,10723,10723,10723,10723,11324,11324,11324,11324,
7347,7347,7347,7347,10723,10723,10723,10723,9565,9565,8749,8749,9565,9565,10723,10723,
8749,8749,8749,8749,8749,8749,8749,8749,8749,8749,8749,8749,8749,8749,8749,8749);
TYPE SONG3 IS ARRAY(1 TO 128)OF INTEGER ; --第三首乐曲 《世上只有妈妈好》的音符预置数组
CONSTANT DATA3:SONG3:=
(14123,14123,14123,14123,14123,14123,13853,13853,13853,13853,13853,13853,14249,14249,14123,14123,
14123,14123,14123,14123,14123,14123,13553,13553,13553,13553,13553,13553,16383,16383,16383,16383,
13553,13553,13553,13553,14476,14476,14476,14476,14476,14476,14249,14249,14249,14249,13853,13853,
13853,13853,13853,13853,13853,13853,13853,13853,13853,13853,13853,13853,13853,13853,13853,13853,
14123,14123,14123,14123,14123,14123,13853,13853,13853,13853,13853,13853,14249,14249,14123,14123,
14123,14123,14123,14123,14123,14123,13553,13553,13553,13553,13553,13553,16383,16383,16383,16383,
12974,12974,12974,12974,13553,13553,13553,13553,13553,13553,13553,13553,13853,13853,13553,13553,
13553,13553,13553,13553,13553,13553,13553,13553,13553,13553,13553,13553,13553,13553,13553,13553);
BEGIN
P0: PROCESS(CLK_50M)
BEGIN
IF CLK_50M'EVENT AND CLK_50M='1' THEN
q1<=q1+1;
END IF;
END PROCESS P0;
CLK_3M<=q1(3);
P1: PROCESS (CLK_3M)
BEGIN
IF CLK_3M'EVENT AND CLK_3M='1' THEN
q3<=q3+1;
if(q3=681250)then
q3<=0;
elsif(q3<290625)then
CLK_4HZ<='1';
else
CLK_4HZ<='0';
end if;
END IF;
END PROCESS P1;
P2: PROCESS(CLK_3M,i)
BEGIN
IF CLK_3M'EVENT AND CLK_3M='1' THEN
IF CNT_14=16384 THEN
IF S1='0' THEN --如果外部的拨码开关选择乐曲一时
CNT_14<=DATA1(i); --当计数器计满时 将乐曲一数组中的下一个预置数给计数器 这样使音符一个一个的演奏下去 形成乐曲
elsif S2='0' THEN --如果外部的拨码开关选择乐曲2时
CNT_14<=DATA2(i); --当计数器计满时 将下一个预置数给计数器 这样使音符一个一个的演奏下去 形成乐曲
elsif S3='0' THEN --如果外部拨码开关选择乐曲3时
CNT_14<=DATA3(i); --当计数器计满时 将下一个预置数给计数器 这样使音符一个一个的演奏下去 形成乐曲
END IF;
ELSE
CNT_14<=CNT_14+1; --否则的话 计数器继续做减一操作
if(CNT_14<15621) then --用于拓宽一个周期内高电平的长度
FULL<='1'; --使溢出标志信号为高电平
else
full<='0'; --使溢出标志位为低电平
end if;
END IF ;
END IF;
END PROCESS P2;
SPK<=full;
P3: PROCESS (CLK_4HZ) --在4HZ时钟下播放乐曲也就是每拍为0.25S
BEGIN
IF CLK_4HZ'EVENT AND CLK_4HZ='1' THEN --当时钟为上升沿时
IF S1='0' THEN --如果当下选择播放的是乐曲一
IF i=192 THE --i的值为第一首乐曲总的音符数时
i<=1; --当满足条件时,说明乐曲播放完毕这时要使乐曲循环播放,使计数变量为1
ELSE
i<=i+1; --当乐曲数组中音符没有播放完毕时,则技术变量加一计数,使乐曲向后推进播放
END IF ;
elsif S2='0' THEN --当选定为第二首乐曲时,逻辑原理同上
IF i=128 THEN
i<=1;
ELSE
i<=i+1;
END IF;
elsif S3='0' THEN --当选定为第三首乐曲时,逻辑原理同上
IF i=128 THEN
i<=1;
ELSE
i<=i+1;
END IF ;
ENDIF ;
END IF ;
END PROCESS;
END ;
引脚图