verilog的学习

verilog描述模块逻辑

数字逻辑电路以模块(module)的形式定义

语法:

vl 复制代码
module xxx;


endmodule

标识符的命名规则

1.以字母开头

2.可以包含任何字母和数字以及下划线_、美元符号$

3.区分大小写

verilog模块端口描述

电路模块的端口:一个电路模块有输入和输出信号,它们统称为端口(port)

语法:

vl 复制代码
module circle(s,x1,x2);//这括号里里面就是端口
input s,x1;
output x2;

endmodule

电路功能描述---门级原始结构

门级原始结构又称门实例化 gate instantiation

语法:

vl 复制代码
具体哪个门逻辑(output,input,input...)

PS:需要注意的是 有非门的情况先要提前声明,例如not(k,s)

eg:一个2输入与门,其输出为y,输入为x1和x2

vl 复制代码
and( y, x1, x2 );

电路功能描述---行为定义---连续赋值

在设计大规模电路时,使用门级原始结构会很繁琐。可行的选择是采用更为抽象的表达式和编程结构描述逻辑电路的行为。

所以在这里我们采取用逻辑表达式 表示的方法,例如f = ~s1x1 + s1x2

在verilog中就可以用assign 进行连续赋值

vl 复制代码
assign f = (~s1 & x1) | (s1 & x2)

电路功能描述---行为定义---过程语句

上述是用逻辑表达式 定义语句的,这次就来看一个使用过程语句定义的,用always编程结构

eg:如果s=0,则f=x1;如果s=1,则f=x2

vl 复制代码
if(s) f = x1;
else f = x2;

但是上述过程语句需要包含在always结构中

vl 复制代码
always @(sensitivity_list)
[begin]
    [procedural assignment statements]  //过程赋值语句
    [if-else statements]  //if-else语句
    [case statements]     //case语句
    [while, repeat, and for loops] //循环语句
    [task and function calls]      //任务和函数调用
[end]

PS:
1.always块中的输出信号必须定义成寄存器型reg

2.一个Verilog模块中可以包含多个always块

3.一整个always块可以看成是一个并行语句

verilog基础练习

verilog 练习网站

Step one

没啥好说的就让你输出一个值

v 复制代码
module top_module( output one );

// Insert your code here
    assign one = 1'b1;

endmodule

Zero

也没啥好说的,就是让你指定输出为0

v 复制代码
module top_module(
    output zero
);// Module body starts after semicolon
assign zero = 0;
endmodule

Wire

就是让你接线,这里注意输出在左,输入在右

v 复制代码
module top_module( input in, output out );
assign out = in;
endmodule

Wire4

也没啥好说的,在一对一接线上,增加了input 的 口

v 复制代码
module top_module( 
    input a,b,c,
    output w,x,y,z );
	assign w = a;
	assign x = b;
    assign y = b;
    assign z = c;
endmodule

反相器

不在输出端取反,而是将气泡往前推,推到输入端

v 复制代码
module top_module( input in, output out );
assign out = ~in;
endmodule

Andgate

没啥好说的,直接在输入端取与即可

v 复制代码
module top_module( 
    input a, 
    input b, 
    output out );
assign out = a & b;
endmodule

Norgate

取反往前推,推到输入端

v 复制代码
module top_module( 
    input a, 
    input b, 
    output out );
    assign out = ~(a | b);
endmodule

Xnorgate

我其实一开始直接写成与或式,完全忘记了还可以直接用^表示的

v 复制代码
module top_module( 
    input a, 
    input b, 
    output out );
    assign out = ~(a ^ b);
endmodule

Wire decl

其实看组合逻辑电路即可

v 复制代码
`default_nettype none
module top_module(
    input a,
    input b,
    input c,
    input d,
    output out,
    output out_n   );
    wire haha;
    wire haha1;
    wire haha2;
    assign haha = (a & b);
    assign haha1 = (c & d);
    assign haha2 = (haha|haha1);
    assign out_n = ~haha2;
    assign out = haha2;
endmodule

7458

照样看电路图

v 复制代码
module top_module ( 
    input p1a, p1b, p1c, p1d, p1e, p1f,
    output p1y,
    input p2a, p2b, p2c, p2d,
    output p2y );
    wire p2xi1;
    wire p2xi2;
    wire p1xi1;
    wire p1xi2;
    assign p2xi1 = (p2a & p2b);
    assign p2xi2 = (p2c & p2d);
    assign p2y = (p2xi1 | p2xi2);
    assign p1xi1 = (p1a & p1c & p1b);
    assign p1xi2 = (p1f & p1e & p1d);
    assign p1y = (p1xi1 | p1xi2);

endmodule
相关推荐
希言自然也3 小时前
FPGA 时序分析(一)
fpga开发
骑驴看星星a5 小时前
数学建模--Topsis(Python)
开发语言·python·学习·数学建模
长安即是故里7 小时前
Maxwell学习笔记
笔记·学习
I'm a winner9 小时前
基于FPGA的情绪感知系统设计方案:心理健康监测应用(一)
fpga开发·前沿研究
★YUI★9 小时前
学习制作记录(选项UI以及存档系统)8.24
学习·游戏·ui·unity·c#
咸甜适中9 小时前
rust语言 (1.88) egui (0.32.1) 学习笔记(逐行注释)(十四)垂直滚动条
笔记·学习·rust·egui
It_张11 小时前
Building Systems with the ChatGPT API 使用 ChatGPT API 搭建系统(第五章学习笔记及总结)
笔记·学习·chatgpt
The_Second_Coming11 小时前
Linux 学习笔记 - 集群管理篇
linux·笔记·学习
浪子不回头41514 小时前
Mirage-LLM编译成大Kernel
学习
red_redemption15 小时前
自由学习记录(87)
学习