当前位置:文档之家› 多路选择器(MUX)功能实现Verilog HDL源代码

多路选择器(MUX)功能实现Verilog HDL源代码

多路选择器(MUX)功能实现Verilog HDL源代码

多路选择器(MUX)功能实现Verilog HDL源代码

电子发烧友网核心提示:本例程是Verilog HDL源代码:关于基本组合逻辑功能中多路选择器(MUX)的功能实现源代码。注意:程序运行在不同软件平台可能要作一些修改,请注意阅读程序中的注释。

?

?

?

?//-----------------------------------------------------------------------------------

?

?// DESCRIPTION : MulTIplexer

?

?// Code style: used case statement

?

?// Width of output terminal: 8

?

?// Number of terminals: 4

?

?// Output enable acTIve: HIGH

?

?// Output value of all bits when enable not acTIve: 0

?

?//-----------------------------------------------------------------------------------

?

VerilogHDL经典程序非常适合新手

一、2线-4线译码器 module counter4(q1,q0,ncr,cp); input cp,ncr; output q1,q0; reg q1,q0; always@(posedge cp or negedge ncr) begin if(~ncr){q1,q0}<=2'b00; else{q1,q0}<={q1,q0}+1'b1; end endmodule 二、4选1数据选择器 module selector4_1(i0,i1,i2,i3,a1,a0,y); input i0,i1,i2,i3,a1,a0; output y; reg y; always@(a1or a0) begin case({a1,a0}) 2'b00:y=i0; 2'b01:y=i1; 2'b10:y=i2; 2'b11:y=i3; default:y=0; 一、2线-4线译码器 module counter4(q1,q0,ncr,cp); input cp,ncr; output q1,q0; reg q1,q0; always@(posedge cp or negedge ncr) begin if(~ncr){q1,q0}<=2'b00; else{q1,q0}<={q1,q0}+1'b1; end endmodule 二、4选1数据选择器 module selector4_1(i0,i1,i2,i3,a1,a0,y); input i0,i1,i2,i3,a1,a0; output y; reg y; always@(a1or a0) begin case({a1,a0}) 2'b00:y=i0;

Director 疑难解答

Director 疑难解答 01. 如何制作一个放映机(projector)可以在不同分辨率下播放? [A] 加入下列语句: on prepareMovie (the stage).rect = (the desktopRectList)[1] (the stage).drawRect = (the desktopRectList)[1] end 注意,这个语句是通过放大或缩小舞台来达到效果的,所以会有变形。 02. 如何导入photoshop的图层? [A] Director7.0以后的版本你可以通过Medialab公司的Photocaster Xtra来实现。 03. 在程序中如何导入图片而不失去图片周围的白色部份? [A] 通过指定图片的trim whitespace属性可以实现: m = new(#bitmap) m.trimWhiteSpace = 0 m.filename = the moviePath & ‘‘file.bmp‘‘ m.media = m.media 04. 如何得到全局变量列表? [A] 在messages的窗口中,你可以输入showGlobals来显示所有的全局变量。以下的代码也可以显示所有的全局变量: repeat with x = 1 to (the globals).count put (the globals).getPropAt(x) & ‘‘= ‘‘& (the globals)[x] end repeat 05. 如何播放mpeg文件? [A] 有一系列的方法,不能说哪一种更好,并且在pc机和mac机上是不一样的,下面是四种常见的方法: 1. 用一个xtra。这种方法用起来简单,且也有好的产品支持,但大多不能跨平台使用。当然,这是需要购买的。 2. 使用ActiveX控件。这只能在pc机上用,相对xtra而言会有更多的限制,但它是免费的,且与标准playback能够很好的集成。

Verilog编码风格

Verilog编码风格 嵌入式开发2010-05-03 15:28:13 阅读14 评论0 字号:大中小订阅 这是以前公司的对fpga代码编写的要求 良好代码编写风格的通则概括如下: (1)对所有的信号名、变量名和端口名都用小写,这样做是为了和业界的习惯保持一致;对常量名和用户定义的类型用大写; (2)使用有意义的信号名、端口名、函数名和参数名; (3)信号名长度不要太长; (4)对于时钟信号使用clk 作为信号名,如果设计中存在多个时钟,使用clk 作为时钟信号的前缀; (5)对来自同一驱动源的信号在不同的子模块中采用相同的名字,这要求在芯片总体设计时就定义好顶层子模块间连线的名字,端口和连接端口的信号尽可能采用相同的名字; (6)对于低电平有效的信号,应该以一个下划线跟一个小写字母b 或n 表示。注意在同一个设计中要使用同一个小写字母表示低电平有效; (7)对于复位信号使用rst 作为信号名,如果复位信号是低电平有效,建议使用rst_n; (8)当描述多比特总线时,使用一致的定义顺序,对于verilog 建议采用bus_signal[x:0]的表示; (9)尽量遵循业界已经习惯的一些约定。如*_r 表示寄存器输出,*_a 表示异步信号,*_pn 表示多周期路径第n 个周期使用的信号,*_nxt 表示锁存前的信号,*_z 表示三态信号等; (10)在源文件、批处理文件的开始应该包含一个文件头、文件头一般包含的内容如下例所示:文件名,作者,模块的实现功能概述和关键特性描述,文件创建和修改的记录,包括修改时间,修改的内容等; (11)使用适当的注释来解释所有的always 进程、函数、端口定义、信号含义、变量含义或信号组、变量组的意义等。注释应该放在它所注释的代码附近,要求简明扼要,只要足够说明设计意图即可,避免过于复杂; (12)每一行语句独立成行。尽管VHDL 和Verilog 都允许一行可以写多个语句,当时每个语句独立成行可以增加可读性和可维护性。同时保持每行小于或等于72 个字符,这样做都是为了提高代码得可读性; (13)建议采用缩进提高续行和嵌套语句得可读性。缩进一般采用两个空格,如西安交通大学SOC 设计中心 2 如果空格太多则在深层嵌套时限制行长。同时缩进避免使用TAB 键,这样可以避免不同机器TAB 键得设置不同限制代码得可移植能力; (14)在RTL 源码的设计中任何元素包括端口、信号、变量、函数、任务、模块等的命名都不能取Verilog 和VHDL 语言的关键字; (15)在进行模块的端口申明时,每行只申明一个端口,并建议采用以下顺序:

2选1多路选择器 EDA实验报告

EDA实验报告 学生姓名:asfmla;m 学号:eafvpa[cv专业班级:电子3班 组合电路设计 一、实验目的 熟悉quartusⅡ的VHDL文本设计全过程,学习简单组合电路的设计、多层次电路设计、仿真。 二、实验内容 实验内容:首先利用quartusⅡ完成2选1多路选择器(例4-3)的文本编译输入(mux21a.vhd)和仿真测试等步骤,最后在实验系统上硬件测试,验证此设计的功能。将此多路选择器看成一个元件mux21a,利用元件例化语句描述成三选一,然后进行编译、综合、仿真。引脚锁定以及硬件下载测试。建议选实验电路模式5,用键1(PIO0)控制s0;用键2(PIO1)控制s1;a3、a2和a1分别接clock5、clock0和clock2;输出信号outy仍接扬声器spker。通过短路帽选择clock0接256HZ信号,clock5接1024HZ信号,clock2接8HZ信号。最后选行编译、下载和硬件测试实验。 三、实验器材 Quartus II软件。 四、设计思路/原理图 五、实验程序 实验内容1:二选一: library ieee; use ieee.std_logic_1164.all; entity mux21a is port(a,b: in std_logic; s: in std_logic; y: out std_logic); end entity; architecture dataflow of mux21a is begin

y<=a when s='0' else b; end architecture; 实验内容2:三选一 library ieee; use ieee.std_logic_1164.all; entity mux31a is port(a1,a2,a3: in std_logic; s0,s1: in std_logic; outy: out std_logic); end entity mux31a; architecture m31a of mux31a is component mux21a port( a,b: in std_logic; s: in std_logic; y: out std_logic); end component; signal tmp: std_logic; begin u1: mux21a port map(a=>a2,b=>a3,s=>s0,y=>tmp); u2: mux21a port map(a=>a1,b=>tmp,s=>s1,y=>outy); end architecture; 六、实验步骤 在E盘新建一个文件夹,用于存放工程。打开quartus,新建工程,然后选择新建VHDL 文件,命名为mux21a。在VHDL编辑窗口中输入实验程序后,进行编译、仿真;在实验一的基础上,新建VHDL文件,命名为mux31a。在VHDL编辑窗口中输入实验程序后,进行编译、综合、仿真;最后进行硬件测试。 七、仿真波形分析 二选一波形: 分析:当s=0时,y=a;当s=1时,y=b。 三选一综合图形及其波形

Director MX 2004使用问答

Director MX 2004使用问答 Q: 为什么用MX2004打包后会显示标题栏? A:把display template中的titlebat options里的选项都取消就可以了。 Q:如何在DR中打开word文件 A:1,在d内打开须使用activex 2,在d外打开调用word程序打开即可 Q:怎样实现让用户选择不同的背景音乐? A:on mouseUp me,7v@ fileobj=new(xtra "fileio")~M+Hhf fileobj.setFilterMask("all file, *.*,mp3,*.mp3,wave, *.wav")i filename=displayOpen(fileobj)^|kHUb if filename="" or filename=void then exitU9 closefile(fileobj) jhI sound playFile 2, string(filename) end Q:请问怎么给mpg视频加遮照? A:1,利用open widndow 做视频遮照 2,用MPEG advance xtra 插件,在属性窗口中把playback opitions 下的DTS取消了,就可以了,然后就在视频之上的通道里放你遮的图片即可 Q:怎么检测本机是否连接到intel网上? A:WinSocket Xtra Ad可以实现,说明: WinSocket Xtra 是一套Sprite Xtra,一共有三个,分别为 TCPServer.X32,TCPClient.X32和UDPSocket.X32。TCPServer.X32是服务器端xtra,TCPClient.X32是客户端xtra,采用Tcp/ip协议。互相配套用于网络信息传递,可以构建类似聊天室,多人连线游戏。UDPSocket.X32采用UDP 协议。独立用于网络信息传递,也可以构建类似聊天室,多人连线游戏。 Q:flash动画导到dr后声音和动画不同步怎么解决? A:使用线索点,最好调好以后把它锁定。 Q:如何检测用户是否安装quicktime,若无就提示安装? A:on exitframe me if quicktimeversion()<5.0 then open the moviepath@"quicktime\fullinstallercn.exe“ halt() else go "start" end if end Q:为什么发布成exe文件后视频不能正常播放? A:1.打包后Xtras文件夹是否在打包文件夹下,是否包含播放视频所需插件 2.视频是否为mpg,如使用DirectMediaXtras,mpg文件是否与exe在同级目录下 Q:如何实现点击打开本地文件夹? A:gotoNetPage("c:\") 不过路径中不要有中文! Q:如何将dr里的flash导出? A:ExportSWF.x32插件。说明: object = xtra("ExportSWF").new()

74LS138Verilog源码

`timescale 1ns / 1ps ////////////////////////////////////////////////////////////////////////////////// // Company: // Engineer: // // Create Date: 2020/02/28 13:40:03 // Design Name: // Module Name: _74ls138 // Project Name: // Target Devices: // Tool Versions: // Description: // // Dependencies: // // Revision: // Revision 0.01 - File Created // Additional Comments: // ////////////////////////////////////////////////////////////////////////////////// module _74ls138(nE1,nE2,E3,B,nY); input nE1,nE2,E3; input [2:0]B; output[7:0]nY; reg[7:0]nY; always@(nE1,nE2,E3,B) if(!nE1 && !nE2 && E3) begin case(B) 3'b000: nY = 8'b1111_1110; 3'b001: nY = 8'b1111_1101; 3'b010: nY = 8'b1111_1011; 3'b011: nY = 8'b1111_0111; 3'b100: nY = 8'b1110_1111; 3'b101: nY = 8'b1101_1111; 3'b110: nY = 8'b1011_1111; 3'b111: nY = 8'b0111_1111; default:nY = 8'b1111_1111; endcase end

EDA技术与应用的二选一选择器

EDA 技术与应用的二选一选择器 学院名称: 东方学院 专 业: 电子信息工程 班 级: 学 号: 姓 名: 指导教师姓名: 指导教师职称: 2007年 4 月24日 JIANGSU TEACHERS UNIVERSITY OF TECHNOLOGY 本科课程设计(论文)

二选一选择器 一.设计目的 1.学习VHDL编程; 2.进一步熟悉实验箱电路; 二.设计指标及功能要求 设计指标: (1)对所设计的小系统功能正确分析; (2)基于VHDL语言描述系统的功能; (3)在QUARTUSⅡ环境中编译通过; (4)仿真通过,并得到正确的波形; (5)给出相应设计报告; 功能要求:1.用VHDL语言设计可控加减计数器; 2.至少两层电路,底层有三种元件; 3.使得其执行可控加,减记数; 三.实验步骤 1.建立Light目录,用于存放本实验所建立的文本 2.点击“File New”,在出现的对话框中,选择“VHDL File”进入文本编辑器。 3.输入VHDL语言源文件。 4.点“Save as”,保存该源文件。 5.进行编译,点“start compilation”,若语句有错会有提示,修改后重新编译直到无错误。

6.点“File New”,选择“Vector Waveform File”,建立仿真输入文件. 7.点“End time”,输入终止时间(表示波形长度).点“light”将所有信号选中或部分选中。点“start simulation”.运行波形,直至正确。 四、电路工作原理 首先,用异或门控制输入端,加一个脉冲信号。在其后方分别加上加法计数器和减法计数器:来一个脉冲,当异或门输出为0时,减法计数器开始工作,当输出为1时,加法计数器工作。这样,利用给异或门加不同的信号来控制加减计数器。 五.各子模块设计与调试过程 library ieee; use ieee.std_logic_1164.all; entity ora is port(a:in std_logic; b:out std_logic); end entity; architecture one of ora is begin b<=not a; end architecture;

Director实例剖析

Director实例剖析:Director的常用Lingo命令和句柄 常用lingo 利用控制director电影的重要方面就是利用控制各个方面的属性,下面列出常用的精灵属性、字段属性、造型成员属性,以及其他的一些常用的命令和句柄。 1.常用精灵属性 blend 语法:the blend of sprite whichsprite 用途:此属性决定了精灵的混合百分比 举例:set the blend of sprite 3 to 40 bottom 语法:the bottom of sprite whichsprite 用途:此属性决定了精灵矩形边框的下部边缘的坐标值,这个属性可以用来测试但是不能直接修改 举例:set lowest =put the botiom ofsprite (i +l) castlibnum 语法:the castlibnum of sprite whichsprite 用途:此属性决定了精灵所使用的造型成员的cast表的编号,可以被测试和修改。如果更改此属性但是不修改castnum属性,director会使用原来的造型成员编号在新的cast表中为精灵寻找造型成员 举例:set the castlibnum of sprite 3 to the number ofcastlib“newcast” constrainh 语法:constrainh(whichsprite,va1ue) 用途:此函数首先计算表达式va1ue的值,然后和精灵的左右矩形边缘坐标进行比较。如果表达式在精灵左右矩形边缘之间,就返回这个表达式;如果这个表达式小于精灵矩形边缘的左边的坐标值,就返回精灵矩形左边边缘的坐标值;如果表达式大于精灵矩形边缘右边的坐标值,就返回精灵矩形右边边缘的坐标值 举例:put constrainh(1,20) --30 put constrainh(1,60) --60 put constrainh(1,100) constrainv 语法:constrainv(whichsprite,va1ue) 用途:和constrainh类似,但是是和精灵矩形边枢的上下边缘进行比较。 举例:set the locv of sprite l to constrainv(3,the mousev) constraint 语法:the constraint of sprite whichsprite

全数字锁相环的verilog源代码讲解

支持论坛发展帖出全数字锁相环的verilog源代码,仿真已通过 module dpll(reset,clk,signal_in,signal_out,syn; parameter para_K=4; parameter para_N=16; input reset; input clk; input signal_in; output signal_out; output syn; reg signal_out; reg dpout; reg delclk; reg addclk; reg add_del_clkout; reg [7:0]up_down_cnt; reg [2:0]cnt8; reg [8:0]cnt_N; reg syn; reg dpout_delay; reg [8:0]cnt_dpout_high; reg [8:0]cnt_dpout_low; /******phase detector*****/ always@(signal_in or signal_out begin dpout<=signal_in^signal_out; end /******synchronization establish detector*****/ always@(posedge clk or negedge reset begin if(!reset dpout_delay<='b0; else dpout_delay<=dpout; end always@(posedge clk or negedge reset begin if(!reset begin cnt_dpout_high<='b0; cnt_dpout_low<='b0; end else if(dpout if(dpout_delay==0 cnt_dpout_high<='b0; else if(cnt_dpout_high==8'b11111111 cnt_dpout_high<='b0; else cnt_dpout_high<=cnt_dpout_high+1; else if(!dpout if(dpout_delay==1 cnt_dpout_low<='b0; else if(cnt_dpout_low==8'b11111111 cnt_dpout_low<='b0; else cnt_dpout_low<=cnt_dpout_low+1; end always@(posedge clk or negedge reset begin if(!reset syn<='b0; else if((dpout&&!dpout_delay||(!dpout&&dpout_delay if(cnt_dpout_high[8:0]-cnt_dpout_low[8:0]<=4||cnt_dpout_low[8:0]- cnt_dpout_high[8:0]<=4 syn<='b1; else syn<='b0; end /****up down couter with mod=K****/ always@(posedge clk or negedge reset begin if(!reset begin delclk<='b0; addclk<='b0; up_down_cnt<='b00000000; end else begin if(!dpout begin delclk<='b0; if(up_down_cnt==para_K-1 begin up_down_cnt<='b00000000; addclk<='b0; end else begin up_down_cnt<=up_down_cnt+1; addclk<='b0; end end else begin addclk<='b0; if(up_down_cnt=='b0 begin up_down_cnt<=para_K-1; delclk<='b0; end else if(up_down_cnt==1 begin delclk<='b1; up_down_cnt<=up_down_cnt-1; end else up_down_cnt<=up_down_cnt-1; end end end /******add and delete clk*****/ always@(posedge clk or negedge reset begin if(!reset begin cnt8<='b000; end else begin if(cnt8=='b111 begin cnt8<='b000; end else if(addclk&&!syn begin cnt8<=cnt8+2; end else if(delclk&&!syn

verilog有限状态机实验报告(附源代码)

有限状态机实验报告 一、实验目的 ●进一步学习时序逻辑电路 ●了解有限状态机的工作原理 ●学会使用“三段式”有限状态机设计电路 ●掌握按键去抖动、信号取边沿等处理技巧 二、实验内容 用三段式有限状态机实现序列检测功能电路 a)按从高位到低位逐位串行输入一个序列,输入用拨动开关实现。 b)每当检测到序列“1101”(不重叠)时,LED指示灯亮,否则灭,例如 i.输入:1 1 0 1 1 0 1 1 0 1 ii.输出:0 0 0 1 0 0 0 0 0 1 c)用八段数码管显示最后输入的四个数,每输入一个数,数码管变化一次 d)按键按下的瞬间将拨动开关状态锁存 i.注意防抖动(按键按下瞬间可能会有多次的电平跳变) 三、实验结果 1.Rst_n为0时数码管显示0000,led灯不亮,rst_n拨为1,可以开始输入,将输 入的开关拨到1,按下按钮,数码管示数变为0001,之后一次类推分别输入1, 0,1,按下按钮后,数码管为1101,LED灯亮,再输入1,LED灯灭,之后再输 入0,1(即共输入1101101使1101重叠,第二次LED灯不亮),之后单独输入

1101,LED灯亮 2.仿真图像 刚启动时使用rst_n 一段时间后 其中Y代表输出,即控制led灯的信号,sel表示数码管的选择信号,seg表示数码管信号 四、实验分析 1、实验基本结构

其中状态机部分使用三段式结构: 2、整体结构为:

建立一下模块: Anti_dither.v 输入按键信号和时钟信号,输出去除抖动的按键信号生成的脉冲信号op 这一模块实现思路是利用按钮按下时会持续10ms以上而上下抖动时接触时间不超过10ms来给向下接触的时间计时,达到上限时间才产生输出。 Num.v 输入op和序列输入信号A,时钟信号clk和复位信号,复位信号将num置零,否则若收到脉冲信号则将num左移一位并将输入存进最后一位。输出的num即为即将在数码管上显示的值 Scan.v 输入时钟信号,对其降频以产生1ms一次的扫描信号。 Trigger.v 这一模块即为状态机模块,按三段式书写。 整个模块的输入为时钟信号,脉冲信号,序列输入变量,复位信号,输出LED灯控制信号Y。 第一段是状态转换模块,为时序逻辑电路,功能是描述次态寄存器迁移到现态寄存器。即如果收到复位信号将现态置零,否则将上次得到的next_state赋给current_state。

ChartDirector常见用法(示例代码)

ChartDirector 常见用法(示例代码) 最近在尝试在ChartDirector 里进行坐标的设置,想在这里写写最近最近的学习成果。 下面是我的代码实例,里面就是实现如何在ChartDirector 里进行坐标的设置,代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 public void createChart(ChartViewer viewer, int index) { // 这是两组数据,X 和Y 会一一对应生成;多在多纵轴图中使用,横坐标点会自动调整。 double[] dataY0 = { 4.5, 5}; Date[] dataX0 = { new GregorianCalendar(1999, 1, 1).getTime(), new GregorianCalendar(2000, 8, 6).getTime() }; double[] dataY1 = {7, 6.5, 6, 5, 6.5, 7, 6, 5.5, 5,9,8,7,8}; Date[] dataX1 = {new GregorianCalendar(1999, 1, 1).getTime(), new GregorianCalendar(1999, 6, 1).getTime(), new GregorianCalendar(1999, 11, 1).getTime(), new GregorianCalendar(1999, 11, 15).getTime(), new GregorianCalendar(1999, 12, 9).getTime(), new GregorianCalendar(2000, 2, 3).getTime(), new GregorianCalendar(2000, 7, 13).getTime(), new GregorianCalendar(2001, 4, 5).getTime(), new GregorianCalendar(2001, 8, 16).getTime(), new GregorianCalendar(2001, 10, 16).getTime(),new GregorianCalendar(2001, 12, 16).getTime(),new GregorianCalendar(2002, 2, 16).getTime(),new GregorianCalendar(2002, 4, 16).getTime()}; //这是单独的横坐标数据,横坐标会根据数据进行调整,Y 轴会按照顺利一一对应。 Date[] dataX2 = { new GregorianCalendar(1999, 1, 1).getTime(), new

Verilog的135个经典设计实例

【例3.1】4位全加器 module adder4(cout,sum,ina,inb,cin); output[3:0] sum; output cout; input[3:0] ina,inb; input cin; assign {cout,sum}=ina+inb+cin; endmodule 【例3.2】4位计数器 module count4(out,reset,clk); output[3:0] out; input reset,clk; reg[3:0] out; always @(posedge clk) begin if (reset) out<=0; //同步复位 else out<=out+1; //计数 end endmodule 【例3.3】4位全加器的仿真程序 `timescale 1ns/1ns `include "adder4.v" module adder_tp; //测试模块的名字 reg[3:0] a,b; //测试输入信号定义为reg型 reg cin; wire[3:0] sum; //测试输出信号定义为wire型 wire cout; integer i,j; adder4 adder(sum,cout,a,b,cin); //调用测试对象 always #5 cin=~cin; //设定cin的取值 initial begin a=0;b=0;cin=0; for(i=1;i<16;i=i+1) #10 a=i; //设定a的取值 end - 1 -

initial begin for(j=1;j<16;j=j+1) #10 b=j; //设定b的取值 end initial//定义结果显示格式 begin $monitor($time,,,"%d + %d + %b={%b,%d}",a,b,cin,cout,sum); #160 $finish; end endmodule 【例3.4】4位计数器的仿真程序 `timescale 1ns/1ns `include "count4.v" module coun4_tp; reg clk,reset; //测试输入信号定义为reg型 wire[3:0] out; //测试输出信号定义为wire型 parameter DELY=100; count4 mycount(out,reset,clk); //调用测试对象 always #(DELY/2) clk = ~clk; //产生时钟波形 initial begin//激励信号定义 clk =0; reset=0; #DELY reset=1; #DELY reset=0; #(DELY*20) $finish; end //定义结果显示格式 initial $monitor($time,,,"clk=%d reset=%d out=%d", clk, reset,out); endmodule 【例3.5】“与-或-非”门电路 module AOI(A,B,C,D,F); //模块名为AOI(端口列表A,B,C,D,F) input A,B,C,D; //模块的输入端口为A,B,C,D output F; //模块的输出端口为F - 2 -

第10章例题verilog源代码(夏宇闻版)

第十章例题 module add_4( X, Y, sum, C); input [3 : 0] X, Y; output [3: 0] sum; output C; assign {C, Sum } = X + Y; endmodule //而16位加法器只需要扩大位数即可,见下例: module add_16( X, Y, sum, C); input [15 : 0] X, Y; output [15 : 0] sum; output C; assign {C, Sum } = X + Y; endmodule 快速乘法器常采用网格形式的迭带阵列结构,图10.3示出两个四位二进制数相乘的结构图,//用Verilog HDL来描述乘法器是相当容易的,只需要把运算表达式写出就可以了,见下例。module mult_4( X, Y, Product); input [3 : 0] X, Y; output [7 : 0] Product; assign Product = X * Y; endmodule // 而8位乘法器只需要扩大位数即可,见下例: module mult_8( X, Y, Product); input [7 : 0] X, Y; output [15 : 0] Product; assign Product = X * Y; endmodule

// 下面就是一个位数可以由用户定义的比较电路模块: module compare_n ( X, Y, XGY, XSY, XEY); input [width-1:0] X, Y; output XGY, XSY, XEY; reg XGY, XSY, XEY; parameter width = 8; always @ ( X or Y ) // 每当X 或Y 变化时 begin if ( X = = Y ) XEY = 1; // 设置X 等于Y的信号为1 else XEY = 0; if (X > Y) XGY = 1; // 设置X 大于Y的信号为1 else XGY = 0; if (X < Y) XSY = 1; // 设置X 小于Y的信号为1 else XSY = 0; end endmodule //下面就是带使能控制信号(nCS)的数据位宽可以由用户定义的(8位)八路数据通道选择器模块: module Mux_8( addr,in1, in2, in3, in4, in5, in6, in7, in8, Mout, nCS); input [2:0] addr; input [width-1:0] in1, in2, in3, in4, in5, in6, in7, in8; input nCS; output [width-1:0] Mout; parameter width = 8; always @ (addr or in1 or in2 or in3 or in4 or in5 or in6 or in7 or in8 or nCS) begin if (!nCS) //nCS 低电平使多路选择器工作 case(addr) 3’b000: Mout = in1; 3’b001: Mout = in2; 3’b010: Mout = in3; 3’b011: Mout = in4;

director 快捷键

1、F i l e菜单快捷键 命令快捷键 New Movie(新影片)Ctrl+N NewCast(新演员表)Ctrl+Alt+N Open(打开)Ctrl+O Close(关闭)Ctrl+F4 Save(保存)Ctrl+S Import(输入)Ctrl+R Export(输出)Ctrl+Shift+R Preview inBrowser(在浏览器中预览)F12 Page Setup(页面设置)Ctrl+Shift+P Print(打印)Ctrl+P General Preferences(基本参数设置)Ctrl+U Exit/Quit(退出)Alt+F4 2、Edit菜单快捷键 命令快捷键 Undo(撤消)Ctrl+Z Repeat(重复)Ctrl+Y Cut(剪切)Ctrl+X 命令快捷键 Copy(拷贝)Ctrl+C Paste(粘贴)Ctrl+V Clear(清除)Backspace Duplicate(复制)Ctrl+D Select All(全选)Ctrl+A Find Text(查找文本)Ctrl+F Find Handler(查找处理程序)Ctrl+Shift+; Find Cast Member(查找演员)Ctrl+; Find Selection(查找选区)Ctrl+H Find Again(再查找)Ctrl+Alt+F Replace Again(再替换)Ctrl+Alt+E Edit Sprite Frames(编辑角色的帧)Ctrl+Alt+] Edit Entire Sprite(编辑整个角色)Ctrl+Alt+[ Exchange Cast Members(交换演员)Ctrl+E Launch External Editor(运行外部编辑器)Ctrl+,(逗号) 3、View菜单快捷键 命令快捷键 Next Marker(下一个标志)Ctrl+右箭头键 Previous Marker(前一个标志)Ctrl+左箭头键 Zoom In(变焦放大)Ctrl++ Zoom Out(变焦缩小)Ctrl+-(连字符) Show Grid(显示网格)Ctrl+Shift+Alt+G Snap to Grid(吸附于网格)Ctrl+Alt+G Show Rulers(显示标尺)Ctrl+Shift+Alt+R

基于FPGA的SDRAM实验Verilog源代码

// megafunction wizard: %ALTPLL% // GENERATION: STANDARD // VERSION: WM1.0 // MODULE: altpll // ============================================================ // File Name: clk_ctrl.v // Megafunction Name(s): // altpll // // Simulation Library Files(s): // altera_mf // ============================================================ // ************************************************************ // THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE! // // 11.0 Build 208 07/03/2011 SP 1 SJ Full Version // ************************************************************ //Copyright (C) 1991-2011 Altera Corporation //Your use of Altera Corporation's design tools, logic functions //and other software and tools, and its AMPP partner logic //functions, and any output files from any of the foregoing //(including device programming or simulation files), and any //associated documentation or information are expressly subject //to the terms and conditions of the Altera Program License //Subscription Agreement, Altera MegaCore Function License //Agreement, or other applicable license agreement, including, //without limitation, that your use is for the sole purpose of //programming logic devices manufactured by Altera and sold by //Altera or its authorized distributors. Please refer to the //applicable agreement for further details. // synopsystranslate_off `timescale 1 ps / 1 ps // synopsystranslate_on moduleclk_ctrl ( areset, inclk0, c0, c1, c2,

ADDA等一些芯片的verilog程序

/* AD0809 module v1.0 work up to 5M sample = 25us 40khz for normal clk = 2.5M sample = 30us 33khz */ module ad0809( clkin, adclk, eoc, st, ale, datain, oe, dataout ); input clkin; input eoc; input [7:0]datain; output st; output ale; output oe; output adclk; output [7:0]dataout; reg adclk; reg [7:0]dataout; reg st; reg oe; reg ale; //frequence divider for AD parameter Div_adclk = 8'd9;//(9+1)*2=20 adclk=2.5M parameter Div_clk_state = 4'd4;//(4+1)*2=10 clk_state=5M

reg [8:0]div_cnt_ad;//frequence div cnt reg [3:0]div_cnt_state; reg clk_state; always@(negedge clkin)begin if(div_cnt_ad != Div_adclk) div_cnt_ad <= div_cnt_ad + 1'b1; else begin div_cnt_ad <= 0; adclk <= ~adclk; end if(div_cnt_state != Div_clk_state) div_cnt_state <= div_cnt_state + 1'b1; else begin div_cnt_state <= 0; clk_state <= ~clk_state; end end /*AD convert*/ reg [3:0]state; reg [7:0]delay; initial begin state <= 4'd0; end always@(negedge clk_state)begin case(state) 4'd0:begin //clear all st <= 1'b0; oe <= 1'b0; ale <= 1'b0;

相关主题
文本预览
相关文档 最新文档