异步串行通信接收发送器(UART)的VHDL设计
   来源:中国科技博览     2021年05月21日 19:13

唐丽+张蓝星+李虎

[摘 要]异步串行通信接收发送器(UART)是现代电子系统中的关键部件之一,本文通过应用VHDL硬件描述语言来描述UART系统,进行UART电路的设计,设计成满足要求的UART,并使用ModelSim进行仿真、测试,验证VHDL实现的UART是否达到功能要求。

[关键词]异步串行通信接收发送器,VHDL,ModelSim

中图分类号:TN702 文献标识码:A 文章编号:1009-914X(2016)15-0280-02

[Abstract]The Universal Asynchronous Receiver/Transmitter(UART) is one of the key components in modern electron systems. In this paper,we use Very High-Speed Integrated Circuit hardware Description Language(VHDL) to design the UART?circuit which can satisfied design requirement.In the end,we use the ModelSim software to simulate?and?test, to verify the UART so that it can meet the criterias.

[Key words]UART,VHDL,ModelSim

1.引言

异步串行通信接收发送器是现代电子系统中的关键部件之一,其作为一种体积小、重量轻和可靠性高的混合集成电路(MIC),在电子系统尤其是近代航天、航空技术中被广泛使用。

本文采用VHDL语言进行UART的设计实现,首先VHDL描述UART系统,包括系统的顶层描述和串行输入并行输出、并行输入串行输出子系统描述;其次,使用ModelSim对设计进行功能仿真,为子系统编写仿真程序来验证其行为是否符合设计要求;最后将程序下载到芯片,在演示板上进行设计功能的硬件验证。

2. 异步串行通信接收发送器(UART)的设计

2.1 设计环境

一台装有Windows操作系统的计算机,安装了XILINX公司设计软件ISE6.2和ModelSim。

2.2 UART电路主要功能和外部引脚图

UART电路的主要功能为:

(1)当CS和WR有效时(低电平时),从计算机接收8位并行数据到后在TXD端串行输出。发送完毕后,INT0置“0”,直到再次写入一个数据为止。

(2)当接收端RXD检测到由“1”到“0”的负跳变后,开始接收数据到移位寄存器,接收完毕后,INT1置“0”。当RD有效时,将缓冲区的数据送到输出端D[0:7]。

2.3 UART的设计

UART电路可以分为串行输入并行输出、并行输入串行输出两个模块,按照Top-Down设计方法,首先作出系统的顶层描述,部分代码如下:

component par_in_ser_out

port (reset,clk16x,cs,wr : in std_logic;

din : in std_logic_vector(7 downto 0);

txd : out std_logic;

int0 : out std_logic);

end component ;

component ser_in_par_out

port (reset,clk16x,rxd,rd : in std_logic;

dout : out std_logic_vector(7 downto 0);

int1 : out std_logic);

end component ;

上述程序表示了UART内两个子系统的划分,由2个元件,即par_in_ser_out 和ser_in_par_out构成,其中clk16x是系统时钟CLOCK。但上述程序未定义元件的具体实现。

下面是并入串出模块par_in_ser_out的VHDL程序的部分代码,定义了元件par_in_ser_out的具体实现。当CS和WR有效时(低电平),将输入口din的数据装入缓冲区tbr,时钟信号clk16x经16分频后产生串行输出时钟clk1x。其中clk1x_enable当WR有效时为高电平。在时钟clk1x的上升沿,移位寄存器tsr依次左移,经TXD输出,每移出一位,tsr的最低位补“0”。

--16分频部分

process (reset,clk16x,clk1x_enable)

begin

if reset = '1' then

clkdiv <= "0000.jpg" >

elsif clk16x'event and clk16x = '1' then

if clk1x_enable = '1' then

clkdiv <= clkdiv + "0001" ;

end if ;

end if ;

end process ;

clk1x <= clkdiv(3) ;

--移位寄存器移出数据到TXD部分

process (reset,clk1x,clk1x_enable)

begin

if reset = '1' or clk1x_enable = '0' then

sent <= "0000" ;

elsif clk1x'event and clk1x = '1' then

if clk1x_enable = '1' then

sent <= sent + "0001" ;

end if ;

end if ;

end process ;

process (reset,clk1x,sent,tbr)

begin

if reset = '1' then

txd <= '1' ;

tsr <= "00000000" ;

elsif clk1x'event and clk1x = '1' then

if std_logic_vector(sent) = "0001" then

tsr <= tbr ;

elsif std_logic_vector(sent) = "0010" then

txd <= '0' ;

elsif std_logic_vector(sent) >= "0011" and std_logic_vector(sent) <= "1010" then

tsr <= tsr(6 downto 0) & '0' ;

txd <= tsr(7) ;

end if ;

end if ;

end process ;

串入并出模块ser_in_par_out的时钟16分频部分、接收数据到移位寄存器rsr部分与par_in_ser_out模块类似,这里不再详细解释了。需要说明一下的是,ser_in_par_out模块只有当RD有效时,才将缓冲区的数据送到输出口dout。

3. ModelSim仿真测试及结果分析

3.1 ModelSim仿真测试的结果

par_in_ser_out模块的仿真程序及仿真结果如下图2所示:

tb : PROCESS

BEGIN

reset <='0','1' after 3 ns,'0' after 25 ns ;

din <= "10100111","10101011" after 4450 ns;

cs <='1','0' after 40 ns;

wr <='1','0' after 60 ns,'1' after 260 ns,'0' after 4500 ns,'1' after 4900 ns ;

wait; -- will wait forever

END PROCESS;

ser_in_par_out模块的仿真程序及仿真结果如下图3所示:

tb : PROCESS

BEGIN

reset <='0','1' after 3 ns,'0' after 25 ns;

rd <='1','0' after 2000 ns,'0' after 3000 ns;

rxd <= '1','0' after 500 ns,'1' after 1200 ns,'0' after 2000 ns ;

wait; -- will wait forever

END PROCESS;

由上可知,经ModelSim软件仿真测试,采用VHDL生成的UART电路的串行输入并行输出、并行输入串行输出两个模块功能均正常实现。

3.2 设计中可以改进的地方

在par_in_ser_out和ser_in_par_out模块均可以设置奇偶校验位,以便检查接收到数据是否有误,另外也可以考虑加入帧校验位,将程序下载到芯片,在演示板上进行设计功能的硬件验证。

4.结论

本文按照给定的UART电路,给出VHDL硬件描述语言模块化设计过程,得出该电路的相关参数和主要功能,再用ModelSim软件进行UART的仿真测试。经仿真生成的UART电路各项功能指标基本达到要求。

参考文献

[1] Jan M. Rabaey,Anantha,Chandrakasan. Digital Integrated Circuits. Second Edition, 2004

[2] 周润德.数字集成电路――电路、系统与设计.北京:电子工业出版社,2004

[3] 付永庆.VHDL语言及其应用. 北京:高等教育出版社,2007

文章 数据 时钟