数字系统设计 Digital System Design

Slides:



Advertisements
Similar presentations
《 E D A 技 术》 课 程 教 学 讲授:伍宗富 湖南文理学院电气与信息工程学院 2017年3月10日星期五.
Advertisements

Introduction to Verilog
实验四 利用中规模芯片设计时序电路(二).
第2章 FPGA/CPLD结构与应用.
现代电子设计技术 Modern Electronic Design Technology
第4章 VHDL设计初步.
5.4 顺序脉冲发生器、 三态逻辑和微机总线接口 顺序脉冲发生器 顺序脉冲 计数型 分类 移位型.
Chapter 5 Sequential Logic Circuit
數位邏輯設計與實習 ch04 組合邏輯電路設計.
第八章 可编程逻辑器件 本章的重点: 本章的难点: 1.PLD的基本特征,分类以及每种类型的特点;
Combinational Logic 組合邏輯
Applications of Digital Signal Processing
Hardware Chen Ching-Jung
授课对象:微电子、电子、计算机专业本科生、研究生 先修课:数字逻辑电路、Verilog
数字系统设计 I Digital System Design I
数字系统设计 Digital System Design
触发器和时序电路分析 刘鹏 浙江大学信息与电子工程学院 March 30, 2017 ZDMC.
时序电路 计数器分析及设计 刘鹏 浙江大学信息与电子工程学院 April 10, 2018 EE141
Chapter 5 Verilog 硬體描述語言
数字系统设计 Digital System Design
Chapter 5 Verilog硬體描述語言
Ch01-2 Verilog語法 資料流(DataFlow)設計 行為(Behavior)設計
EDA技术 廖义奎.
数字系统设计 Digital System Design
时序电路 计数器分析及设计 刘鹏 浙江大学信息与电子工程学院 March 31, 2016 EE141
版权所有,禁止未经授权的商业使用行为 何宾 Tel: 北京中教仪装备技术有限公司.
嵌入式系统课程简介 宋健建 南京大学软件学院 2004/02/10.
第四阶段实验 ISP器件的设计与应用 一、实验目的 二、实验内容与要求 三、ISP器件的开发流程 四、EDA Pro2K实验系统介绍
数字系统设计 Digital System Design
数字系统设计 Digital System Design
微程序控制器 刘鹏 Dept. ISEE Zhejiang University
数字系统设计复习 Digital System Design Summary
第 9 章 存储器和可编程逻辑器件 9.1 半导体存储器 9.2 可编程逻辑器件.
第13章 数字电路基础 13.1 数字电路概述 13.2 数字电路中的数值与码制 13.3 逻辑代数 13.4 逻辑门电路
第八章 可编程逻辑器件 8.1 可编程逻辑器件的基本特点 数字集成电路从功能上可分为通用型、专用型两大类。
可编程器件与电子设计自动化 上海交通大学电工及电子技术实验中心 一九九九年三月.
组合逻辑3 Combinational Logic
数字系统设计 Digital System Design
第四阶段实验 Verilog HDL简介 1 Verilog描述的一般结构 2 Verilog HDL基础知识 3 设计举例
第三章 项目设定.
本章小结: 可编程逻辑器件(Programmable Logic Device,简称为 PLD)是目前数字系统设计的主要硬件基础。现场可编程门阵列 FPGA(Field Programmable Gate Array)现场可编程门阵列FPGA在结构上由逻辑功能块排列为阵列,功能由逻辑结构的配置数据决定,配置数据可以存放在片外的EPROM或其他存储体上,人们可以控制加载过程,在现场修改器件的逻辑功能。
Programmable Logic Architecture Verilog HDL FPGA Design
JTAG INTERFACE SRAM TESTER WITH C-LCM
邏輯設計 Logic Design 顧叔財, Room 9703, (037)381864,
数字系统设计 Digital System Design
语法进阶.
时序电路设计 刘鹏 浙江大学信息与电子工程系 Apr. 24, 2011 EE141
数字电路 Digital Circuits 王维东 浙江大学信息与电子工程系 信息与通信工程研究所 March 03, 2009 EE141
触发器和时序电路分析 刘鹏 浙江大学信息与电子工程学院 March 29, 2016 ZDMC.
Verilog HDL 硬件描述语言 刘鹏 浙江大学信息与电子工程系 Mar. 6, 2012
Instructions: Language of the Machine
EDA 第二章 可编程逻辑器件.
第七章 可编程逻辑器件 PLD 7.1 PLD 概述 PLD 的电路结构及分类 PLD 的编程工艺及描述的逻辑规则和符号 PLD 的设计过程及主要优点 7.2 只读存储器 ROM 的内部结构 用ROM 实现组合逻辑设计 常用的LSI.
C语言程序设计 主讲教师:陆幼利.
计算机学院 数字逻辑实验的要求.
虚 拟 仪 器 virtual instrument
计算机EDA设计 教 程 北航计算机学院 艾明晶.
设计示例一 用门级结构描述D触发器:.
數位邏輯設計 VHDL.
SoC 與微控制器的發展 朱亞民.
组合逻辑电路 ——中规模组合逻辑集成电路.
《数字电子技术基础》(第五版)教学课件 清华大学 阎石 王红
实验三 16位算术逻辑运算实验 不带进位控制的算术运算 置AR=1: 设置开关CN 1 不带进位 0 带进位运算;
长春理工大学 电工电子实验教学中心 数字电路实验 数字电路实验室.
动词不定式(6).
5. Combinational Logic Analysis
FPGA组合逻辑 王安然.
Verilog HDL 基本语法 STEP 2016/12/3.
第九章 存储器和可编程逻辑器件 本章主要内容 半导体存储器 只读存储器 随机存取存储器 存储器容量的扩展 可编程逻辑器件
Programmable Logic System Design
Presentation transcript:

数字系统设计 Digital System Design EE141 数字系统设计 Digital System Design -----可编程器件与硬件描述语言 王维东 Weidong Wang 浙江大学信息与电子工程学院 College of Information Science & Electronic Engineering 信息与通信网络工程系 Zhejiang University Spring 2018 – Lec. #5

任课教师 王维东 TA: 浙江大学信息与电子工程学院, 信电楼306 邮箱:wdwang@zju.edu.cn EE141 任课教师 王维东 浙江大学信息与电子工程学院, 信电楼306 邮箱:wdwang@zju.edu.cn College of Information Science & Electronic Engineering Zhejiang University, Hangzhou, 310027 Tel: 86-571-87953170 (O) Mobile: 13605812196 TA: 陈 佳云 Jiayun CHEN,13161700140; chenjy93@outlook.com; 陈 彬彬 Binbin CHEN, 13071888906; 15091831397@163.com; Office Hours:玉泉信电楼 308室(可以微信或邮件联系). Spring 2018 – Lec. #5

Prerequisites预修课程 电子电路基础 电子线路 C语言 How to learn this Course? Not only listening, thinking and waiting …. But Exercise, Simulation, Practice!

课程简介 课程代码:111C0120 参考书 阎石, 数字电子技术基础, 第6版, 高等教育出版社, 2016. EE141 课程简介 课程代码:111C0120 参考书 阎石, 数字电子技术基础, 第6版, 高等教育出版社, 2016. 王金明著,数字系统设计与Verilog HDL,电子工业出版社,第6版 补充讲义/期中考试前预备 Stanford 大学 108A课程notes. R.H.Katz, G.Borriello, Contemporary Logic Design, second edition,电子工业出版社, 2005. M.M.Mano, 数字设计(第四版), 电子工业出版社, 2010. http://www.prenhall.com/mano Spring 2018 – Lec. #5

Other Course Info Website: http://mypage.zju.edu.cn/wdwd/教学工作/ Check frequently 答疑 玉泉信电楼308室/周三周五下午2:30-5:00 上课课间、课后均可 Email,微信群/数字系统设计2018,短信均可

Grading (考核) Final grades will be computed approximately as follows: 平时(含课程作业、期中考试+小测验、Project、出勤等)30% Class Room Check Homework Sets 作业每周三上交截止期为课后一周内有效。 Project 2 projects (1 or 2 members team) Project-2可选(总评加分1~5分,但不超过平时成绩范围) Finial Exam期末闭卷考试 - 70% 上课说明此门课程的成绩合成:平时成绩包括平时小测验、期中考试、作业、出勤、课堂讨论、论文

授课时间和地点: 2017年春夏学期, 地点:紫金港西2-309(多) 周三上午,第1~2节(8:00-9:35) 星期五上午,第1~2节(8:00-9:35) 地点:紫金港西2-309(多) http://mypage.zju.edu.cn/wdwd/教学工作/ 学在浙里/数字系统设计2018

课程简介 课程代码:111C0120 参考书 阎石, 数字电子技术基础, 第6版, 高等教育出版社, 2016. EE141 课程简介 课程代码:111C0120 参考书 阎石, 数字电子技术基础, 第6版, 高等教育出版社, 2016. 王金明著,数字系统设计与Verilog HDL,电子工业出版社,第6版 补充讲义/期中考试前预备 Stanford 大学 108A课程notes. R.H.Katz, G.Borriello, Contemporary Logic Design, second edition,电子工业出版社, 2005. M.M.Mano, 数字设计(第四版), 电子工业出版社, 2010. http://www.prenhall.com/mano Spring 2018 – Lec. #5

课程结构 数字理论知识(必备) 数字电路分析与设计 脉冲电路与接口 控制器与数字系统 微处理器简介与设计 数字系统和编码、逻辑代数、门电路 EE141 课程结构 数字理论知识(必备) 数字系统和编码、逻辑代数、门电路 数字电路分析与设计 组合逻辑电路 触发器、半导体存贮器、可编程器件 时序逻辑电路 脉冲电路与接口 控制器与数字系统 状态机 控制器 微码控制器 测试和验证 微处理器简介与设计 指令集 简单CPU设计 Spring 2018 – Lec. #5

EE141 4.6 可编程逻辑器件 Today, programmable logic devices, which contain the circuitry necessary to create logic functions, are being used to implement digital systems. Why have PLDs taken over so much of the market? With programmable devices, the same functionality can be obtained with one IC rather than using several individual logic chips. This characteristic means less board space, less power required, greater reliability, less inventory, and overall lower cost in manufacturing. Spring 2018 – Lec. #5

DIGITAL SYSTEMS FAMILY TREE Spring 2018 – Lec. #5

4.6可编程逻辑器件 (PLD, Programmable Logic Device) EE141 4.6可编程逻辑器件 (PLD, Programmable Logic Device) 4.6.1 概述 一、PLD的基本特点 1. 数字集成电路从功能上有分为通用型、专用型两大类 2. PLD的特点:是一种按通用器件来生产,但逻辑功能是由用户通过对器件编程来设定的 数字 系统 Spring 2018 – Lec. #5

Programmable Logic Regular logic Field Programmable Gate Arrays EE141 Programmable Logic Regular logic Programmable Logic Arrays Multiplexers/Decoders ROMs Field Programmable Gate Arrays Xilinx Vertex “Random Logic” Full Custom Design “Regular Logic” Structured Design Spring 2018 – Lec. #5

二、PLD的发展和分类 PROM是最早的PLD PAL 可编程逻辑阵列 FPLA 现场可编程阵列逻辑 GAL 通用阵列逻辑 EE141 二、PLD的发展和分类 PROM是最早的PLD PAL 可编程逻辑阵列 FPLA 现场可编程阵列逻辑 GAL 通用阵列逻辑 EPLD 可擦除的可编程逻辑器件 FPGA 现场可编程门阵列 ISP-PLD 在系统可编程的PLD Spring 2018 – Lec. #5

EE141 三、LSI中用的逻辑图符号 Spring 2018 – Lec. #5

4.6.2 现场可编程逻辑阵列 FPLA Field Programmable Logic Array EE141 4.6.2 现场可编程逻辑阵列 FPLA Field Programmable Logic Array 组合电路和时序电路结构的通用形式1970s 逻辑函数与或表达式 与逻辑+或逻辑 最小项之和 部分最小项 与EPROM很相似 时序型FPLA A0~An-1 W0 W(2n-1) D0 Dm Although the FPLA is more flexible than the PAL architecture, it has not been as widely accepted by engineers. FPLAs are used mostly in state-machine design where a large number of product terms are needed in each SOP expression. Spring 2018 – Lec. #5

EE141 4.6.2 FPLA结构 组合电路和时序电路结构的通用形式 Spring 2018 – Lec. #5

4.6.5 可擦除的可编程逻辑阵列EPLD 一、结构特点 相当于 “与-或”阵列(PAL) + OLMC 二、采用EPROM工艺 集成度提高 EE141 4.6.5 可擦除的可编程逻辑阵列EPLD 一、结构特点 相当于 “与-或”阵列(PAL) + OLMC 二、采用EPROM工艺 集成度提高 高密度 复杂的可编程逻辑阵列CPLD Spring 2018 – Lec. #5

Simplified version of FPGA internal architecture EE141 4.6.7 现场可编程门阵列FPGA Basic idea: two-dimensional array of logic blocks and flip-flops with a means for the user to configure: 1. the interconnection between the logic blocks, 2. the function of each block. 一、基本结构 1. IOB输入输出 2. CLB逻辑 3. 互连资源IR 4. SRAM编程数据 Simplified version of FPGA internal architecture Spring 2018 – Lec. #5

EE141 Why FPGAs? By the early 1980’s most of the logic circuits in typical systems where absorbed by a handful of standard large scale integrated circuits (LSI). Microprocessors, bus/IO controllers, system timers, ... Every system still had the need for random “glue logic” to help connect the large ICs: generating global control signals (for resets etc.) data formatting (serial to parallel, multiplexing, etc.) Systems had a few LSI components and lots of small low density SSI (small scale IC) and MSI (medium scale IC) components. Spring 2018 – Lec. #5

Field-Programmable Gate Arrays PLAs: 100s of gate equivalents FPGAs: 1000-10000s gates  upto 10,000,000gates Logic blocks Implement combinational and sequential logic Interconnect Wires to connect inputs and outputs to logic blocks I/O blocks Special logic blocks at periphery of device for external connections Key questions: How to make logic blocks programmable? How to connect the wires? After the chip has been fabbed Spring 2018 – Lec. #5

4.6.8 编程数据的装载 数据可先放在EPROM或PC机中 EE141 4.6.8 编程数据的装载 数据可先放在EPROM或PC机中 通电后,自行启动FPGA内部的一个时序控制逻辑电路,将在EPROM中存放的数据读入FPGA的SRAM中 “装载”结束后,进入编程设定的工作状态 !!每次停电后,SRAM中数据消失 下次工作仍需重新装载 Spring 2018 – Lec. #5

FPGA architecture Spring 2018 – Lec. #5

4.6.9 PLD的编程 以上各种PLD均需离线进行编程操作,使用开发系统 一、开发系统 硬件:计算机+编程器 软件:开发环境(软件平台) EE141 4.6.9 PLD的编程 以上各种PLD均需离线进行编程操作,使用开发系统 一、开发系统 硬件:计算机+编程器 软件:开发环境(软件平台) VHDL, Verilog 真值表,方程式,电路逻辑图(Schematic) 状态转换图( FSM) Spring 2018 – Lec. #5

抽象(系统设计采用Top-Down的设计方法) 选定PLD 选定开发系统 编写源程序(或输入文件) 调试,运行仿真,产生下载文件 下载 测试 EE141 二、步骤 抽象(系统设计采用Top-Down的设计方法) 选定PLD 选定开发系统 编写源程序(或输入文件) 调试,运行仿真,产生下载文件 下载 测试 Spring 2018 – Lec. #5

FPGA Generic Design Flow EE141 FPGA Generic Design Flow Design Entry: Create your design files using: schematic editor or hardware description language (Verilog, VHDL) Design “implementation” on FPGA: Partition, place, and route to create bit-stream file Design verification: Use Simulator to check function, other software determines max clock frequency. Load onto FPGA device (cable connects PC to development board) check operation at full speed in real environment. Spring 2018 – Lec. #5

JTAG interface between PC parallel port and EPM7128SLC84 programmer Spring 2018 – Lec. #5

4.7 硬件描述语言Verilog DHL简介 ---@组合电路设计 EE141 4.7 硬件描述语言Verilog DHL简介 ---@组合电路设计

EE141 概述 一、什么是Verilog HDL? Verilog HDL是一种应用广泛的硬件描述性语言,主要用于从算法级、门级到开关级的多种抽象层次的数字系统建模。 二、为什么要用Verilog HDL? 电子设计规模越来越大(普通设计已达几百万门的数量级) ,复杂度越来越高。有必要用高级语言来表达其功能,隐藏其具体的细节实现。 提高逻辑设计的效率,降低设计成本,更重要的是缩短设计同期。 可读性强,易修改。 Spring 2018 – Lec. #5

Verilog HDL的基本结构: module adder8 (cout, sum, ina,inb, cin); EE141 Verilog HDL的基本结构: 简单的Verilog HDL的例子 准备实现的逻辑功能: 例1 一个8位加法器的Verilog HDL源代码 输入、输出端口描述 module adder8 (cout, sum, ina,inb, cin); output[7:0] sum; output cout; input[7:0] ina,inb; input cin; assign {cout,sum}=ina+inb+cin; endmodule ∑ 8 ci co cin cout ina inb sum 程序为模块结构,包含在module与endmodule间 逻辑功能描述 问题:若要设计16位加法器,怎样修改? Spring 2018 – Lec. #5

module counter8 (out, cout, data, load, cin, clk); output [7:0] out; EE141 例2 8位二进制加法计数器 module counter8 (out, cout, data, load, cin, clk); output [7:0] out; output cout; input load, cin, clk; input [7:0] data; reg [7:0] out; always @(posedge clk) begin if (load) out<= data;//置数 else out <= out + cin; //计数或保持 end assign cout=&out&cin; // 进位 endmodule 准备实现的 逻辑功能: 输入、输出端口描述 CTR8 M1 M2 G3 C4/2,3+ 8 3CT=255 1,4D load cin clk data out cout 逻辑功能描述 时钟上沿触发 Spring 2018 – Lec. #5

Verilog HDL模块的结构 2.模块的结构 1.模块的概念 module <模块名>(<端口列表>) EE141 Verilog HDL模块的结构 2.模块的结构 1.模块的概念 module <模块名>(<端口列表>) 模块是Verilog HDL语言的基本单元,数字系统是用模块集合的形式来描述。 端口说明(input,output,inout) 参数定义(可选) 模块是描述某个设计的功能、结构和与其它模块通信的外部端口。 数据类型定义 //wire,reg,task,function 连续赋值语句(assign)//组合逻辑 过程块(always和initial) -行为描述语句 Verilog HDL中各个模块是并行运行。 模块可以调用其它模块的实例。 低层模块实例 //调用其它模块 任务和函数 延时说明块 endmodule Spring 2018 – Lec. #5

语句的顺序执行与并行执行 一、assign语句之间:并行执行(同时执行) 二、过程块之间( always, initial ):并行执行 EE141 语句的顺序执行与并行执行 一、assign语句之间:并行执行(同时执行) 二、过程块之间( always, initial ):并行执行 三、 assign语句与过程块之间:并行执行 四、 过程块( always, initial )内部 非阻塞语句类似并行语句 串行块(begin-end):顺序执行 并行块(fork-join ):并行执行 Spring 2018 – Lec. #5

6) 位运算符(~,|,^,&,^~) 1) ~ //取反 2) & //按位与 3) | //按位或 4) ^ //按位异或 1) ~ //取反 2) & //按位与 3) | //按位或 4) ^ //按位异或 5) ^~ //按位同或(异或非) 说明: • 位运算符中除了~是单目运算符以外,均为二目运算符,即要求运算符两侧各有一个操作数. • 位运算符中的二目运算符要求对两个操作数的相应位进行运算操作。 Spring 2018 – Lec. #5

位拼接运算符(Concatation) 在Verilog HDL语言有一个特殊的运算符:位拼接运算符{}。用这个运算符可以把两个或多个信号的某些位拼接起来进行运算操作。 其使用方法如下: {信号1的某几位,信号2的某几位,..,..,信号n的某几位} 即把某些信号的某些位详细地列出来,中间用逗号分开,最后用大括号括起来表示一个整体信号。见下例: {a,b[3:0],w,3’b101} 也可以写成为 {a,b[3],b[2],b[1],b[0],w,1’b1,1’b0,1’b1} 在位拼接表达式中不允许存在没有指明位数的信号。 位拼接还可以用重复法来简化表达式。见下例: {4{w}} //这等同于{w,w,w,w} 位拼接还可以用嵌套的方式来表达。见下例: {b,{3{a,b}}} //这等同于{b,a,b,a,b,a,b} Spring 2018 – Lec. #5

缩减运算符(reduction operator) 缩减运算符是单目运算符,也有与或非运算。 例如: reg [3:0] B; reg C; C = &B; 相当于: C =( (B[0]&B[1]) & B[2] ) & B[3]; (1).非阻塞(Non_Blocking)赋值方式( 如 b <= a; ) 1) 块结束后才完成赋值操作。 2) b的值并不是立刻就改变的。 3) 这是一种比较常用的赋值方法。(特别在编写可综合模块时) (2).阻塞(Blocking)赋值方式( 如 b = a; ) 1) 赋值语句执行完后,块才结束。 2) b的值在赋值语句执行完后立刻就改变的。 3) 可能会产生意想不到的结果。 非阻塞赋值方式和阻塞赋值方式的区别常给设计人员带来问题。 Spring 2018 – Lec. #5

常用组合电路的设计 & A B C D F G1 G2 G3 1.基本门电路的描述 方法1:调用门原语 EE141 常用组合电路的设计 1.基本门电路的描述 方法1:调用门原语 & ≥1 A B C D F F1 F2 G1 G2 G3 module gate1(F, A, B, C, D); input A, B, C, D; output F; wire F1,F2; nand G1 ( F1, A, B ); and G2 ( F2, B, C, D); or G3 ( F, F1, F2); endmodule 调用格式: 多输入门:原语名 < 例化名称> (输出,输入1,输入2……) 非门: 原语名 < 例化名称> (输出,输入) Spring 2018 – Lec. #5

方法2:用assign连续赋值语句描述 & A B C D F 方法3:用过程赋值语句描述 module gate2(F,A,B,C,D); EE141 方法2:用assign连续赋值语句描述 module gate2(F,A,B,C,D); input A,B,C,D; output F; assign F=~(A & B)|(B & C & D); endmodule & ≥1 A B C D F F1 F2 逻辑表达式 方法3:用过程赋值语句描述 module gate3(F,A,B,C,D); input A,B,C,D; output F; reg F; always @(A or B or C or D) begin F=~(A & B) | (B & C & D); end endmodule 敏感信号表: 与同步时序电路差别? Spring 2018 – Lec. #5

三态门 b1 in out oe Bufif1原语: in out en 例 用bufifl关键字描述的三态门 EN EE141 EN out in oe b1 三态门 例 用bufifl关键字描述的三态门 module tristate(in, oe, out); input in, oe; output out; tri out; //注意三态门端口的排列顺序 bufif1 b1(out, in, oe);//(输入,输出,使能) endmodule EN Bufif1原语: 例 用assign描述的三态门 module tri_1(out, in, en); output out; input in, en; assign out = en ? in : 1'bz; //若en = 1, out = in;若en = 0 ,out为高阻态 endmodule EN out in en Spring 2018 – Lec. #5

例 用三态双向驱动器 双向端口 module bidir(tri_inout , out , in , en , b); EE141 例 用三态双向驱动器 双向端口 module bidir(tri_inout , out , in , en , b); inout tri_inout; output out; input in, en, b; assign tri_inout = en ? in : 1'bz;//三态门 assign out = tri_inout ^ b; endmodule EN in en =1 tri_inout out b Spring 2018 – Lec. #5

译码器、编码器 3线_8线译码器(输出低电平有效) out0 out7 1 2 in0 in1 in2 BIN/OCT 01234567 EE141 译码器、编码器 3线_8线译码器(输出低电平有效) module edcoder_38(out, in); output[7:0] out; input[2:0] in; reg[7:0] out; always @(in) begin case(in) 3'd0: out = 8'b1111_1110; 3'd1: out = 8'b1111_1101; 3'd2: out = 8'b1111_1011; 3'd3: out = 8'b1111_0111; 3'd4: out = 8'b1110_1111; 3'd5: out = 8'b1101_1111; 3'd6: out = 8'b1011_1111; 3'd7: out = 8'b0111_1111; endcase end endmodule 01234567 out0 out7 BIN/OCT 1 2 in0 in1 in2 分隔符,便于阅读 真值表 Spring 2018 – Lec. #5

8 线_ 3线高优先编码器 方法1:用if_else语句描述编码器 outcode1 outcode2 1 2 outcode0 EE141 8 线_ 3线高优先编码器 方法1:用if_else语句描述编码器 module encoder8_3(none_on,outcode,a, b, c, d, e, f, g, h); output[2:0] outcode; output none_on; input a, b, c, d, e, f, g, h; reg[3:0] outtemp; assign {none_on, outcode} = outtemp; always @(a or b or c or d or e or f or g or h) begin if(h) outtemp = 4'b0_111; else if(g) outtemp = 4'b0_110; else if(f ) outtemp = 4'b0_101; else if(e) outtemp = 4'b0_100; else if(d) outtemp = 4'b0_011; else if(c) outtemp = 4'b0_010; else if(b) outtemp = 4'b0_001; else if(a) outtemp = 4'b0_000; else outtemp = 4'b1_000; end endmodule 引进变量,便于描述 01234567 BIN/OCT outcode1 outcode2 abcdefgh 1 2 outcode0 none_on (输入无效) Spring 2018 – Lec. #5

方法2:用case语句描述编码器 outcode1 outcode2 1 2 outcode0 none_on BIN/OCT EE141 方法2:用case语句描述编码器 module encoder_83(none_on,outcode,a, b, c, d, e, f, g, h); output[2:0] outcode; output none_on; input a, b, c, d, e, f, g, h; reg[3:0] outtemp; assign {none_on, outcode} = outtemp; always @(a or b or c or d or e or f or g or h) begin casex ({a, b, c, d, e, f, g, h}) 8'B????_???1 : outtemp=4'b0_111; 8'B????_??10 : outtemp=4'b0_110; 8'B????_?100 : outtemp=4'b0_101; 8'B????_1000 : outtemp=4'b0_100; 8'B???1_0000 : outtemp=4'b0_011; 8'B??10_0000 : outtemp=4'b0_010; 8'B?100_0000 : outtemp=4'b0_001; 8'B1000_0000 : outtemp=4'b0_000; 8'B0000_0000 : outtemp=4'b1_000; endcase end endmodule 01234567 BIN/OCT outcode1 outcode2 abcdefgh 1 2 outcode0 none_on (输入无效) Spring 2018 – Lec. #5

数据选择器MUX 用assign语句设计2选1 MUX module mux2_1(out , a , b , sel); EE141 数据选择器MUX 用assign语句设计2选1 MUX module mux2_1(out , a , b , sel); output out; input a, b, sel; assign out = sel ? a : b; endmodule mux sel 1 b a out sel=1:out=a sel=0:out=b Spring 2018 – Lec. #5

用if-else语句描述4选1 MUX mux sel0 G sel1 in0 8 in1 in2 out in3 EE141 用if-else语句描述4选1 MUX module mux4_1(out , in0 , in1 , in2 , in3 , sel); output out ; input[7:0] in0 , in1 , in2 , in3 ; input[1:0] sel; reg[7:0] out ; always @(in0 or in1 or in2 or in3 or sel) begin if(sel== 2'b00) out = in0; else if(sel == 2'b01) out = in1; else if(sel == 2'b10) out = in2; else out = in3; end endmodule mux 1 out G 3 sel0 8 sel1 2 in0 in1 in2 in3 Spring 2018 – Lec. #5

用case语句描述4选1 MUX 共有8个4选1 MUX, mux sel0 G sel1 in0 8 in1 in2 out in3 EE141 用case语句描述4选1 MUX module mux_4_1(out , in0 , in1 , in2 , in3 , sel); output[7:0] out ; input[7:0] in0 , in1 , in2 , in3 ; input[1:0] sel; reg[7:0] out ; always @(in0 or in1 or in2 or in3 or sel) begin case(sel) 2'b00: out = in0; 2'b01: out = in1; 2'b10: out = in2; default: out = in3; endcase end endmodule 共有8个4选1 MUX, 它们共用sel信号 mux 1 out G 3 sel0 8 sel1 2 in0 in1 in2 in3 Spring 2018 – Lec. #5

奇偶校验器 奇校验:输入数据“1”的个数为奇数。可用“异或”运算 偶校验:输入数据“1”的个数为偶数。可用“同或”运算 EE141 奇偶校验器 奇校验:输入数据“1”的个数为奇数。可用“异或”运算 偶校验:输入数据“1”的个数为偶数。可用“同或”运算 module parity(even_bit ,odd_bit , input_bus); output even_bit ,odd_bit ; input [7:0] input_bus; assign odd_bit = ^ input_bus; //产生奇校验位 assign even_bit = ~odd_bit; //产生偶校验位 endmodule Spring 2018 – Lec. #5

BCD码-七段 译码器(共阴) a e c d b f g bcd/7seg 1 2 4 8 D0 D1 D2 D3 EE141 BCD码-七段 译码器(共阴) module decode4_7(a,b,c,d,e,f,g,D); output a,b,c,d,e,f,g; input[3:0] D; reg a,b,c,d,e,f,g; always @(D) begin case(D) 4'd0 : {a,b,c,d,e,f,g}=7'b1111110; 4'd1 : {a,b,c,d,e,f,g}=7'b0110000; 4'd2 : {a,b,c,d,e,f,g}=7'b1101101; 4'd3 : {a,b,c,d,e,f,g}=7'b1111001; 4'd4 : {a,b,c,d,e,f,g}=7'b0110011; 4'd5 : {a,b,c,d,e,f,g}=7'b1011011; 4'd6 : {a,b,c,d,e,f,g}=7'b1011111; 4'd7 : {a,b,c,d,e,f,g}=7'b1110000; 4'd8 : {a,b,c,d,e,f,g}=7'b1111111; 4'd9 : {a,b,c,d,e,f,g}=7'b1111011; default : {a,b,c,d,e,f,g}=7'bx; endcase end endmodule a e c d b f g bcd/7seg 1 2 4 8 D0 D1 D2 D3 Spring 2018 – Lec. #5

运算电路 例:带进位的n位通用加法器 逻辑图 n ∑ ina sum inb cout co ci cin EE141 运算电路 例:带进位的n位通用加法器 module adder_n (cout, sum, ina,inb, cin); parameter n=16; output[n:1] sum; output cout; input[n:1] ina,inb; input cin; assign {cout,sum}=ina+inb+cin; endmodule 逻辑图 ∑ n ci co cin cout ina inb sum Spring 2018 – Lec. #5

比较器 comp n ina inb P Q great equa Small EE141 比较器 module compare_n (great, equal, Small, ina, inb); parameter n=16; output great, equal, Small; input[n:1] ina,inb; assign great=(ina>inb); assign equal=(ina==inb); assign Small=(ina<inb); endmodule comp n ina inb P Q P>Q P=Q P<Q great equa Small Spring 2018 – Lec. #5

课后作业 练习: 作业: 阅读: 见/学在浙里; Verilog参考书的实例 编译工具 modelsim、MAXplus等 EE141 课后作业 练习: 编译工具 modelsim、MAXplus等 作业: 见/学在浙里; 阅读: Verilog参考书的实例 Spring 2018 – Lec. #5