数字信号发送接收.docx
- 文档编号:3009521
- 上传时间:2022-11-17
- 格式:DOCX
- 页数:9
- 大小:372.15KB
数字信号发送接收.docx
《数字信号发送接收.docx》由会员分享,可在线阅读,更多相关《数字信号发送接收.docx(9页珍藏版)》请在冰豆网上搜索。
数字信号发送接收
数字逻辑课程设计
VHDL数字信号发送和接收电路设计
摘要:
将待发送的字符串进行奇校验编码,增加校验位,起始位’0’和终止位’1’。
如果发送完一个信号后,没有继续发送,则接收端收到空闲信号串“1111…111”。
采用串行方式发送并行输入的数字信号,在接收端采用串行方式接收,在接收端进行偶校验,如果正确,说明信号传输正确,不报警,否则报警。
这个设计可以提高数字信号传输的可靠性,减小其它信号的干扰,可以应用于一些简单的数字系统。
电路设计
电路的框图如下图所示
设计内容:
设计一个5位数字信号的发送和接收电路,把并行码变为串行码发送,串行奇校验检测器可通过异或实现。
在数据接收端,只有在代码传输无误后,才把数据代码并行输出。
数据传送的格式采用异步串行通信的格式,包含起始位、数据位、校验位、停止位和空闲位。
数据发送模块:
将并行数据加上起始位、偶校验位和停止位,以串行方式发送出去。
仿真结果:
在test_bench里测试了10101、01001、11101这几个信号,可以看到均实现了并转串输出
接收电路模块:
接收电路要实时检测起始位’0’的到来,一旦检测到起始位到,就要将这一帧数据接收下来,开始接受数据,接收完成后,将数据位和校验位取出,若校验无误,则并行送出,若有误则报警。
仿真结果:
我在test_bench里串行输入了0、1、0、1、0、0、0…
第一个0为起始位,可以看到接收数据为00101,接受正确,alarm=0
整体结构:
包括数据发送和接收模块,用component语句调用前两个模块,即可实现
仿真结果
收获
这个自由创作刚开始准备的时候觉得挺简单,但真正开始编译的时候,发现很多问题,有时候编译通过了还是得不到正确的仿真波形,原因在于程序的思路有问题,只好再把程序流程在纸上模拟一遍,发现错误后再改正。
通过这次设计,从中对于VHDL语言有了更加深入的理解,对于数字信号的特点也有了初步的了解。
设计过程中,遇到过许多困难,但在努力下,数字信号的发送和接收,能够准确的发送和接收,最终通过仿真。
几点VHDL语法的收获:
1)在进行代码编写前,应先有一个明确的思路,可以通过纸上的模拟检验程序是否有错误。
2)test_bench里不同测试信号的process分开写,不仅简单明了,而且可以避免错误。
3)在进行顶层模块的test_bench信号书写时应当赋初值,否则观测不到信号。
代码附录:
1.发送模块
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitysendis
port(a:
instd_logic_vector(4downto0);
clk,start:
instd_logic;
b:
outstd_logic);
endsend;
architecturebehavofsendis
signala0:
std_logic_vector(4downto0);
begin
process(clk,a)
variabletemp:
std_logic_vector(6downto0);
variabletemp0,m:
std_logic;
variablecnt:
integerrange0to8;
begin
if(clk'eventandclk='1')then
if(m='0')then
temp0:
='1';
endif;
if(a0/=a)then
m:
='1';
temp(5downto1):
=a(4downto0);
temp(6):
=a(4)xora(3)xora
(2)xora
(1)xora(0);
temp(0):
='0';
a0<=a;
endif;
if(m='1'andstart='0')then
temp0:
=temp(0);
temp:
='1'&temp(6downto1);
if(cnt<7)then
cnt:
=cnt+1;
else
m:
='0';
temp:
="0000000";
cnt:
=0;
endif;
endif;
endif;
b<=temp0;
endprocess;
endbehav;
2.接收模块
entityreceiveis
port(clk,re:
instd_logic;
accept:
outstd_logic_vector(4downto0);
alarm:
outstd_logic);
endreceive;
architecturearcofreceiveis
begin
process(clk)
variablea:
std_logic;
variablecnt:
integerrange0to7;
variableshift:
std_logic_vector(5downto0);
begin
ifclk'eventandclk='1'then
ifre='0'andcnt=0then
alarm<='0';
a:
='0';
endif;
if(a='0')then
ifcnt<7then
shift:
=re&shift(5downto1);
cnt:
=cnt+1;
else
cnt:
=0;
a:
='1';
if(shift(0)xorshift
(1)xorshift
(2)xorshift(3)xorshift(4)xorshift(5))='0'then
accept<=shift(4downto0);
else
alarm<='1';
endif;
endif;
endif;
endif;
endprocess;
endarc;
3.顶层模块
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitysignal_sendis
port(start:
instd_logic;
string:
instd_logic_vector(4downto0);
clk0:
instd_logic;
rece:
outstd_logic_vector(4downto0);
warning:
outstd_logic
);
endsignal_send;
architectureactofsignal_sendis
componentsendis
port(a:
instd_logic_vector(4downto0);
clk,start:
instd_logic;
b:
outstd_logic);
endcomponent;
componentreceiveis
port(clk,re:
instd_logic;
accept:
outstd_logic_vector(4downto0);
alarm:
outstd_logic);
endcomponent;
signalc1:
std_logic;
begin
u0:
sendportmap(start=>start,a=>string,clk=>clk0,b=>c1);
u1:
receiveportmap(clk=>clk0,re=>c1,accept=>rece,alarm=>warning);
endarchitecture;
4.顶层模块的test_bench
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitysignal_send_tbis
endsignal_send_tb;
architecturebehavofsignal_send_tbis
componentsignal_sendis
port(start:
instd_logic;
string:
instd_logic_vector(4downto0);
clk0:
instd_logic;
rece:
outstd_logic_vector(4downto0);
warning:
outstd_logic
);
endcomponent;
signalstart:
std_logic;
signalclk:
std_logic;
signalalarm0:
std_logic:
='0';
signalcode,rec:
std_logic_vector(4downto0);
begin
u0:
signal_sendportmap(start=>start,string=>code,clk0=>clk,rece=>rec,warning=>alarm0);
process
begin
clk<='0';
waitfor1ns;
clk<='1';
waitfor1ns;
endprocess;
process
begin
start<='1';
waitfor2ns;
start<='0';
wait;
endprocess;
process
begin
code<="00101";
waitfor30ns;
code<="01001";
waitfor30ns;
code<="11101";
wait;
endprocess;
endbehav;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数字信号 发送 接收