发布时间 : 星期日 文章任意波形信号发生器更新完毕开始阅读40e1e74c2b160b4e767fcfc5
? 锯齿波设计模块:
锯齿波在一个周期内的波形也是线性增长的,所以锯齿波的取值可以从0递加到
最大值,再返回到0,循环实现。 process(clk,reset)is begin
if(reset='1') then tmp<=\ elsif(clk'event and clk='1') then
if(tmp<\
tmp<=tmp+'1';
--异步复位 --检测时钟上升沿
--clk、reset分别为时钟和复位信号
else
tmp<=\
--输出最大是降为零
end if;
end if; Q<=tmp;
? 方波设计模块:
由于方波的占空比是50%,且只有两个状态,所以方波的取样比较简单。即前半周
期取样点取值为低电平“00000000”,后半周期取样点取值为高电平“11111111”就可以了。通过与“11111111”异或,交替送出8位全0和全1,并给以10个时钟延时实现,20个时钟为一个周期。 process (clk,reset) is begin
if(reset='1') then tmp<=\ elsif(clk'event and clk='1') then
if(cc<9) then
cc<=cc+1;
--异步复位 --检测时钟上升沿
else
cc<=0;
end if;
if cc=9 then tmp<=tmp xor \
12
--异或取反
end if;
end if;
Q<=tmp; end process;
? 波形信号选择控制模块:
波形数据信号选择器通过设置四位选择开关,根据四位外部开关的状态,选择调
用上述设计的四种波形模块的一种或其中二者的组合。用CASE语句设计完成要求信号选择,在外接开关的控制下选择输出一种波形数据输出,或完成两种波形的线性组合。波形组合是将波形每一时刻的数值相加,为了不超出DAC0832的输出范围,做相应的除2操作 。
process (ob,si,dl,sq) is begin
tmp<=ob&si&dl&sq; case tmp is
--将四位开关并置为四位信号数组
--斜波选择 --正弦波选择 --锯齿波选择 --方波选择
when \ when \ when \ when \
when \组合波形 when \ when \ when \ when \ when \ when others=>null; end case; end process;
? 顶层模块主要部分设计:
13
1.元件定义及例化
元件定义语句在结构体说明部分进行描述如下(以选择模块元件定义为例):
component chs is
port(ob,si,dl,sq: in std_logic;
obl,sin,dlt,squ: in std_logic_vector(7 downto 0);
Q:out std_logic_vector(7 downto 0)); end component chs;
之定义元件对应的元件例化语句置于结构主体中:
u4: chs port map(ob,si,dl,sq,JJ,KK,LL,ZZ,Q);
2.进程启动DAC832: process(clk)is begin
if(clk'event and clk='1') then
if(reset='1') then wr<='1'; else wr<='0'; end if;
end if; end process;
3.信号衰减选择与衰减档位显示进程 process(tc,J,K,L,Z)is begin case tc is
--检测选择信号 --不衰减
--2倍衰减
--4倍衰减
when \
when \
LL<='0'&L(7 downto 1);ZZ<='0'&Z(7 downto 1);
when \LL<=\
14
when \ --8倍衰减
LL<=\
when others=>null; end case;
if tc=\elsif tc=\elsif tc=\elsif tc=\end if;
a<=s(6);b<=s(5);c<=s(4);d<=s(3);e<=s(2);f<=s(1);g<=s(0); end process;
--送衰减显示值至数码管显示
15