用VHDL设计数字系统实例

  • 格式:pdf
  • 大小:561.21 KB
  • 文档页数:91
port(clk_1m : in std_logic; --时钟信号,1 MHz。 k1 : in std_logic; --调节频率的开关信号。 k2 : in std_logic; --调节占空比的开关信号。 k3 : in std_logic; --换挡开关信号。 sel : out std_logic_vector(5 downto 0);--数码管片选信号。 d : out std_logic_vector(6 downto 0);--数码管的驱动信号。
f : out std_logic_vector (7 downto 0));--输出给 DAC0832 的 8 位数字信号。
end cheif ; architecture aa of cheif is
signal mode_mid : integer range 0 to 1; signal clk_125_mid : std_logic; signal s1 : std_logic; signal s2 : std_logic; signal s3 : std_logic; signal fs_mid : std_logic; signal statusf_mid : integer range 0 to 9; signal statush_mid : integer range 0 to 8; component keyin --调用防抖动模块。
clk_125_mid, sel,d); end aa; (2) 下层模块 ① 防抖动模块 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity keyin is
port(k : in std_logic; --有抖动的开关信号。 kout : buffer std_logic; --消抖动后的开关信号。 clk_125 : in std_logic); --时钟信号,125 Hz。
port(clk_1m : in std_logic; --时钟信号,1 MHz。 s1 : in std_logic; --经过防抖后输入的调节频率的开关信号。 s3 : in std_logic; --经过防抖后输入的换挡开关信号。 statusf : out integer range 0 to 9; --改变频率的控制计数器。 mode : out integer range 0 to 1; --换挡控制信号。 fs : out std_logic); --取样信号。
if (m=1) then m<=0;
elsif (m=0) then m<=1;
end if; end if; case status is
when 0=>n<=166; --信号 n 用来控制对 1 MHz 信号分频电路输出信号的频率。 when 1=>n<=83; when 2=>n<=55; when 3=>n<=41; when 4=>n<=33; when 5=>n<=27; when 6=>n<=23; when 7=>n<=20; when 8=>n<=18; when 9=>n<=16; when others=>n<=null; end case; end process; process(clk_1m) begin if(clk_1m′event and clk_1m=′1′)then if(count=n)then --n 的值不同,输出信号的频率也不同。 count<=1;
end component; component output --调用信号输出模块。
port(fs : in std_logic; s2 : in std_logic; statush : out integer range 0 to 8; f : out std
end process; end aa; ② 分频及控制模块 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_signed.all; use ieee.std_logic_unsigned.all; entity fp is
目 录
例 1 矩形波发生器­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­2 例 2 三角波发生器­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­15 例 3 数字频率计­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­22 例 4 数字钟­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­32 例 5 交通灯控制器­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­43 例 6 LED 字符显示器­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­52 例 7 LED 跑马灯­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­55 例 8 过河游戏­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­59 例 9 拔河游戏­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­69 例 10 键盘输入显示器 ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­82
end fp ; architecture aa of fp is
signal n : integer range 0 to 166; signal m : integer range 0 to 1; signal status : integer range 0 to 9; signal fs2 : std_logic; signal fs2_10 : std_logic; signal fs1 : std_logic; signal count : integer range 0 to 166; signal c : integer range 0 to 10; begin process(s1,s3) begin

附 录
I 用 VHDL 设计数字系统实例
为了拓宽设计思路,在光盘中再举出一些用 VHDL 设计数字系统的实例。以下实例只提供简单的 总体框图和简单的注释作为提示,未涉及之处留给读者思考、开拓。
例 1 矩形波发生器
1. 设计任务及要求 (1) 设计一个矩形波发生器,输出频率范围为 10 Hz~1 kHz,分如下两挡: ○1 10Hz~100 Hz 挡,其频率可调节,频率递增步进长度为 10 Hz。 ○2 100 Hz~1 kHz 挡,其频率可调节,频率递增步进长度为 100 Hz。 (2) 输出矩形波的占空比在 10%~90%之间可调,调节的递增步进长度为 10%。 (3) 输出电压峰峰值为 5 V。 (4) 每个周期信号的构造数据由 30 个取样点的值组成。 2. 可选器件 EPM7128S、共阴极七段数码管、DAC0832、LM741、开关、电阻和电容。 3. 设计总体框图 矩形波发生器总体框图如附图 1.1 所示。
if (s1′event and s1=′1′) then
5
if(status=9)then status<=0;
else status<=status+1;
end if; end if; if (s3′event and s3=′1′) then
end process; p2 :process
4
begin s<=d1 and d2; r<=(not d1) and (not d2); a<=s or ((not r) and a);
end process; p3 :process(clk_125)
begin if (clk_125′event and clk_125=′1′) then q2<=q1; q1<=a; end if; b<=q1 and not q2; kout<= b;
附图 1.1 矩形波发生器总体框图
4. 源程序及注释 (1) 上层模块 library ieee; use ieee.std_logic_1164.all;
2
use ieee.std_logic_signed.all; use ieee.std_logic_unsigned.all; entity cheif is
end keyin; architecture aa of keyin is
signal a,d1,d2,s,r,q1,q2,b : std_logic; begin p1 :process(clk_125)
begin if(clk_125=′0′) then d1<=k; d2<=d1; end if;
3
end component; component display --调用分频及显示模块。
port(statusf : in integer range 0 to 9; statush : in integer range 0 to 8; mode : in integer range 0 to 1; clk_1m : in std_logic; clk_125 : out std_logic; sel : out std_logic_vector(5 downto 0); d : out std_logic_vector(6 downto 0) );