【文件属性】:
文件名称:用vhdl编写
文件大小:30KB
文件格式:DOC
更新时间:2016-12-20 05:10:05
vhdl
这是用vhdl编写信号发生器输出三角波,方波,锯齿波
由于用VHDL编写输出的是数字信号,所以要在后面加入D/A转换
实现方式 PLD(或FPGA)+D/A转换
用PLD(或FPGA)产生3种循环变化的数据量(这里用4位 实现幅值10=‘1010)
1 用0-10的循环加法计数 实现锯齿波
2 用0-10-0循环加减计数器 实现三角波
3 用0-10-0循环加减计数实现 方波
Library IEEE;
Use ieee.std_logic_1164.all;
Use ieee.std_logic_unsigned.all;
Entity sig is
Port( clk,reset: in std_logic;
Mod: in std_logic_vector(1 downto 0); --MOD为模式选择
--00输出递增锯齿波 01输出递减锯齿波 --10 输出三角波 11 输出方波
dout: out std_logic_vector(3 downto 0));
End sig;
Architecture one of sig is
Signal count:std_logic_vector(3 downto 0); --count 为计数
Signal addsub:std_logic; -- addsub 为0时 加法计数
Begin -- 为1时 减法计数
cout<= count; -- 将计数值送给输出
Process(clk,reset,mod)
Begin
If reset=’1’ then -- 异步复位
Count<=”0000”;
Elsif clk’event and clk=’1’ then
If count=”1010” then --同步复位
Count<=”0000”;
End if;
Case mod is
When “00” => if count --所得递增锯齿波波形周期为10个时钟周期
count<= count+1;
When “01” => count<= count-1; --所得递减锯齿波形周期为10个时钟周期
When “10” =>if (addsub=’0’) then --所得三角波形周期为20个时钟周期
count<= count+1;