8.6 DAC0832 接口电路程序
见随书所附光盘中文件:DAC0832VHDL 程序与仿真。
--文件名:DAC0832.VHD
--功能:产生频率为 762.9Hz 的锯齿波。
--最后修改日期:2004.3.18。
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity DAC0832 is
port(clk:in std_logic;
rst:in std_logic;
ile:out std_logic;
cont:out std_logic;
--系统时钟
--复位信号
--数据锁存允许信号
--控制信号(WR1、WR2、CS、Xfer)
data_out:out std_logic_vector(7 downto 0));
--波形数据输出
end DAC0832;
architecture behav of DAC0832 is
signal q:integer range 0 to 63;
signal data:std_logic_vector(7 downto 0);
begin
process(clk)
begin
if rst='1' then q<=0;
elsif clk'event and clk='1' then
if q=63 then q<=0;
--计数器
--波形数据
--复位,对计数器 q 清零
--此 IF 语句对系统时钟进行 64 分频
if data="11111111" then data<="00000000";
--此 IF 语句产生锯齿波波形数据
else data<=data+1;
end if;
else q<=q+1;
end if;
end if;
end process;
ile<='1';cont<='0';data_out<=data;
--ile、cont 赋值;波形数据输出;
end behav;