1、数字信号发送接收数字逻辑课程设计VHDL数字信号发送和接收电路设计 摘要: 将待发送的字符串进行奇校验编码,增加校验位,起始位0 和终止位1 。如果发送完一个信号后,没有继续发送,则接收端收到空闲信号串“1111111”。采用串行方式发送并行输入的数字信号,在接收端采用串行方式接收,在接收端进行偶校验,如果正确,说明信号传输正确,不报警,否则报警。这个设计可以提高数字信号传输的可靠性,减小其它信号的干扰,可以应用于一些简单的数字系统。电路设计电路的框图如下图所示设计内容:设计一个5位数字信号的发送和接收电路,把并行码变为串行码发送,串行奇校验检测器可通过异或实现。在数据接收端,只有在代码传输无
2、误后,才把数据代码并行输出。数据传送的格式采用异步串行通信的格式,包含起始位、数据位、校验位、停止位和空闲位。 数据发送模块:将并行数据加上起始位、偶校验位和停止位,以串行方式发送出去。仿真结果:在test_bench里测试了10101、01001、11101这几个信号,可以看到均实现了并转串输出接收电路模块:接收电路要实时检测起始位0 的到来,一旦检测到起始位到,就要将这一帧数据接收下来,开始接受数据,接收完成后,将数据位和校验位取出,若校验无误,则并行送出,若有误则报警。 仿真结果:我在test_bench 里串行输入了0、1、0、1、0、0、0第一个0为起始位,可以看到接收数据为0010
3、1,接受正确,alarm = 0整体结构:包括数据发送和接收模块,用component语句调用前两个模块,即可实现仿真结果收获 这个自由创作刚开始准备的时候觉得挺简单,但真正开始编译的时候,发现很多问题,有时候编译通过了还是得不到正确的仿真波形,原因在于程序的思路有问题,只好再把程序流程在纸上模拟一遍,发现错误后再改正。通过这次设计,从中对于语言有了更加深入的理解,对于数字信号的特点也有了初步的了解。设计过程中,遇到过许多困难,但在努力下,数字信号的发送和接收,能够准确的发送和接收,最终通过仿真。几点VHDL语法的收获:1)在进行代码编写前,应先有一个明确的思路,可以通过纸上的模拟检验程序是否
4、有错误。2)test_bench里不同测试信号的process分开写,不仅简单明了,而且可以避免错误。3)在进行顶层模块的test_bench信号书写时应当赋初值,否则观测不到信号。代码附录:1.发送模块library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity send isport( a: in std_logic_vector(4 downto 0); clk,start: in std_logic; b:out std_logic);end send;architecture behav
5、 of send issignal a0 :std_logic_vector(4 downto 0);beginprocess(clk,a)variable temp:std_logic_vector(6 downto 0);variable temp0,m:std_logic; variable cnt:integer range 0 to 8;beginif(clkevent and clk=1)then if(m=0)then temp0:=1; end if; if(a0 /= a)then m:=1; temp(5 downto 1):=a(4 downto 0); temp(6):
6、=a(4)xor a(3) xor a(2) xor a(1) xor a(0); temp(0):=0; a0 = a; end if; if( m=1 and start=0)then temp0:=temp(0); temp:=1&temp(6 downto 1); if(cnt7)then cnt:=cnt+1; else m:=0; temp:=0000000; cnt:=0; end if; end if;end if;b=temp0;end process;end behav;2.接收模块entity receive isport(clk,re:in std_logic; acc
7、ept:out std_logic_vector(4 downto 0); alarm:out std_logic);end receive;architecture arc of receive isbeginprocess(clk)variable a:std_logic;variable cnt:integer range 0 to 7;variable shift:std_logic_vector(5 downto 0);beginif clkevent and clk=1 then if re=0 and cnt=0 then alarm=0; a:=0; end if; if(a=
8、0)then if cnt7 then shift:=re&shift(5 downto 1); cnt:=cnt+1; else cnt:=0; a:=1; if(shift(0) xor shift(1) xor shift(2) xor shift(3) xor shift(4) xor shift(5)=0 then accept=shift(4 downto 0); else alarmstart,a=string,clk=clk0,b=c1); u1:receive port map(clk=clk0,re=c1,accept=rece,alarm=warning); end ar
9、chitecture;4.顶层模块的test_benchlibrary ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity signal_send_tb isend signal_send_tb;architecture behav of signal_send_tb iscomponent signal_send isport(start: in std_logic; string: in std_logic_vector(4 downto 0); clk0: in std_logic; rece:o
10、ut std_logic_vector(4 downto 0); warning:out std_logic );end component;signal start:std_logic;signal clk:std_logic;signal alarm0:std_logic:=0;signal code,rec: std_logic_vector(4 downto 0);begin u0:signal_send port map (start=start,string=code,clk0=clk,rece=rec,warning=alarm0); process begin clk = 0; wait for 1ns; clk = 1; wait for 1ns; end process; process begin start=1; wait for 2ns; start=0; wait; end process;process begin code=00101; wait for 30ns; code=01001; wait for 30ns; code=11101; wait; end process; end behav;
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1