zoukankan      html  css  js  c++  java
  • 【转】Verilog语法简介 Structure model Dataflow model

    What is Verilog 
    硬体描述语言->和一般在写的C语言对象不同 具有多种描述硬体的方式
    结构模型(structural) 通常用在简单逻辑闸的互连,或是各个小模组之间方块的连接. 资料流模型(dataflow) 若是所要描述的电路,可以用布林代数写出来,或者它可以用简单的运 算子描述出来的话,就会用资料流来表示.
    行为模型(behavior) 最常用的描述方式,可以用来描述很复杂的组合逻辑.若要撰写到跟时 序有关系的电路,一律都用行为模型来描述.
    在一个较大的电路方块内,经常会同时运用到3种描述方式
    For Example
    1-bit全加器,结构模型 module FA_1bit(sum,c_out,a,b,c_in); output sum,c_out; input a,b,c_in; wire s1,c1,c2; xor(s1,a,b); and(c1,a,b); xor (sum,s1,c_in); and (c2,s1,c_in); xor (c_out,c2,c1);
    endmodule
    For Example
    1-bit全加器,资料流模型(布林代数表达法) module FA_1bit(a,b,cin,s,cout); input a,b,cin; output s,cout;
    assign cout=(a&b)|(cin&b)|(a&cin); assign s=a^b^c;
    endmodule
    For Example
    1-bit全加器,资料流模型(运算子表达法)
    module FA_1bit(a,b,cin,s,cout); input a,b,cin; output s,cout;
    assign {cout,s}=a+b+cin; endmodule
    For Example
    1-bit全加器,行为模型 module FA_1bit(a,b,cin,s,cout); input a,b,cin; output s,cout; reg s,cout;
    always@(*) begin {cout,s}=a+b+cin end endmodule
    有抓到感觉了吗 
    Verilog的基本架构
    Verilog的基本架构
    Verilog最基本的精神就在於,把电路视为一 个方块,大的方块是由内部许多个小方块 互相连接而成. Top-Down
    Verilog的基本架构
    所以我们要学的第一件事是如何把模组连起来! 回到第一个程式 Another example:4-bit ripple carry adder
    Verilog的基本架构
    基本逻辑闸的互连可以靠位置,那模组呢 Connect by name! GOOD FA FA0 ( .a(a[0]),
    .b(b[0]), .cin(c[0]), .s(s[0]), .cout(c1) );
    BAD FA FA0(a[0],b[0],c[0],s[0],c1); 输入/输出与连线的宽度 input [3:0] a; output [3:0] s; output cout; wire c1,c2,c3;
    How to Debug 
    1bit的全加器,3个input共8种组合. 4bit的全加器,9个input共512种组合… Using testbench! 在大一程度的实习课内,所有的testbench都由 助教提供 大二之后就必须自己想如何测试,并实地撰写 testbench
    多工器
    多工器(Multiplexer)缩写MUX;或称资料选 择器(Data Selector)功能图如下,它乃利用 资料选择线来选择资料输入线的其中一条,将 此条资料送至输出端Y.
    多工器
    2-1 MUX
    4-1 MUX
    多工器
    使用结构模型去描述 OK,but so tired… Using dataflow! 在dataflow只能够使用运算子 位元运算子:~ & | ^ 算术运算子:+ - * % 连接运算子:{ , } { const{ } } 逻辑运算子:! && || 关系运算子:> >= < > << 条件运算子:condition true_statement : false_statement
    多工器
    二对一 assign Y = S0 D1 : D0;
    四对一 assign Y = {S1,S0}==2'b00 D0 : {S1,S0}==2'b01 D1 : {S1,S0}==2'b10 D2 : {S1,S0}==2'b11 D3 : 4'dz;
    解码器
    输入一个数字(位址) ,选择其中的某一位输出
    Decimal Digit 0 1 2 3 4 0 0 0 0 1 Binary Inputs 0 0 1 1 0 0 1 0 1 0 Outputs D0 1 0 0 0 0 D1 0 1 0 0 0 D2 0 0 1 0 0 D3 0 0 0 1 0 D4 0 0 0 0 1 D5 0 0 0 0 0 D6 0 0 0 0 0 D7 0 0 0 0 0
    5 6
    7
    1 1
    1
    0 1
    1
    1 0
    1
    0 0
    0
    0 0
    0
    0 0
    0
    0 0
    0
    0 0
    0
    1 0
    0
    0 1
    0
    0 0
    1
    When to use 记忆体定址,取出特定内容
    解码器
    使用dataflow描述 assign Y = (A==3'd0) 8'b00000001; (A==3'd1) 8'b00000010; (A==3'd2) 8'b00000100; (A==3'd3) 8'b00001000; (A==3'd4) 8'b00010000; (A==3'd5) 8'b00100000; (A==3'd6) 8'b01000000; (A==3'd7) 8'b10000000 : 8'dz;

  • 相关阅读:
    sublime text 4 vim 插件配置
    ssh-keygen 的使用
    distribution transaction solution
    bilibili 大数据 视频下载 you-get
    Deepin 20.2.1 安装 MS SQL 2019 容器版本
    【转】使用Linux下Docker部署MSSQL并加载主机目录下的数据库
    【转】You Can Now Use OneDrive in Linux Natively Thanks to Insync
    dotnet 诊断工具安装命令
    Linux 使用 xrandr 设置屏幕分辨率
    【转】CentOS 7.9 2009 ISO 官方原版镜像下载
  • 原文地址:https://www.cnblogs.com/lzhitian/p/2765725.html
Copyright © 2011-2022 走看看