DAT CLK RESET - 怎么连USB

LED灯条空制器上的GNDDATcLK端口接线怎么接_百度知道
LED灯条空制器上的GNDDATcLK端口接线怎么接
我有更好的答案
如果是幻彩控制器,就要谨慎接线哦,毕竟很贵,如果是幻彩的,就要知道你的灯条是几伏电压的,是什么芯片的,如WS2811芯片5V的话,公共端就是负极,也就是说,负极两条线一条要接电源负极,一条要接控制器输出负极,幻彩输入共有四条线的,如果没有记错的话CLK好像是同步接线端,这个不用管,不过幻彩不管是5v还是12v接线方式都一样的的,
如果我没记错的话控制器应该是:NLRGB,五个端口,最多也就是加一个地线GND,R是接红色,G是绿色,B是蓝色,N是电源负,L是电源正!GND是三相电里的地线!
为您推荐:
led灯条的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。摘要摘要通用串口是远程通信接口,在数字系统使用很普遍,是一个很重要的部件。 本论文使用 Verilog HDL 语言描述硬件功能,利用 QuartusII 5.0 在 FPGA 芯 片上的综合描述,采用模块化设计方法设计 UART (通用异步收发器) 的各个模块。 其中包括波特发生器,程序控制器,UART 数据接收器和 UART 数据发送器,本文 采用的外部时钟为 48MHZ,波特率为 9600。在 QuartusII 5.0 和 Modelsim6.0 环境下进行设计、编译和仿真。最后的程序编译仿真表明系统数据完全正确。 关键词:VerilogHDL; UART;帧格式;FPGA;Ⅰ AbstractAbstractIn this paper, the use of hardware description languages Verilog VHDL function, the use of Altera's FPGA chips, the design of modular design method of UART (Universal Asynchronous Receiver Transmitter) of each module, including Porter, generators, process controllers, UART receiver data and the UART transmitter data. QuartusII 5.0 and Modelsim6.0 in environment design, compilation, simulation and downloading. Finally, simulation results show that the procedures for compiling data entirely correct.Key words: VerilogHDL; UART; FPGAⅡ 目录目录第一章 绪论..................................................................................................................................... 1 1.1 引言..................................................................................................................................... 1 1.2 什么是 Verilog HDL? ...................................................................................................... 1 1.3 历史.................................................................................................................................... 2 1.4 主要能力............................................................................................................................ 2 1.5 模块.................................................................................................................................... 4 1.6 数据流描述方式................................................................................................................ 5 第二章片上系统 SOC 与 FPGA 的现状 ......................................................................................... 6 2.1 片上系统 SOC 介绍 .......................................................................................................... 6 2.2 FPGA 技术介绍 ................................................................................................................. 6 2.3 FPGA 核心设计流程 ......................................................................................................... 7 2.3.1 设计流程图 ............................................................................................................. 7 2.3.2 关键步骤的实现 ...................................................................................................... 8 2.3.2.1 功能仿真 .............................................................................................................. 8 2.3.2.2 逻辑综合 .............................................................................................................. 9 2.3.2.3 前仿真.................................................................................................................. 9 2.3.2.4 布局布线 .......................................................................................................... 140 2.3.2.5 后仿真(时序仿真) ...................................................................................... 151 第三章 UART 设计 ...................................................................................................................... 162 3.1 UART 的帧格式 ............................................................................................................. 162 3.2 UART 模块 ..................................................................................................................... 173 3.2.1 主要引脚功能介绍 .............................................................................................. 173 3.2.2UART 主体程序 ................................................................................................... 184 3.3UART 发送模块 .............................................................................................................. 195 3.3.1UART 的数据发送服务 ....................................................................................... 195 3.3.2UART 的数据发送操作 ......................................................................................... 16 3.3.3UART 的数据发送模块程序 ................................................................................. 17 3.3.4UART 的数据发送模块程序仿真图 ................................................................... 240 3.4UART 接收模块 .............................................................................................................. 251 3.4.1UART 数据接收服务 ........................................................................................... 251 3.4.2UART 数据接收操作 ........................................................................................... 262 3.4.3UART 的数据接收模块程序 ............................................................................... 262 3.4.4UART 的数据接收模块程序功能仿真图 ........................................................... 295 3.5UART 控制器 .................................................................................................................... 26 3.5.1UART 控制器服务 ................................................................................................. 26 3.5.2UART 控制器模块程序 ..................................................................................... 3026Ⅲ 目录 3.5.3UART 控制器模块程序仿真图 ............................................................................. 28 3.6UART 波特发生器 ............................................................................................................ 29 3.6.1UART 波特发生器服务 ......................................................................................... 29 3.6.2UART 波特发生器模块程序 ................................................................................. 29 3.6.13UART 波特发生器程序仿真图 ......................................................................... 340 结论 .............................................................................................................................................. 351 参考文献....................................................................................................................................... 362 致谢 .............................................................................................................................................. 373 附录 .............................................................................................................................................. 384 外文资料原文............................................................................................................................... 395 译文 .............................................................................................................................................. 473Ⅳ 绪论绪论1.1 引言21 世纪,电子技术迅猛发展,高新技术日新月异。传统的设计方法正逐步 退出历史舞台,取而代之的是基于 EDA 技术的芯片设计技术,它正在成为电子 系 统 设 计 的 主 流 。 大 规 模 可 编 程 器 件 现 场 可 编 程 门 阵 列 FPGA ( Field Programmable Gate Array) 和复杂可编程逻辑器件 CPLD (Complex Programmable Logic Device)是当今应用最广泛的两类可编程专用集成电路(ASIC) 。其性能 好、可靠性高、容量大、体积小,微功耗、速度快、使用灵活、设计周期短、开 发成本低,静态可重复编程、动态在系统重构、硬件功能可以像软件一样通过编 程来修改, 极大地提高了电子系统设计的灵活性和通用性。电子工程师和科学研 究人员利用该类器件可以在办公室或实验室设计出所需要的专用集成电路, 大大 缩短产品的研发周期和降低成本。 近年来, 可编程逻辑器件的开发生产和销售规模以惊人的速度增长,且广泛 地应用于航空航天、网络通信、军用雷达、仪器仪表、工业控制、医用 CT、家 用电器、手机和计算机等各个领域。它的广泛应用,使传统的设计方法正在进行 一场巨大的变革。异步串行通信要求的传输线少,可靠性高,传输距离远,被广 泛应用于微机和外设的数据交换。通常都由通用异步收发器 UART(Universal AsynchronousReceiver- Transmitter)来实现该功能,如 IBM PC 机中作为串行接 口芯片的 National INS 8250。在实际应用中,往往只需要 UART 的几个主要功 能, 专用的接口芯片会造成资源浪费和成本提高,特别是近来电子设计领域中日 趋成熟的 SOC 技术, 由于要在单块或极少数的几块芯片中实现整个系统的功能, 设计者就可以将类似 UART 的功能模块集成到 FPGA 中。1.2 什么是 Verilog HDL?Verilog HDL 是一种硬件描述语言,用于从算法级、门级到开关级的多种抽 象设计层次的数字系统建模。 被建模的数字系统对象的复杂性可以介于简单的门 和完整的电子数字系统之间。 数字系统能够按层次描述,并可在相同描述中显式 地进行时序建模。Verilog HDL 语言具有下述描述能力:设计的行为特性、设计1 福州大学工程技术学院毕业设计论文的数据流特性、 设计的结构组成以及包含响应监控和设计验证方面的时延和波形 产生机制。所有这些都使用同一种建模语言。此外, Verilog HDL 语言提供了编 程语言接口,通过该接口可以在模拟、验证期间从设计外部访问设计,包括模拟 的具体控制和运行。Verilog HDL 语言不仅定义了语法,而且对每个语法结构都 定义了清晰的模拟、仿真语义。因此,用这种语言编写的模型能够使用 Ve r i l o g 仿真器进行验证。语言 从 C 编程语言中继承了多种操作符和结构。 Verilog HDL 提供了扩展的建模能力, 其中许多扩展最初很难理解。但是,Verilog HDL 语言的核心子集非常易于学习 和使用,这对大多数建模应用来说已经足够。当然,完整的硬件描述语言足以对 从最复杂的芯片到完整的电子系统进行描述。1.3 历史Verilog HDL 语言最初是于 1 9 8 3 年由 Gateway Design Automation 公司为其 模拟器产品开发的硬件建模语言。那时它只是一种专用语言。 由于他们的模拟、 仿真器产品的广泛使用,Verilog HDL 作为一种便于使用且实用的语言逐渐为众 多设计者所接受。在一次努力增加语言普及性的活动中, Verilog HDL 语言于 1 9 9 0 年被推向公众领域。Open Verilog International(O V I)是促进 Ve r i l o g 发 展的国际性组织。1 9 9 2 年, O V I 决定致力于推广 Verilog OVI 标准成为 I E E E 标准。这一努力最后获得成功, Verilog 语言于 1 9 9 5 年成为 I E E E 标准, 称为 IEEE Std1 3 6 4-1 9 9 5。完整的标准在 Ve r i l o g 硬件描述语言参考手册 中有详细描述。1.4 主要能力下面列出的是 Ve r i l o g 硬件描述语言的主要能力: ? 基本逻辑门,例如 a n d、o r 和 n a n d 等都内置在语言中。 ? 用户定义原语( U D P)创建的灵活性。用户定义的原语既可以是组合逻 辑原语,也可以是时序逻辑原语。 ? 开关级基本结构模型,例如 p m o s 和 n m o s 等也被内置在语言中。2 绪论? 提供显式语言结构指定设计中的端口到端口的时延及路径时延和设计的 时序检查。 ? 可采用三种不同方式或混合方式对设计建模。这些方式包括:行为描述方 式―使用过程化结构建模; 数据流方式―使用连续赋值语句方式建模;结构化方 式―使用门和模块实例语句描述建模。 ? Verilog HDL 中有两类数据类型:线网数据类型和寄存器数据类型。线网 类型表示构件间的物理连线,而寄存器类型表示抽象的数据存储元件。 ? 能够描述层次设计,可使用模块实例结构描述任何层次。 ? 设计的规模可以是任意的;语言不对设计的规模(大小)施加任何限制。 ? Verilog HDL 不再是某些公司的专有语言而是 I E E E 标准。 ? 人和机器都可阅读 Verilog 语言,因此它可作为 E D A 的工具和设计者之 间的交互语言。 ? Verilog HDL 语言的描述能力能够通过使用编程语言接口( P L I)机制进 一步扩展。P L I 是允许外部函数访问 Verilog 模块内信息、允许设计者与模拟器 交互的例程集合。 ? 设计能够在多个层次上加以描述, 从开关级、 门级、 寄存器传送级 RT L) ( 到算法级,包括进程和队列级。 ? 能够使用内置开关级原语在开关级对设计完整建模。 ? 同一语言可用于生成模拟激励和指定测试的验证约束条件,例如输入值的 指定。 ? Verilog HDL 能够监控模拟验证的执行,即模拟验证执行过程中设计的值 能够被监控和显示。这些值也能够用于与期望值比较,在不匹配的情况下,打印 报告消息。 ? 在行为级描述中, Verilog HDL 不仅能够在 RT L 级上进行设计描述,而且能 够在体系结构级描述及其算法级行为上进行设计描述。 ? 能够使用门和模块实例化语句在结构级进行结构描述。建 模能力,即在一个设计中每个模块均可以在不同设计层次上建模。 ? Verilog HDL 还具有内置逻辑函数,例如&(按位与)和|(按位或) 。 ? 对高级编程语言结构,例如条件语句、情况语句和循环语句,语言中都可 以使用。 ? 可以显式地对并发和定时进行建模。 ? 提供强有力的文件读写能力。 ? 语言在特定情况下是非确定性的,即在不同的模拟器上模型可以产生不同3 福州大学工程技术学院毕业设计论文的结果;例如,事件队列上的事件顺序在标准中没有定义。1.5 模块模块是 Verilog 的基本描述单位,用于描述某个设计的功能或结构及其与其 他模块通信的外部端口。 一个设计的结构可使用开关级原语、门级原语和用户定 义的原语方式描述; 设计的数据流行为使用连续赋值语句进行描述; 时序行为使 用过程结构描述。 一个模块可以在另一个模块中使用。 一个模块的基本语法如下: Module modulename(portlist); D reg, wire, parameter, input, output, inout, function, task, . . . Statements: Initial statement Always statement Module instantiation Gate instantiation UDP instantiation Continuous assignment endmodule 说明部分用于定义不同的项,例如模块描述中使用的寄存器和参数。语句定 义设计的功能和结构。 说明部分和语句可以散布在模块中的任何地方; 但是变量、 寄存器、 线网和参数等的说明部分必须在使用前出现。为了使模块描述清晰和具 有良好的可读性, 最好将所有的说明部分放在语句前。本书中的所有实例都遵守 这一规范。 图 1- 2 为建模一个半加器电路的模块的简单实例。 Module halfadder(A,B,Sum,Carry); Input: Output: A, B; Sum, Cassign #2 Sum = A ^ B; assign #5 Carry = A & B; endmodule4 图 1-2 半加法器 绪论模块的名字是 halfadder。模块有 4 个端口: 两个输 入端口 A 和 B,两个输出端口 S u m 和 C a rry。由于没有定义端口的位数, 所有 端口大小都为 1 位;同时, 由于没有各端口的数据类型说明, 这四个端口都是线 网数据类型。 模块包含两条描述半加器数据流行为的连续赋值语句。从这种意义 上讲,这些语句在模块中出现的顺序无关紧要,这些语句是并发的。每条语句的 执行顺序依赖于发生在变量 A 和 B 上的事件。 在模块中,可用下述方式描述一个设计: 1) 数据流方式; 2) 行为方式; 3) 结构方式; 4) 上述描述方式的混合。1.6 数据流描述方式用数据流描述方式对一个设计建模的最基本的机制就是使用连续赋值语句。 在连续赋值语句中,某个值被指派给线网变量。连续赋值语句的语法为: a s s i g n [d e l a y] L H S n e t = RHS_ 右边表达式使用的操作数无论何时发生变化, 右边表达式都重新计算, 并且在指 定的时延后变化值被赋予左边表达式的线网变量。 时延定义了右边表达式操作数 变化与赋值给左边表达式之间的持续时间。 如果没有定义时延值, 缺省时延为 0。 1.6 行为描述方式 设计的行为功能使用下述过程语句结构描述: 1)initial 语句:此语句只执行一次。 2) always 语句:此语句总是循环执行, 或者说此语句重复执行。 只有寄存器类型数据能够在这两种语句中被赋值。寄存器类型数据在被赋新 值前保持原有值不变。所有的初始化语句和 a l w a y s 语句在 0 时刻并发执行。5 片上系统 SOC 与 FPGA 的现状第二章片上系统 SOC 与 FPGA 的现状2.1 片上系统 SOC 介绍SOC(systemonChip)称为片上系统。它最早产生于 20 世纪 90 年代中期,是 一种将一个完整系统所有不同的功能块一次直接集成于一颗硅片上的技术。 根据 这种技术所制造出的芯片,就叫做片上系统,也称为系统级芯片。SOC 由可设 计复用的 IP 核组成,采用超深亚微米工艺技术制造。这种结构使得在芯片设计 过程中,能做到各种资源的最优化利用,使设计周期缩短,资源利用率最高。 在一般设计过程中, 设计人员要做的只是前端设计, 如系统结构设计、 硬件编程、 功能仿真、时序仿真,然后向芯片制造商提供生成的网表。芯片制造商则负责芯 片的物理设计、封装、测试等工作。但是随着系统集成度的不断提高以及终端用 户需求的多样化, 系统功能愈来愈复杂, 如何确定系统结构并完成软硬件的划分, 传统的系统设计方法己经不能很好满足设计的需求。为了提高芯片的设计效率, 缩短设计周期, 系统设计需要新的设计理论体系和设计方法,以克服传统设计方 法中前端设计和后端设计相互分离的弊病 。 SOC 技术从诞生到目前被广泛采用, 也正是基于这一背景。本文设计工作采用的 FPGA 技术,就是目前流行的一种 SOC。2.2 FPGA 技术介绍FPGA(Field Programmable Gate Array)称为现场可编程门阵列,是在 CPLD 的基础上发展起来的新型高性能可编程逻辑器件,它一般采用 SRAM 工艺,也 有一些专用器件采用 Flash 工艺或反熔丝(Anti 一 Fuse)工艺等。FPGA 的集成度 很高, 其器件密度从数万系统门到数千万系统门不等,可以完成极其复杂的组合 与时序逻辑电路功能,适用于高速、高密度的高端数字逻辑电路设计领域。使用 FPGA 技术设计各种大规模或超大规模的组合、时序逻辑电路,不仅可以使设计 者避免直接与若干复杂烦琐的电路元器件的选择布线直接接触, 而且开发设计过 程中采用的类似于软件开发的模块化设计方法还更加便于多人合作设计开发, 这 就极大地提高了产品规划设计的效率。因此,FPGA 技术己经成为目前国际上通6 福州大学工程技术学院毕业设计论文行的硬件芯片产品设计开发的主流。 现在通用的 FPGA 芯片都含有大容量的 ROM 和 RAM 单元、可编程逻辑 单元、 丰富的布线资源等基本组成部分,这些资源已经完全可以满足目前绝大多 数设计开发的需要。随着工艺技术的发展与市场需要,超大规模、高速、低功耗 的新型 FPGA 不断推陈出新。一些高级的 FPGA 智能芯片甚至包含了中央处理 器(CPU)和内嵌专用硬核。FPGA 的主要器件供应商有 Xilinx、Altera、Lattice、 Actel 和 Atmel 等,本文工作所用的 FPGA 开发板和芯片就是由 Altera 公司提供的。2.3 FPGA 核心设计流程2.3.1 设计流程图(1)设计定义(2)HDL 实现(3)功能仿真逻辑仿真器(4)逻辑综合逻辑综合器(5)前仿真逻辑仿真器(6)布局布线FPGA 厂家工具(8)静态时序分析(7)后仿真逻辑仿真器(9)在系统测试 图 2-1FPGA 设计流程图 7 片上系统 SOC 与 FPGA 的现状说明: 逻辑仿真器主要指 modelsim,Verilog-XL。 逻 辑 综 合 器 主 要 指 LeonardoSpectrum 、 Synplify 、 FPGA Express/FPGA Compiler 等。 FPGA 厂 家 工 具 指 的 是 如 Altera 的 Max+PlusII 、 QuartusII , Xilinx 的 Foundation、Alliance、ISE4.1 等。 2.3.2 关键步骤的实现 2.3.2.1 功能仿真调用模块的 行为仿真模型RTL 代码测试程序 (test bench)测试数据逻辑仿真器 图 2-2FPGA 设计流程之功能仿真说明: “调用模块的行为仿真模型” 指的是 RTL 代码中引用的由厂家提供的宏模块 /IP,如 Altera 提供的 LPM 库中的乘法器、存储器等部件的行为模型。8 福州大学工程技术学院毕业设计论文2.3.2.2 逻辑综合RTL 代码调用模块的 黑盒子接口设置综合目标 和约束条件逻辑综合器EDIF 网表 (netlist)HDL 网表 (netlist)图 2-3FPGA 设计流程之逻辑综合说明: “调用模块的黑盒子接口”的导入,是由于 RTL 代码调用了一些外部模块, 而这些外部模块不能被综合或无需综合, 但逻辑综合器需要其接口的定义来检查 逻辑并保留这些模块的接口。2.3.2.3 前仿真如图 2-4FPGA 设计流程之前仿真9 片上系统 SOC 与 FPGA 的现状逻辑综合器HDL 网表 (netlist)调用模块的 行为仿真模型测试程序 (test bench)测试数据说明: 题。逻辑仿真器一般来说,对 FPGA 设计这一步可以跳过不做,但可用于 debug 综合有无问2.3.2.4 布局布线逻辑综合器EDIF 网表 (netlist)调用模块的 综合模型设置布局布线 约束条件FPGA 厂家工具下载/编程文件HDL 网表 (netlist)SDF 文件 (标准延时格式)图 2-5FPGA 设计流程之布局布线10 福州大学工程技术学院毕业设计论文2.3.2.5 后仿真(时序仿真)测试数据 FPGA 厂家工具HDL 网表 (netlist)SDF 文件 (标准延时格式)FPGA 基本单 元仿真模型测试程序 (test bench)逻辑仿真器 图 2-6FPGA 设计流程之后仿真随 着 微 机 系 统 的 广 泛 运 用 和 微 机 网 络 的 极 大 发 展 , UART(Universal Asynchronous Receive Transmitter)在数据通信及控制系统中得到了广泛运用。 8250,NS 16450 等芯片都是常见的 UART 器件,这类芯片己经相当复杂,有的含 有许多辅助模块(如 FIFO),但在实际中有时只需要使用 UART 的部分功能,因 而会造成一定的资源浪费。 FPGA 在现代电子设计中的广泛运用,使我们可以充分利用其资源,在芯片 上集成 UART 的功能模块,这样就无需外接专用 UART 芯片,从而简化了电路, 缩小了体积,设计的灵活性更大。11 UART 设计第三章 UART 设计3.1 UART 的帧格式在 UART 中,数据位是以字符为传送单位,数据的前、后要有起始位、停止 位,另外可以在停止位的前面加上一个比特(bit)的校验位。其帧格式如图所示。数据位 起始位 D0 D1 D2 D3 ――――――D7 校验位 停止位以 9600 波特率接收或发送,每一位时间为 1/9600 秒,或 48MHZ 晶振 5000 次计数图 3_1 数据帧格式文章 通 过 分析 UART 的功能, 利用有限状态机来描述 UART 核心控制逻辑 的方法,将其核心功能集成,从而使整个设计更加稳定、可靠。基本的 UART 通信只需要两条信号线就可以完成数据的相互通信。UART 的功能模块如图 3_2 所示。波特发生器Uart 控制器接收模块发送模块对象模块 图 3_2UART 的功能模块图12 福州大学工程技术学院毕业设计论文3.2 UART 模块在大规模电路的设计中,广泛采用层次化,结构化的设计方法。它将一个完 整的硬件设计任务从系统级开始,划分为若干个可操作的模块,编制出相应的模 型并进行仿真验证, 最后在系统级上进行组合。这样在提高设计效率的同时又提 高了设计质量, 是目前复杂数字系统实现的主要手段, 也是本文设计思想的基础。 其系统模块可划分为 4 个部分,如波特发生器,控制器,接收器,发送器,如图 3-3 所示: readclear_checksendcs Data_outreadClr3 clearclr4 send Data_inksRead_enable reset state T1send_enable counters Counters(control) clk_enable Clk_clear Clk(波特发生器) clk图 3-3uart 结构图counters3.2.1 主要引脚功能介绍 Read:串行输入 Data_in:并行输入 Cs:通知 cpu 接收数据位 Reset:重启输入 Clk:48M 时钟输入 send:串行输出 data_out:并行输出 ks:通知 cpu 发送准备位 state:uart 状态输入13 UART 设计3.2.2UART 主体程序 module uart(read,send,cs,ks,reset,state,clk,dat_in,dat_out); input read,clk,reset, //read 为串行输入,clk 为时钟输入 48MHZ,reset 为重启键 input[7:0] dat_//并行数据输入 output send,cs, //send 为串行输出,cs 为通知 cpu 接收数据位,ks 为发送准备位 output[7:0] dat_//并行数据输出 wire clear,clk_enable,read_enable,clear3,send_enable,clear4,t1; wire[7:0] counters,dat_ read u1 (dat_out,cs,read,reset,clk_enable,clk, read_enable,clear3,counters);//接收数据 module send u2 (dat_in,ks,send,reset,clk_enable,clk, send_enable,clear4,counters);//发送数据 module clk u3 (clk,t1,clk_enable); //时钟计数器模块 counters u4(read_enable,send_enable,clk,state,t1,read,counters,reset,clear); check u5 (state,clear3,clear4,clear,clk_enable3, clk_enable4,clk_enable); endmodule /////////////////////////////////////////////////////////////////////////////////////////////////////////////// module read(dat_out,cs,read,reset,clk_enable3, clk,read_enable,clear3,counters);//接收数据 module input read_ input read,reset, //read 为串行输入,read_control 为时钟控制,reset 为重启键 input[7:0] output cs,clear3,clk_enable3;//cs 为通知 cpu 读取数据位 output[7:0] dat_ endmodule /////////////////////////////////////////////////////////////////////////////////////////////////////////////// module send(dat_in,ks,send,reset,clk_enable4,clk, send_enable,clear4,counters);//发送数据 module input[7:0] dat_in,14 福州大学工程技术学院毕业设计论文input reset,clk,send_ output send,clk_enable4,clear4,//ks 为通知 cpu 发送准备位 endmodule /////////////////////////////////////////////////////////////////////////////////////////////////////////////// module counters(read_enable,send_enable,clk, state,t1,read,counters,reset,clear);//控制器 module input clk,state,t1,read,reset,//state 为 uart 状态输入, //clear 为程序计数寄存器清零控制位 output[7:0] output read_enable,send_ endmodule ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// module clk(clk,t1,clk_enable);//时钟计数器模块 input clk,clk_ output t1; endmodule /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// module check(state,clear3,clear4,clear,clk_enable3, clk_enable4,clk_enable);//clear 选择模块 input state,clear3,clear4,clk_enable3,clk_enable4; output clear,clk_ assign clear=state?clear4:clear3;assign clk_enable==state?clk_enable4:clk_enable3;endmodule ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////3.3UART 发送模块3.3.1UART 的数据发送服务 发送器实现的功能是将输入的 8 位并行数据变为串行数据, 同时在数据头部加 起始位,在数据位尾部加奇偶校验位和停止位。数据发送服务如表 3.115 UART 设计计数器 操作0 发送低电平1~~~8 偶校验表 3.1 数据发送9 结果10发送数据和奇 发送奇偶校验 发送高电平其基 本 特 点是: ① 在 信 号线上共有两种状态,可分别用逻辑 1 和逻辑。来区分。在发送器空 闲时,数据线应该保持在逻辑高电平状态。 ②发送 起 始 位:该位是一个逻辑 0,总是加在每一帧的头部,提示接受器数据 传输即将开始,在接收数据位过程中又被分离出去,占据一个数据位的时间。 ③发送 数 据 位:在起始位之后就是数据位,一般为 8 位一个字节的数据,低位 在前,高位在后。如字母 C 在 ASCII 表中是十进制 67,二进制 ,那么 传输的将是 。并在数据发送过程当中,进行数据位奇偶校验。 ④ 发送校 验 位:该位一般用来判断接收的数据位有无错误,常用的校验方法是 奇偶校验法。 3 过程当中奇偶校验的结果输入到数据线, 将 并占一个数据位时钟。 ⑤ 停止位 :停止位总在每一帧的末尾,为逻辑 1,用于标志一个字符传送的结束, 占据一个数据位的时间。 ⑥ 帧:从起始位到停止位之间的一组数据称为一帧。3.3.2UART 的数据发送操作 如图 3-4拉低电平 空闲检测 Cpu 发送位检测 自检测 接 cpu 传入数据 拉高电平发送等待数据发送和奇偶校验 图 3-4 数据发送操作奇偶结果发送16 福州大学工程技术学院毕业设计论文解释:采用 9600 波特率发送 从 cpu 传入数据:是指将 data_in 端口的数据存入寄存器中 Cpu 发送为检测:是指将 ks 寄存器置位,即数据发送完毕3.3.3UART 的数据发送模块程序module send(dat_in,send,reset,clk_enable4,clk, send_enable,clear4,counters);//发送数据 module input[7:0] dat_in, input reset,clk,send_ output send,clk_enable4,clear4; wire[7:0] dat_s; reg send,parity_ reg clk_enable,clear1,clear4; reg[7:0] date_s; ///////////////////////////////////////////////////////////////////////////////////////////////////////// always@(posedge clk) begin if(send_enable & !reset)//当 send_enable 为高电平时为发送操作状态 begin clk_enable4&=1; clear4&=clear1; end else begin clear4&=1; end end17 UART 设计 ////////////////////////////////////////////////////////////////////////////////////////////////////////////always@(posedge clk) if(send_enable & !reset) begin if(counters==8'b)//0 begin send&=0; date_s&=dat_ parity_result&=1; end else if(counters==8'b)//1 begin send&=date_s[0]; parity_result&=parity_result + date_s[0]; end else if(counters==8'b)//2 begin send&=date_s[1]; parity_result&=parity_result + date_s[0]; end else if(counters==8'b)//3 begin send&=date_s[2]; parity_result&=parity_result + date_s[0]; end else if(counters==8'b)//4 begin send&=date_s[3]; parity_result&=parity_result + date_s[0]; end else if(counters==8'b)//5 begin send&=date_s[4]; parity_result&=parity_result + date_s[0];18 福州大学工程技术学院毕业设计论文end else if(counters==8'b)//6 begin send&=date_s[5]; parity_result&=parity_result + date_s[0]; end else if(counters==8'b)//7 begin send&=date_s[6]; parity_result&=parity_result + date_s[0]; end else if(counters==8'b)//8 begin send&=date_s[7]; parity_result&=parity_result + date_s[0]; end else if(counters==8'b)//9 发送奇偶校验结果 begin send=parity_ end else if(counters==8'b)//0 发送高电平 begin send&=1; end else if(counters==8'b)//0 begin clear1&=1; end else if(counters==8'b) begin send&=1; end else clear1&=0; End19 UART 设计else send&=1; ///////////////////////////////////////////////////////////////// endmodul 3.3.4UART 的数据发送模块程序仿真图当 reset 为零时图 3-5reset 为零时仿真图 如图为 UART 的数据发送模块的功能仿真图,为方便观察,其中的时钟是直 接给出来的,根据图中的数据判读,其功能为正确,UART 的数据发送模块编译 成功。 1.当计时器为 140ns 时,为数据接收 2.当计时器为 357ns 时,为数据发送 3.当计时器为 705ns 时,为奇偶校验结果发送 4.当计时器为 825ns 时,发送高电平 当 reset 为 1 时 如图 3-6图 3-6reset 为 1 时仿真图20 福州大学工程技术学院毕业设计论文3.4UART 接收模块3.4.1UART 数据接收服务 串行 数 据 帧和接收时钟是异步的,由逻辑 1 跳变为逻辑 0 可视为一个数据 帧的开始,所以接收器首先要判断起始位。如表 3.2计数器 操作 测01~~~~8 偶校验910 数据判断数据起始位检 数据接收和奇 奇偶校验表 3.2uart 的数据接收服务其基 本 特 点是: UART 接收状态 一 共 有 4 个:state0(检测起始位), e1( 对数据位进行采样, stat 并串/并转换),state2(奇偶校验 分析),state3(接收数据正确与否检测)。 ① 起始位判读:当 UART 接收器复位以后,接收器将处 于这一状态。在该状态, 控制器一直等待 read 电平的跳 变,即从逻辑 1 变为逻辑 0,也就是等待起始位 的到来 。一旦检测到起始位,就对采样时钟 elk 一 rev 上跳沿计 数,当计数为 8 时,也就是确保在起始位的中间点 ,然后转到 state1 状态。 ② 数据接收 :该状态下,每间隔 16 位倍频采样一位 串行数据,接收 8 位异步 数据并进行串/并转换。 即对 clk 一 rev 上跳沿计数, 当为 16 时, 就对数据采样, 这样 保证了数据位是在中点处被采样的,同时串/并转换,当检测到已收到 8 个 数据后以后,便进入了 state2 状态。 ③ 奇偶校验 :该状态实现的功能是奇偶校验。本文采 用的是偶校验。校验结束 以后,转到 state3 状态。 ④ 数据帧判读 :该状态是用来帧校验的,即在校验位 以后,检测停止位是否为 逻辑高电平21 UART 设计3.4.2UART 数据接收操作图 3-7UART 数据接收操作 起始位检测 空闲检测 Cpu 接收位检测 检测 毛刺检测 数据帧检测接收等待数据位读取和奇偶校验奇偶结果比较图 3-7UART 数据接收操作解释:数据接收速度 9600 波特率,以 16 倍频接收 cpu 接收位检测:当奇偶结果比较和数据帧检测都正确时,cpu 检测接收位 cs 置 位3.4.3UART 的数据接收模块程序 module read(dat_out,cs,read,reset,clk_enable3,clk,read_enable,clear3,counters); //接收数据 module input read_ input read,reset,//read 为串行输入,read_control 为时钟控制,reset 为重启键 input[7:0] output cs,clear3,clk_enable3;//cs 为通知 cpu 读取数据位 output[7:0] dat_ wire clear3; reg cs,cs1,clk_enable3; reg[7:0] data_//移位寄存器22 福州大学工程技术学院毕业设计论文reg parity_check_result,parity_result,clear3,clear1;//////////////////////////////////////////////////////// ///////////////// always@(posedge clk) begin if(read_enable)//当 read_enable 为高电平时为发送操作状态 begin clk_enable3&=1; clear3&=clear1; end else begin clear3&=1; end end////////////////////////////////////////////////////////////////////////////// always@(negedge counters[0]) if(read_enable & !reset) begin if (counters==8'b) //1 begin data_out[7]&= parity_check_result&=parity_check_result + end else if (counters==8'b) //2 begin data_out[6]&= parity_check_result&=parity_check_result + end else if (counters==8'b) //323///接收操作 UART 设计begin data_out[5]&= parity_check_result&=parity_check_result + end else if (counters==8'b) //4 begin data_out[4]&= parity_check_result&=parity_check_result + end else if (counters==8'b) //5 begin data_out[3]&= parity_check_result&=parity_check_result + end else if (counters==8'b) //6 begin data_out[2]&= parity_check_result&=parity_check_result + end else if (counters==8'b) //7 begin data_out[1]&= parity_check_result&=parity_check_result + end else if (counters==8'b) //8 begin data_out[0]&= parity_check_result&=parity_check_result + end else if (counters==8'b) //9 进行奇偶校验检测 begin parity_result&=24 福州大学工程技术学院毕业设计论文parity_result&=#2 (parity_check_result == parity_result) ? 1:0; end begin cs1&=(read) ? 1:0; end else if (counters==8'b) //01 给 cpu 发送接收信号 begin cs&=(cs1 && parity_result) ? 1:0; //当奇偶校验结果与帧检测结果都为 1 时,cs 置位 clear1&=1; end else if(counters==8'b)//检测是否是毛刺 begin clear1&=(!read)?0:1; end else end else clear1&=1; endmodule 3.4.4UART 的数据接收模块程序功能仿真图 图 3-8 当 counters 指定时间时功能仿真 clear1&=0; clk_enable&=0; else if (counters==8'b) //0 进行帧检测图 3-8 当 counters 指定时间时25 UART 设计解释:由图可明显看出 data[0]和 data[1]变化,模块功能仿真通过 图 3-9 当 counters 未指定时间时功能仿真图 3-9 当 counters 未指定时间时功能仿真3.5UART 控制器3.5.1UART 控制器服务 UART 控制器实质上是一组计数器,由 state 决定计数器数据发送对象,在这 里指定当 state 为 1 时,发送到 UART 接收模块,反之,发送到 UART 发送模块。 当计数到指定数据时,触发指定模块的制定操作。 3.5.2UART 控制器模块程序 module counters(read_enable,send_enable, clk,state,t1,read,counters,reset,clear);//程序计数寄存器 input clk,state,t1,read,reset,//state 为 uart 状态输入, //clear 为程序计数寄存器清零控制位 output[7:0]26 福州大学工程技术学院毕业设计论文output read_enable,send_ reg read_enable,send_enable,//read_enable 为接收控制位?//// //////send_enable 为发送控制位,control 为程序计数寄存器为零状态寄存位 reg[7:0]//8 位程序计数寄存器 always@(posedge clk) //当程序计数寄存器为零时,程序计数寄存器为零状态寄存位置位 begin control&=(!counters)? 1 : 0; end /////////////////////////////////////////////////////////////////////////////////////// always@(negedge read)//uart 发送或接收状态判断 if(control) begin if(state) begin if(!read) begin read_enable&=1; send_enable&=0; end else begin send_enable&=0; end end else begin send_enable&=1; read_enable&=0; end end ////////////////////////////////////////////////////////////27 UART 设计always@(posedge t1) if(!reset && !clear)//reset 为 1 时,clear 为 1 时程序计数寄存器清零 begin if(counters&8'b) counters&=8'b; else counters&=counters + 1; end else begin counters&=8'b; end endmodule3.5.2UART 控制器模块程序仿真图图 3-10UART 控制器模块程序仿真图由图判读有: 1.当计时器为 175ns 时,!计时器==0,control 被赋予 1;xx_enable 未被赋值 2.当计时器为 265ns 时,xx_enable 未被赋值 3.当计时器为 335ns 时,xx_enable 被赋值28 福州大学工程技术学院毕业设计论文4.当计时器为 475ns 时,xx_enable 被赋值 5.当计时器为 630ns 时,xx_enable 被赋值 6.当计时器为 721ns 时,xx_enable 未被赋值 7.当计时器为 850ns 时,xx_enable 被赋值 可判断 UART 控制器模块程序编译成功3.6UART 波特发生器3.6.1UART 波特发生器服务 为 UART 控制器提供时钟,本文采用 9600 波特率发送或接收数据。波特率 发生器实际上就是分频器,设计比较简单。3.6.2UART 波特发生器模块程序 module clk(clk,t1,clk_enable);//时钟计数器模块 input clk,clk_ output t1; //output[8:0] counter1; reg t1; reg[7:0] counter1; //(48,000,000/9,600)=5,000 为一个数据发送计数, 接收为 16 倍频为 5,000/16=312 always@(posedge clk) if(clk_enable)//当 clk_enable 有效时,计数器计数 begin if(counter1==8'b)//当 counter 等于 156 时 begin counter1&=8'b;//counter 清零 t1&=t1 + 1;//t1 取反 end else begin counter1&=counter1 + 1;29 UART 设计t1&=t1; end end else begin counter1&=8'b; t1&=0; end endmodule3.6.13UART 波特发生器程序仿真图 如图 3-11;图 3-11UART 波特发生器程序仿真图 由图判读: 1.当 clk_enable 为 0 时,时钟不计时;2.当 clk_enable 为 1 时,时钟计时30 结论结论本文用 verilog HDL 编写的 UART 包括波特发生器,程序控制器,数据接收 器,数据发送器,使用单工模式工作。其中的数据接收器和数据发送器可以分开 单独使用,也可以合并使用。在程序控制器中增加一组寄存器,可以实现双工模 式工作,在波特发生器中增加一组寄存器,可以实现波特率改变。 用 FPGA 实现 UART 功能,可以减小电路板的面积,降低电路的功耗,提 高设计的稳定性,也充分利用了 FPGA 的剩余资源,这种硬件软件化的方法已 成为当今电子设计领域中的主导趋势。在很多场合下,该 UART 控制器可以完 全 代 替 专 用 的 IC 芯 片 。 经 管 仿 真 后 , 综 合 报 告 显 示 消 耗 了 195 个 LE (LogicElement),在中大规模的 FPGA 中,这只是很小的一部分资源。31 参考文献参考文献[1]夏宇闻. Verilog 数字系统设计教程[M].北京:北京航空航天大学出版社,2003 [2]Bhasker J. Verilog HDL Synthesis A Practical primer[M]. London, UK:Star G 1998. [3]Liakot Ali, Roslina Sidek, Ishak Aris, Alauddin Mohd. Ali, BambangSunaryo Suparjo.Design of a micro - UART for SoC application [J].In:Computers and Electrical Engineering 30 ( C268. [4]Wilfried Elmenreich,Martin Delvaio &Time-Triggered Communicationwith UARTS& [J]4th IEEE International Workshop onFactory Communication Systems,Vasteras,Sweden,August . [5]Martin S.Michael,&A Comparison of the INS8250,NS16450 anNS16550AF Series of UARTs& [J] National Seiniconductor ApplicationNote 493,April 1989. [6]潘松,王国栋.VHDL 实用教程「M].成都:电子科技大学出版社,2003. [7]赵尔宁,邵高平.用内建自测试(BIST)方法测试 IP 核阴.微计算机信息,-135. [8]1K 杰 , 杨 建 宁 . 基 于 FPGA 的 UART 控 制 器 的 设 计 和 实 现 [J]. 微 计 算 机 信 息 , :111-11332 致谢致谢四年的大学生活即将结束, 在论文完成之际,我衷心感谢所有关心和帮助我 完成毕业设计的老师和同学。 首先,我要感谢我的家人,尤其是为我辛苦奔波的爸爸妈妈,没有您们十几 年来对我受教育的支持,就没有今天的我,谢谢您们对我的培养! 然后我要感谢我的导师杨硕,在我做毕业设计期间,杨老师给我提供了很 多指导与帮助,让我进一步掌握了 Verilog 编码的技能,还对我的毕业设计提出 了很多宝贵的建议,这样我才更好的完成了本设计。谢谢杨硕老师的辛勤教导! 您辛苦了! 我还要感谢电子科技大学成都学院微电子技术系的各位老师,尤其是辅导 员张洋、王伊阳, 在我大学期间,您们给予了我很多的鼓励与教诲,我才能在 大学里健康的全面成长发展!谢谢您! 最后再次衷心感谢所有关心帮助我的老师、同学! 感谢我的亲人和朋友多年来对我的关心和支持。 感谢所有引文的作者和给予我帮助的人。 最后,衷心感谢在百忙之中评阅论文和参加答辩的各位专家教授!33 附录附录UART 的 RTL 级图34 外文资料原文外文资料原文Transmitting and receiving serial data The Universal Asynchronous Receiver/Transmitter (UART) controller is the key component of the serial communications subsystem of a computer. The UART takes bytes of data and transmits the individual bits in a sequential fashion. At the destination, a second UART re-assembles the bits into complete bytes.Serial transmission of digital information (bits) through a single wire or other medium is much more cost effective than parallel transmission through multiple wires. A UART is used to convert the transmitted information between its sequential and parallel form at each end of the link. Each UART contains a shift register which is the fundamental method of conversion between serial and parallel forms. The UART usually does not directly generate or receive the external signals used between different items of equipment. Typically, separate interface devices are used to convert the logic level signals of the UART to and from the external signaling levels. External signals may be of many different forms. Examples of standards for voltage signaling are RS-232, RS-422 and RS-485 from the EIA. Historically, the presence or absence of current (in current loops) was used in telegraph circuits. Some signaling schemes do not use electrical wires. Examples of such are optical fiber, IrDA (infrared), and (wireless) Bluetooth in its Serial Port Profile (SPP). Some signaling schemes use modulation of a carrier signal (with or without wires). Examples are modulation of audio signals with phone line modems, RF modulation with data radios, and the DC-LIN for power line communication. Communication may be &full duplex& (both send and receive at the same time) or &half duplex& (devices take turns transmitting and receiving). As of 2008, UARTs are commonly used with RS-232 for embedded systems communications. It is useful to communicate between microcontrollers and also with PCs. Many chips provide UART functionality in silicon, and low-cost chips exist to convert logic level signals (such as TTL voltages) to RS-232 level signals (for example, Maxim's MAX232).Asynchronous receive and transmit In asynchronous transmitting, teletype-style UARTs send a &start& bit, five to35 福州大学工程技术学院毕业设计论文eight data bits, least-significant-bit first, an optional &parity& bit, and then one, one and a half, or two &stop& bits. The start bit is the opposite polarity of the data-line's idle state. The stop bit is the data-line's idle state, and provides a delay before the next character can start. (This is called asynchronous start-stop transmission). In mechanical teletypes, the &stop& bit was often stretched to two bit times to give the mechanism more time to finish printing a character. A stretched &stop& bit also helps resynchronization. The parity bit can either make the number of &one& bits between any start/stop pair odd, or even, or it can be omitted. Odd parity is more reliable because it assures that there will always be at least one data transition, and this permits many UARTs to resynchronize. In synchronous transmission, the clock data is recovered separately from the data stream and no start/stop bits are used. This improves the efficiency of transmission on suitable channels since more of the bits sent are usable data and not character framing. An asynchronous transmission sends no characters over the interconnection when the transmitting device has nothing to send -- but a synchronous interface must send &pad& characters to maintain synchronism between the receiver and transmitter. The usual filler is the ASCII &SYN& character. This may be done automatically by the transmitting device. USART chips have both synchronous and asynchronous modes.Serial to Parallel Algorithm Asynchronous transmission allows data to be transmitted without the sender having to send a clock signal to the receiver. Instead, the sender and receiver must agree on timing parameters in advance and special bits are added to each word which are used to synchronize the sending and receiving units. When a word is given to the UART for Asynchronous transmissions, a bit called the &Start Bit& is added to the beginning of each word that is to be transmitted. The Start Bit is used to alert the receiver that a word of data is about to be sent, and to force the clock in the receiver into synchronization with the clock in the transmitter. These two clocks must be accurate enough to not have the frequency drift by more than 10% during the transmission of the remaining bits in the word. (This requirement was set in the days of mechanical teleprinters and is easily met by modern electronic equipment.) After the Start Bit, the individual bits of the word of data are sent, with the Least Significant Bit (LSB) being sent first. Each bit in the transmission is transmitted36 外文资料for exactly the same amount of time as all of the other bits, and the receiver “looks” at the wire at approximately halfway through the period assigned to each bit to determine if the bit is a 1 or a 0. For example, if it takes two seconds to send each bit, the receiver will examine the signal to determine if it is a 1 or a 0 after one second has passed, then it will wait two seconds and then examine the value of the next bit, and so on. The sender does not know when the receiver has “looked” at the value of the bit. The sender only knows when the clock says to begin transmitting the next bit of the word. When the entire data word has been sent, the transmitter may add a Parity Bit that the transmitter generates. The Parity Bit may be used by the receiver to perform simple error checking. Then at least one Stop Bit is sent by the transmitter. When the receiver has received all of the bits in the data word, it may check for the Parity Bits (both sender and receiver must agree on whether a Parity Bit is to be used), and then the receiver looks for a Stop Bit. If the Stop Bit does not appear when it is supposed to, the UART considers the entire word to be garbled and will report a Framing Error to the host processor when the data word is read. The usual cause of a Framing Error is that the sender and receiver clocks were not running at the same speed, or that the signal was interrupted. Regardless of whether the data was received correctly or not, the UART automatically discards the Start, Parity and Stop bits. If the sender and receiver are configured identically, these bits are not passed to the host. If another word is ready for transmission, the Start Bit for the new word can be sent as soon as the Stop Bit for the previous word has been sent. Because asynchronous data is “self synchronizing”, if there is no data to transmit, the transmission line can be idle. A data communication pulse can only be in one of two states but there are many names for the two states. When on, circuit closed, low voltage, current flowing, or a logical zero, the pulse is said to be in the &space& condition. When off, circuit open, high voltage, current stopped, or a logical one, the pulse is said to be in the &mark& condition. A character code begins with the data communication circuit in the space condition. If the mark condition appears, a logical one is recorded otherwise a logical zero. Figure 1 shows this format.The start bit is always a 0 (logic low), which is also called a space. The start bit signals the receiving DTE that a character code is coming. The next five to eight bits, depending on the code set employed, represent the character. In the ASCII code set the eighth data bit may be a parity bit. The next one or two bits are always in the39 福州大学工程技术学院毕业设计论文mark (logic high, i.e., '1') condition and called the stop bit(s). They provide a &rest& interval for the receiving DTE so that it may prepare for the next character which may be after the stop bit(s). The rest interval was required by mechanical Teletypes which used a motor driven camshaft to decode each character. At the end of each character the motor needed time to strike the character bail (print the character) and reset the camshaft. All operations of the UART hardware are controlled by a clock signal which runs at a multiple (say, 16) of the data rate - each data bit is as long as 16 clock pulses. The receiver tests the state of the incoming signal on each clock pulse, looking for the beginning of the start bit. If the apparent start bit lasts at least one-half of the bit time, it is valid and signals the start of a new character. If not, the spurious pulse is ignored. After waiting a further bit time, the state of the line is again sampled and the resulting level clocked into a shift register. After the required number of bit periods for the character length (5 to 8 bits, typically) have elapsed, the contents of the shift register is made available (in parallel fashion) to the receiving system. The UART will set a flag indicating new data is available, and may also generate a processor interrupt to request that the host processor transfers the received data. In some common types of UART, a small first-in, first-out (FIFO) buffer memory is inserted between the receiver shift register and the host system interface. This allows the host processor more time to handle an interrupt from the UART and prevents loss of received data at high rates. Transmission operation is simpler since it is under the control of the transmitting system. As soon as data is deposited in the shift register, the UART hardware generates a start bit, shifts the required number of data bits out to the line,generates and appends the parity bit (if used), and appends the stop bits. Since transmission of a single character may take a long time relative to CPU speeds, the UART will maintain a flag showing busy status so that the host system does not deposit a new character for transmission until the previous on this may also be done with an interrupt. Since full-duplex operation requires characters to be sent and received at the same time, practical UARTs use two different shift registers for transmitted characters and received characters. Transmitting and receiving UARTs must be set for the same bit speed, character length, parity, and stop bits for proper operation. The receiving UART may detect some mismatched settings and set a &framing error& flag bit in exceptional cases the receiving UART will produce an erratic stream of mutilated characters and transfer them to the host system. Typical serial ports used with personal computers connected to modems use eight data bits, no parity, for this configuration the number of ASCII40 [ 外文原文character per seconds equals the bit rate divided by 10. History Some early telegraph schemes used variable-length pulses (as in Morse code) and rotating clockwork mechanisms to transmit alphabetic characters. The first UART-like devices (with fixed-length pulses) were rotating mechanical switches (commutators). These sent 5-bit Baudot codes for mechanical teletypewriters, and replaced morse code. Later, ASCII required a seven bit code. When IBM built computers in the early 1960s with 8-bit characters, it became customary to store the ASCII code in 8 bits. Gordon Bell designed the UART for the PDP series of computers. Western Digital made the first single-chip UART WD1402A around 1971; this was an early example of a medium scale integrated circuit. An example of an early 1980s UART was the National Semiconductor 8250. In the 1990s, newer UARTs were developed with on-chip buffers. This allowed higher transmission speed without data loss and without requiring such frequent attention from the computer. For example, the popular National Semiconductor 16550 has a 16 byte FIFO, and spawned many variants, including the 16C550, 16C650, 16C750, and 16C850. Depending on the manufacturer, different terms are used to identify devices that perform the UART functions. Intel called their 8251 device a &Programmable Communication Interface&. MOS Technology 6551 was known under the name &Asynchronous Communications Interface Adapter& (ACIA). The term &Serial Communications Interface& (SCI) was first used at Motorola around 1975 to refer to their start-stop asynchronous serial interface device, which others were calling a UART.Some very low-cost home computers or embedded systems dispensed with a UART and used the CPU to sample the state of an input port or directly manipulate an output port for data transmission. While very CPU-intensive, since the CPU timing was critical, these schemes avoided the purchase of a costly UART chip. The technique was known as a bit-banging serial port. UART models , early 16550: Obsolete with 1-byte buffers 1A, 16C552: 16-byte buffers, TL=1,4,8,14; 115.2 kbps standard, many support 230.4 or 460.8 kbps 16650: 32-byte buffers. 460.8 kbps41 福州大学工程技术学院毕业设计论文16750: 64-byte buffer for send, 56-byte for receive. 921.6 kbps 1: 128-byte buffers. 460.8 kbps or 1.5 mbps 16950 Hayes ESP: 1k-byte buffers.Structure A UART usually contains the following components: a clock generator, usually a multiple of the bit rate to allow sampling in the middle of a bit period. input and output shift registers transmit/receive control read/write control logic transmit/receive buffers (optional) parallel data bus buffer (optional) First-in, first-out (FIFO) buffer memory (optional)Special Receiver ConditionsOverrun Error An &overrun error& occurs when the UART receiver cannot process the character that just came in before the next one arrives. Various UART devices have differing amounts of buffer space to hold received characters. The CPU must service the UART in order to remove characters from the input buffer. If the CPU does not service the UART quickly enough and the buffer becomes full, an Overrun Error will occur.Underrun Error An &underrun error& occurs when the UART transmitter has completed sending a character and the transmit buffer is empty. In asynchronous modes this is treated as an indication that no data remains to be transmitted, rather than an error, since additional stop bits can be appended. This error indication is commonly found in USARTs, since an underrun is more serious in synchronous systems.Framing Error42 外文原文A &framing error& occurs when the designated &start& and &stop& bits are not valid. As the &start& bit is used to identify the beginning of an incoming character, itacts as a reference for the remaining bits. If the data line is not in the expected idle state when the &stop& bit is expected, a Framing Error will occur.Parity Error A &parity error& occurs when the number of &active& bits does not agree with the specified parity configuration of the UART, producing a Parity Error. Because the &parity& bit is optional, this error will not occur if parity has been disabled. Parity error is set when the parity of an incoming data character does not match the expected value.Break Condition A &break condition& occurs when the receiver input is at the &space& level for longer than some duration of time, typically, for more than a character time. This is not necessarily an error, but appears to the receiver as a character of all zero bits with a framing error. Some equipment will deliberately transmit the &break& level for longer than a character as an out-of-band signal. When signaling rates are mismatched, no meaningful characters can be sent, but a long &break& signal can be a useful way to get the attention of a mismatched receiver to do something (such as resetting itself). UNIX systems and UNIX-like systems such as Linux can use the long &break& level as a request to change the signaling rate.Baudrate In embedded designs, it is necessary to choose proper oscillator to get correct baud rate with small or no error. Some examples of common crystal frequencies and baud rates with no error: 18.432 MHz: 300, 600, , , 19200 Bd 22.118400 MHz: 300, 600, , , , 1, 3, 115200 Bd 16 MHz: 0000 Bd See also43 福州大学工程技术学院毕业设计论文Asynchronous serial communication Baud bit rate Modem Morse code Serial communication Serial port USB 16550 UART 8250 UARTExternal links A tutorial on the RS-232 standard, describing the definition of mark, space and their relationship with negative and positive voltages Freebsd Tutorials (includes standard signal definitions, history of UART ICs, and pinout for commonly used DB25 connector) UART Tutorial for Robotics (contains many practical examples)44 译文译文通用异步接收/发送器 是一种“异步接收器/发射器” ,一块电脑 硬件的转 换之间的数据并行和串行的形式。UART 常用与其他通信标准,如环境影响评估 RS - 232 接口 。 UART 通常是个(或部分) 积体电路用于串行通讯 ,电脑或外围设备的串 行端口 。 UART 现在包含在微控制器。 双 UART 或两个 UART 杜阿尔特结合 到一个单一芯片中。 许多现代集成电路与现在的 UART 还可以沟通同步;这些设 备被称为通用同步 。Transmitting and receiving serial data 发送和接收串行数据 在通用异步接收/发送器( UART 接口)控制器是关键的组成部分,串行通 信子系统的一台计算机。 采取的异步字节的数据传输和个人位依次时尚。 在目 的地, 第二个 UART 重新组装成完整的 bytes.Serial 位数字信息传输模式 bits ) ( 通过一个单一的有线或其他媒介更符合成本效益比并行传输,通过多条线路。阿 的 UART 是用来转换之间的信息传播其顺序和并行形式两端的链接。 每个 UART 接口包含一个移位寄存器这是最根本的方法之间的转换串行和并行的形 式。 该个 UART 通常并不直接产生或接收外部信号之间使用不同的设备。通常 情况下,单独的接口设备是用来转换逻辑电平信号的 UART 和来自外部信号的 水平。 外部信号可能有许多不同的形式。 实例标准电压信号的 RS - 232 接口 , 遥感- 422 和 RS - 485 接口的环境影响评估 。 从历史上看, 存在或不存在电流 (在 目前的循环 )用于电报电路。 一些信令计划不使用电线。.例如是光纤 ,支持 IrDA ( 红外 )和(无线) 蓝牙在串口简介(许可证) 。 一些计划使用信号 调制的载波信号 (带或不带线) 。 例子有调制的音频信号与电话线调制解调器 , 射频调制数据收音机,以及直流林的电力线载波通信 。 通信可能是“全双工” (发送和接收在同一时间)或“半双工” (设备轮流发 送和接收) 。 截至 2008 年,个 UART 常用的 RS - 232 接口的嵌入式系统的通信。 它是 有用的微控制器之间的沟通,并与个人电脑。 许多芯片提供的 UART 功能硅, 和低成本的芯片存在转换逻辑电平信号(如对焦 TTL 电压) ,以 RS - 232 接口 信号(例如, Maxim 的 MAX232 ) 。43 福州大学工程技术学院毕业设计论文Asynchronous receive and transmit异步接收和发送在异步传输, 电传式个 UART 发送“开始”位, 7 点 55 比特的数据,最重 要的位第一,一个可选的“平价”位,然后一,一个半或两个“一站式”的位。 起 始位是极性相反的数据线的空闲状态。 停车位是数据线的空闲状态,并规定在 一段时间后,下一个字符就可以开始。 (这就是所谓的异步起止传输) 。在机 械 teletypes 的“一站式”位往往延伸到 2 位, 以使这一机制更多的时间来完成印刷 字符。加长“一站式”位也有助于同步。 奇偶校验位可以使一些“一”位之间的任何启动/停止对奇怪的,甚至,也可 以省略。奇数奇偶更可靠,因为它确保总是会有至少一个数据过渡,这许多个 UART ,以允许同步。 在同步传输,时钟数据恢复分开的数据流,并没有启动/停止位被使用。这 提高了效率,传输的适当渠道,因为更多的比特发出的可用的数据,而不是性质 的框架。异步传输传送任何字符的互连时,传动装置无关发送-只有闲置停止位; 但同步接口必须发出“垫”字符之间保持同步的接收器和发射器。 通常的填料是 ASCII 的 “同步”的特点。 这可能是自动完成的传动装置。 芯片同步和异步模式。 Serial to Parallel Algorithm 串行到并行算法 异步传输允许数据传送有没有发件人发送时钟信号的接收器。相反,发送和 接收必须商定时间提前参数和特殊位被添加到每个单词用来同步发送和接收单 位。 如果某个词给予的 UART 异步传输, 有些所谓的“开始有点”被添加到开始每 个单词是将转交。 起始位是用来提醒接收器,一个字的数据即将发出,并以武 力的时钟同步接收到的时钟发射机。 这两个时钟必须准确没有足够的频率漂移 了 10 %以上的传输过程中的其余位在 Word 。 (此要求是在未来的日子机械 电传打字电报,是很容易满足了现代化的电子设备。 )开始后位,个人位的话, 数据传送,以最低有效位( LSB 的)被第一次。每比特的传输转交正是相同的 时间内为所有其他位,并接收“期待”在铁丝网约一半的期间分配给每个位,以决 定是否位是 1 或 0 。 例如,如果需要两秒钟发送每比特,将审查接收的信号以 确定它是否是一个 1 或 0 后一秒过去了,然后将等待 2 秒钟,然后检查的价值, 未来位等等。 .发件人不知道什么时候接收了“期待”的价值位。 寄件人只知道说,当时钟 开始转递明年位一词。44 译文.当整个数据一词已发送,发射器可添加一个奇偶校验位产生的发射机。 的 奇偶校验位可使用的接收器进行简单的错误检查。 那么至少一站式位发射机发出 的。 当接收器收到的所有比特的数据字,可以检查奇偶校验码(包括发送和接收 必须商定是否有奇偶校验位将用于) ,然后接收寻找停止位。 如果停止位时, 没有出现这是理应的异步认为整个词是乱码, 并将报告帧错误的主机处理器的数 据时,读字。 通常的原因帧错误的是,发送和接收时钟并没有运行在相同的速 度,或者说,信号中断。 无论是收到的数据正确与否,自动丢弃的 UART 开始,奇偶校验和停止位。 如果发送和接收的配置相同,这些位不能传递到主机。如果另一个词准备传输, 开始位的新词可以发送尽快停止位前一词已发送。 由于异步数据是“自我同 步” ,如果没有数据传输,传输线可以闲置。阿数据通信 脉冲只能在两个国家 之一,但也有许多名字,这两个国家。 当打开时,关闭电路,低电压,电流流 动,或逻辑为零,脉搏据说是在“空间”的条件。如果是 off ,电路开放式,高电 压,电流停止,或逻辑 1 ,脉冲被认为是在“商标”的条件。 阿字符代码始于数 据通信电路在空间条件。 如果该商标的条件看来,是一个合乎逻辑的一个合乎 逻辑的记录,否则为零。开始位总是 0 (逻辑低) ,也就是所谓的空间 。 起始位信号接收终端的 字符代码正在到来。在今后的 5 到 8 位,这取决于代码集就业,代表的性质。在 ASCII 码的数据集第八位可能是奇偶校验位。在未来一个或两个位都是在马克 (逻辑高,也就是说, '1 ' )的条件,并呼吁停止位(县) 。他们提供了一个 “休息”间隔接收终端 ,以便它可以准备下一个字符可能会在停止位(县) 。 其 余的时间间隔,需要用机械 Teletypes 使用电动机驱动凸轮轴解码每个字符。 在 每个字符的运动需要更多的时间来打击性质保释(打印的字符)和重置凸轮轴。 所有业务的 UART 硬件控制的时钟信号运行在一个多(也就是说, 16 日) 的数据速率-每个数据位是,只要 16 个时钟脉冲。 T 该接收机测试状态的输入 信号在每个时钟脉冲, 寻找开始启动位。如果明显开始位持续至少有一半的比特 时间, 它是有效的, 信号开始一个新的特点。 如果不是, 虚伪的脉冲被忽略。 等 待进一步位时间,国家线再次取样和由此产生的水平频率为移位寄存器。 后所 需数目的位期间的字符长度(第 5 至第 8 位,通常)已经过去了,内容的移位寄 存器是提供(并行方式)的接收系统。 该个 UART 将国旗表明新的数据,而且 还可能产生一个处理器的中断请求,主机处理器转让收到的数据。在一些常见的47 福州大学工程技术学院毕业设计论文UART ,一个小头中,先出( FIFO 的)缓冲存储器之间插入接收移位寄存器和 主机系统的接口。 这使得主处理器有更多的时间来处理中断的 UART 和防止损 失收到的数据率高。 system.传输操作更简单, 因为它控制下的传输系统。 当数据保存在移位寄存 器的硬件生成的 UART 开始位,转变所需数量的数据位到线,生成和附加的奇 偶校验位(如果使用) ,以及附加的停止位。 由于传输的一个单一的字符可能 会需要很长的时间相对于 CPU 的速度,将保持的 UART 国旗显示繁忙的地位, 让主机系统并不存款一个新的字符传输到前一个已经完成,这也可能是完成中 断。自全双工操作需要的字符将发送和接收在同一时间,实际个 UART 使用两 种不同的移位寄存器的传播特征及收到字符。 发送和接收 UART 接口必须设置为同一位速度,字符长度,奇偶校验,停 止位的正常运行。 接收的 UART 可以检测一些不相符的设置, 并设定了“帧错误” 标志位的主机系统;在特殊情况下,接收的 UART 将产生不稳定流肢解字符和他 们转移到主机系统。.典型的串行端口,使用个人电脑连接到调制解调器使用了 8 个数据位,无奇偶校验,一个停止位;这一配置的数量 ASCII 字符每秒等于比特 率除以 10 。 History 历史 有些早期的电报计划使用可变长度豆类(如在莫尔斯电码 )和旋转发条机 制转交字母。 第一次的 UART 样装置 (与固定长度脉冲) 的旋转机械式开关 换 ( 向器 )。 这些派出 5 位 Baudot 教授守则机械 teletypewriters , 取代莫尔斯电码 。 Later, ASCII required a seven bit code.后来, ASCII 的需要 7 位代码。当 IBM 公 司建立的计算机在 60 年代初的 8 位字符,它成为习惯存储 ASCII 码的 8 位。 贝尔的 UART 设计的等离子系列个人电脑。 西部数字作出了第一款单芯片 的 UART WD1402A 约 1971 年;这是一个早期的例子一个中等规模的集成电路 。 一个例子是 20 世纪 80 年代初的 UART 是美国国家半导体 8250 。在 20 世 纪 90 年代,制定了新的 UART 接口,带有片上缓冲器。这使得传输速度更高的 数据丢失和未经而不需要如此频繁的注意力从电脑。例如,流行的国家半导体 16550 有一个 16 字节的 FIFO , 并产生许多变种, 其中包括 16C550 , 16C650 , 16C750 和 16C850 。 根据不同的制造商,不同的条件下可用于识别装置执行的 UART 功能。 英 特尔所谓的 8251 设备的“可编程通信接口” 。 马鞍山技术 6551 已知的名义下 “异步通信接口适配器” ( ACIA ) 。 所谓“串行通信接口” ( SCI )的首次 使用在摩托罗拉公司在 1975 年提及的起止异步串行接口设备,它被调用的48 译文UART 。 一些成本很低的家庭计算机或嵌入式系统配有 UART 和使用的 CPU 样品状 况的一个输入端口,或直接操纵输出端口的数据传输。虽然非常 CPU 密集型的, 因为 CPU 的时间是至关重要的, 这些计划避免了购买昂贵的 UART 芯片。 这项 技术被称为位撞串行端口。 异步模式UART models早期 16550 :过时 1 字节缓冲器 1 16 字节缓冲器的 TL = 1,4,8,14 ; 115.2 kbps 的标准, 许多支持 230.4 或 460.8 kbps 的 32 字节的缓冲区。 460.8 kbps 460.8 kbps 的 64 字节的缓冲区发送, 56 字节的接收。 921.6 kbps 921.6 kbps 的 128 字节的缓冲区。 460.8 kbps or 1.5 mbps 460.8 Kbps 或 1.5 Mbps 的
Hayes ESP: 1k-byte buffers. 1000 字节的缓冲区。 Structure 结构 UART 通常包含以下内容: .时钟发生器,通常是多种的比特率,使样品中有点时期。 输入和输出移位寄存器 发射/接收控制 读/写控制逻辑 发射/接收缓冲器(可选) 并行数据总线缓冲器(可选) 第一次中,先出( FIFO 的 )缓冲内存(可选) 特别接收条件 Overrun Error 溢出错误 一个“溢出错误”时发生的 UART 接收器无法处理的性质, 仅仅排在之后再进 入下一个到达。 不同的 UART 设备有不同数量的缓冲空间举行收到字符。 必 须服务的 CPU 的 UART 接口,以便消除字符输入缓冲区。如果 CPU 不服务的 UART 不够迅速,并成为全缓冲,超支将出现错误。 Underrun Error 欠载错误49 福州大学工程技术学院毕业设计论文一个“欠错误”时发生的 UART 发射机已完成派遣一个特点和传输缓冲区是 空的。在异步模式,这被视为表明,仍然没有任何数据传送,而不是一个错误, 因为额外的停止位可附加。 此错误指示中常见的通用同步,因为一个更为严重 的不足是在同步系统。 Framing Error 帧错误 .一个“帧错误”发生在指定的“开始”和“一站式”的位无效。随着“开始”位是用 来识别开始传入性质,它作为参考,其余位。 如果数据线是不能预期的空闲状 态时, “一站式”位预计,一帧将出现错误 。 Parity Error 奇偶错误 一个“平等的错误”时,就会发生一些“积极的”比特不同意指定平价配置的 UART ,产生奇偶错误 。.因为“平价”位是可选的,这个错误不会发生如果平价 已被禁用。奇偶错误时设置的平价数据的性质不符预期价值。 突破条件Break Condition一个“打破状态”时,就会发生接收器输入是在“空间”的水平比一些期限较长 的时间,通常情况下,一个多字符的时间。这不一定是一个错误,但似乎接收一 个字符的所有零位的帧错误。 一些设备将转交故意“打破”水平的时间超过一个字符作为一个带外信号。 当 信号利率不匹配的,没有取得有意义的字符可以发送,但长期“打破”的信号可以 是一个有用的方法来注意错接收做某事(如重置本身) 。 的 UNIX 系统和类 UNIX 系统如 Linux 的可以使用较长的“打破”水平的要求来改变信号率。 Baudrate 波特率 在嵌入式设计, 有必要选择适当的振荡器,以获得正确的波特率与小或没有 错误。一些实例共同晶体频率和波特率,也没有显示错误: 18.432 MHz: 300, 600, , , 19200 Bd 18.432 兆赫: 300 , 600 , 1200 , 2400 , 4800 , 9600 , 19200 屋宇署 22.118400 MHz: 300, 600, , , , 1, 3, 115200 Bd 22.118400 兆赫:300 ,600 ,1200 ,1800 ,2400 ,4800 , 7200 , 9600 , 14400 , 19200 , 38400 , 57600 , 115200 屋宇署 16 MHz: 0000 Bd 16 兆赫:一十二点五○○万, 500000 屋宇署 [ edit ] See also [ 编辑 ]另见50 译文Asynchronous serial communication 异步串行通信 Baud 波特率 bit rate 比特率 Modem 调制解调器 Morse code 莫尔斯电码 Serial communication 串行通信 Serial port 串口 USB USB 接口 16550 UART 16550 个 UART 8250 UART 8250 个 UART RS - 232 接口标准,说明商标的定义,空间及其与消极和积极电压 FreeBSD 的教程 (包括标准信号的定义,历史的 UART IC 和引脚常用 DB25 连接器) 异步教学的机器人 (包含了许多实际例子)51
赞助商链接
racktom.com
copyright &copyright 。共享资料网内容来自网络,如有侵犯请联系客服。}

我要回帖

更多关于 micro USB 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信