打印

大家帮忙看下这个程序里的CNT2变量是干什么用的

[复制链接]
1874|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
风中De舞者|  楼主 | 2007-8-28 09:32 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
se, ge, AN, TE, ST
大家帮忙看下这个程序里的CNT2变量是干什么用的 

这是一个控制蜂鸣器发出友谊天长地久音乐的一个乐谱
用Q来表示的  另外再接一个控制部分就可以控制蜂鸣器演奏了
时钟频率4M
其中的CNT2变量是干什么用的呢?
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;
q    : out integer range 0 to 10204
);
end yindiao;

architecture behave of yindiao is
begin
  process(clk)
  variable cnt1:integer range 0 to 1500000;
  variable cnt2:integer range 0 to 8;
  variable n   :integer range 0 to 45;
  begin 
    if clk'event and clk='1' then
       if cnt1<1500000 then         --此数值控制每一个音的长短
          cnt1:=cnt1+1;
       else
          cnt1:=0;
          case n is
            when 0   =>q<=10204;
                       if cnt2<1 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=1;
                       end if;
            when 1   =>q<=7364;
                       if cnt2<6 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=2;
                       end if;
            when 2   =>q<=6061;
                       if cnt2<1 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=3;
                       end if;
            when 3   =>q<=6803;
                       if cnt2<3 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=4;
                       end if;
            when 4   =>q<=7634;
                       n:=5;
            when 5   =>q<=6803;
                       if cnt2<1 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=6;
                       end if;
            when 6   =>q<=6061;
                       if cnt2<1 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=7;
                       end if;
            when 7   =>q<=7634;
                       if cnt2<4 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=8;
                       end if;
            when 8   =>q<=6061;
                       if cnt2<1 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=9;
                       end if;
            when 9   =>q<=5089;
                       if cnt2<1 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=10;
                       end if;
            when 10  =>q<=4535;
                       if cnt2<9 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=11;
                       end if;
            when 11  =>q<=5089;
                       if cnt2<3 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=12;
                       end if;
            when 12  =>q<=6061;
                       if cnt2<2 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=13;
                       end if;
            when 13  =>q<=7634;
                       if cnt2<1 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=14;
                       end if;
            when 14  =>q<=6803;
                       if cnt2<3 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=15;
                       end if;
            when 15  =>q<=7634;
                       n:=16;
            when 16  =>q<=6803;
                       if cnt2<1 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=17;
                       end if;
            when 17  =>q<=6061;
                       if cnt2<1 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=18;
                       end if;

            when 18  =>q<=7634;
                       if cnt2<3 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=19;
                       end if;
            when 19  =>q<=9050;
                       if cnt2<2 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=20;
                       end if;
            when 20  =>q<=10204;
                       if cnt2<1 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=21;
                       end if;
            when 21  =>q<=7634;
                       if cnt2<7 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=22;
                       end if;
            when 22  =>q<=4535;
                       if cnt2<1 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=23;
                       end if;

            when 23  =>q<=5089;
                       if cnt2<3 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=24;
                       end if;
            when 24  =>q<=6061;
                       if cnt2<2 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=25;
                       end if;
            when 25  =>q<=7634;
                       if cnt2<1 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=26;
                       end if;
            when 26  =>q<=6803;
                       if cnt2<3 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=27;
                       end if;
            when 27  =>q<=7634;
                       n:=28;
            when 28  =>q<=6803;
                       if cnt2<1 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=29;
                       end if;
            when 29  =>q<=4535;
                       if cnt2<1 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=30;
                       end if;
            when 30  =>q<=5089;
                       if cnt2<3 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=31;
                       end if;
            when 31  =>q<=6061;
                       if cnt2<2 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=32;
                       end if;
            when 32  =>q<=5089;
                       if cnt2<1 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=33;
                       end if;
            when 33  =>q<=4535;
                       if cnt2<7 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=34;
                       end if;
            when 34  =>q<=3809;
                       if cnt2<1 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=35;
                       end if;
            when 35  =>q<=5089;
                       if cnt2<3 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=36;
                       end if;
            when 36  =>q<=6061;
                       if cnt2<2 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=37;
                       end if;
            when 37  =>q<=7634;
                       if cnt2<1 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=38;
                       end if;
            when 38  =>q<=6803;
                       if cnt2<3 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=39;
                       end if;
            when 39  =>q<=7634;
                       n:=40;
            when 40  =>q<=6803;
                       if cnt2<1 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=41;
                       end if;
            when 41  =>q<=6061;
                       if cnt2<1 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=42;
                       end if;
            when 42  =>q<=7634;
                       if cnt2<3 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=43;
                       end if;
            when 43  =>q<=9050;
                       if cnt2<2 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=44;
                       end if;
            when 44  =>q<=10204;
                       if cnt2<1 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=45;
                       end if;
            when 45  =>q<=7634;
                       if cnt2<7 then
                          cnt2:=cnt2+1;
                       else
                          cnt2:=0;
                          n:=0;
                       end if;
          end case;
       end if;
    end if;
  end process;
end behave; 
 

相关帖子

沙发
伊处| | 2007-9-2 13:50 | 只看该作者

应该用于控制每个音符的拍数

使用特权

评论回复
板凳
风中De舞者|  楼主 | 2007-9-3 10:28 | 只看该作者

应该是这样 有点理解了

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

32

主题

287

帖子

1

粉丝