【Verilog - 组合逻辑 - 基础3】4. 与或门-1

  • 1. 介绍
    • 1.1 与门介绍
    • 1.2 或门介绍
  • 2.0 与门在verilog的建模
    • 2.1 与门-行为极模型
    • 2.2 与门-门极模型
    • 2.3 与门-电路极模型
  • 3.0 或门在verilog的建模
    • 3.1 或门-行为极模型
    • 3.2 或门-门极模型
    • 3.3 或门-电路极模型
    • 3.4 测试结果
  • 4.0 与非门
    • 4.1 与非门
    • 4.2 与非门-门极模型
    • 4.3 与非门-电路极模型
  • 5.0 或非门
    • 5.1 或非门-行为极模型
    • 5.2 或非门-门极模型
    • 5.3 与门-电路极模型
  • 6.0 与非门和非门,与门和或门的关系
    • 6.1.1 与非门转非门
    • 6.1.1 非门转与非门
    • 6.2.1 与非门转与门
    • 6.2.2 与门转与非门
    • 6.3.1 与非门转或门
    • 6.3.2 或门转与非门
  • 7.0 真实面试题

爱人,待周爱人,而后为爱人。不爱人,不待周不爱人《墨子.小取》

1. 介绍

1.1 与门介绍

与门和或门的逻辑可以同过墨子的兼爱思想来理解。

墨子曰:“爱人,待周爱人,而后为爱人”

就是说,如果爱全部周边的人,则算是一位爱人的仁者。

如果用1来代表爱人,那输入都得是1( 待周爱人)才能使 输出是1(而后为爱人)。这不就是一个与门吗?

输入1 输入2 输出
0 0 0
0 1 0
1 0 0
1 1 1

1.2 或门介绍

或门也可以同过墨子的兼爱思想来理解。这里是反例。

墨子曰:“不爱人,不待周不爱人”

这里就是说,如果周边有任何一个不爱的人,那就不能算是一位爱人的仁者了。

相反,如果用1来代表不爱人,那如果其中有一个输入是1(不待周),那输出就是1 (不爱人)。这不就是一个或门吗?

输入1 输入2 输出
0 0 0
0 1 1
1 0 1
1 1 1

2.0 与门在verilog的建模

在verilog,有三个层面的硬件的模型:行为,门,和电路极。

2.1 与门-行为极模型

module and2(input jia, input yi, output bing);assign bing = jia & yi;
endmodule

2.2 与门-门极模型

module and2(input jia, input yi, output bing);and(bing, jia, yi);
endmodule

2.3 与门-电路极模型

要注意,因为电路里,电极刚好是相反的,所以要实现一个与门(用cmos的话)就要再加一个非门,

module and2(input jia, input yi, output bing);wire yu_fei;wire zhong;//yu_fei menpmos(yu_fei, 1, jia ); pmos(yu_fei,1,yi);nmos(zhong, 0, jia);nmos(yu_fei, zhong, yi);//fei menpmos(bing, 1, yu_fei);nmos(bing, 0, yu_fei);
endmodule

下一节会讨论其它的电路极实现方法。。

3.0 或门在verilog的建模

3.1 或门-行为极模型

module or2(input jia, input yi, output bing);assign bing = jia | yi;
endmodule

3.2 或门-门极模型

module and2(input jia, input yi, output bing);or(bing, jia, yi);
endmodule

3.3 或门-电路极模型

要注意,因为电路里,电极刚好是相反的,所以要实现一个与门(用cmos的话)就要再加一个非门,

module or2(input jia, input yi, output bing);wire huo_fei;wire zhong;//huo_fei menpmos(zhong, 1, jia ); pmos(huo_fei,zhong,yi);nmos(huo_fei, 0, jia); nmos(huo_fei, 0, yi);//fei menpmos(bing, 1, huo_fei);nmos(bing, 0, huo_fei);
endmodule

下一节会讨论其它的电路极实现方法。。

3.4 测试结果

module or2(input jia, input yi, output bing);wire huo_fei;wire zhong;//huo_fei menpmos(zhong, 1, jia ); pmos(huo_fei,zhong,yi);nmos(huo_fei, 0, jia); nmos(huo_fei, 0, yi);//fei menpmos(bing, 1, huo_fei);nmos(bing, 0, huo_fei);
endmodulemodule ceshi;reg jia,yi;wire bing;or2 dut(jia, yi, bing);integer i;initial beginfor (i = 0; i < 4; i++) begin{jia,yi} = i;#1;$display("jiayi=%b%b,bing=%b", jia,yi,bing);endend
endmodule
liu2333hui@liu2333hui-PC:~/verilog/nihao$ epicsim or2.v
jiayi=00,bing=0
jiayi=01,bing=1
jiayi=10,bing=1
jiayi=11,bing=1

4.0 与非门

与或门也可以联合非门,所为学而实习之不亦乐乎?

4.1 与非门

module nand2(input jia, input yi, output bing);assign bing = ~(jia & yi);
endmodule

4.2 与非门-门极模型

module nand2(input jia, input yi, output bing);nand(bing, jia, yi);
endmodule

4.3 与非门-电路极模型

module nand2(input jia, input yi, output bing);wire yu_fei;wire zhong;//yu_fei menpmos(yu_fei, 1, jia ); pmos(yu_fei,1,yi);nmos(zhong, 0, jia);nmos(yu_fei, zhong, yi);assign bing = yu_fei;
endmodule

5.0 或非门

5.1 或非门-行为极模型

module nor2(input jia, input yi, output bing);assign bing = ~(jia | yi);
endmodule

5.2 或非门-门极模型

module nor2(input jia, input yi, output bing);nor(bing, jia, yi);
endmodule

5.3 与门-电路极模型

module nor2(input jia, input yi, output bing);wire huo_fei;wire zhong;//huo_fei menpmos(zhong, 1, jia ); pmos(huo_fei,zhong,yi);nmos(huo_fei, 0, jia); nmos(huo_fei, 0, yi);assign bing = huo_fei;
endmodule

6.0 与非门和非门,与门和或门的关系

其实,一个门可以很容易的转变成其它的门。譬如,

6.1.1 与非门转非门

看看逻辑,

yi = ~jia = ~(jia & jia)

所以,

module not2(input jia, output yi);nand(yi, jia, jia);// assign yi = ~(jia & jia);
endmodule

6.1.1 非门转与非门

这个恐怕不可以了,因为非门只有一个输入的口。

6.2.1 与非门转与门

看看逻辑,

bing = jia & yi = ~(~(jia & yi));

这个就是一个与非门和一个非门(可用与非门来实现)。

module and2(input jia, input yi, output bing);wire zhong;nand(zhong, jia, yi);nand(bing, zhong, zhong);// assign bing = ~(~(jia & yi));
endmodule

6.2.2 与门转与非门

这个恐怕不可以了,因为没有转非的能力。

6.3.1 与非门转或门

看看逻辑,

bing = jia | yi = ~(~(jia | yi)) = ~(~jia & ~yi);

不想信的可以去自己的证明一下。
所以,输出是从一个与非门来的,但是输入是带有两个非门。

module or2(input jia, input yi, output bing);wire fei_jia, fei_yi;nand(fei_jia, jia, jia);nand(fei_yi, yi, yi);nand(bing, fei_jia, fei_yi);
endmodule

6.3.2 或门转与非门

这个恐怕也不可以了,因为没有转非的能力。

7.0 真实面试题

到这里,就可以来解一些有意思的关于非与门面试题了。

请用多个2-输入的与非来实现一个4-输入的与非门?

答:
我们想实现的功能是以下:

out = ~(a & b & c & d );

可以进行推测,

e = a & b = ~(~(a & b)) = not(nand(a,b));
f = c & d = ~(~(c & d) = not(nand(c,d));
out = ~(e & f) = nand(e,f);

这就容易实现了,用verilog的门极建模,

module nand4_2(input a, input b, input c, input d, output out);wire e,f;wire g, h;nand(e, a, b);nand(f, c, d);nand(g, e, e);nand(h, f, f);nand(out, g, h);
endmodulemodule nand4(input a, input b, input c, input d, output out);assign out = ~(a&b&c&d);
endmodulemodule nand4_tb;reg a,b,c,d;wire out,out2;nand4 dut(a,b,c,d,out);nand4_2 dut1(a,b,c,d,out2);integer i;initial beginfor (i = 0; i < 16; i++)begin{a, b, c, d} = i;#1;$display("abcd = %b%b%b%b, out = %b, out2 = %b", a,b,c,d,out, out2);endend
endmodule

效果如下,

liu2333hui@liu2333hui-PC:~/verilog/nihao$ epicsim nand.v
abcd = 0000, out = 1, out2 = 1
abcd = 0001, out = 1, out2 = 1
abcd = 0010, out = 1, out2 = 1
abcd = 0011, out = 1, out2 = 1
abcd = 0100, out = 1, out2 = 1
abcd = 0101, out = 1, out2 = 1
abcd = 0110, out = 1, out2 = 1
abcd = 0111, out = 1, out2 = 1
abcd = 1000, out = 1, out2 = 1
abcd = 1001, out = 1, out2 = 1
abcd = 1010, out = 1, out2 = 1
abcd = 1011, out = 1, out2 = 1
abcd = 1100, out = 1, out2 = 1
abcd = 1101, out = 1, out2 = 1
abcd = 1110, out = 1, out2 = 1
abcd = 1111, out = 0, out2 = 0

【Verilog - 组合逻辑 - 基础3】4. 与或门-1相关推荐

  1. 【Verilog零基础入门-边看边练】学习笔记——第三讲 组合逻辑代码设计和仿真(补码转换和七段译码逻辑设计)(二)

    二.七段译码逻辑设计 所需软件 Verilog编程软件:Lattice Diamond(3.11.0.396.4_Diamond_x64) Verilog仿真软件:ModelSim SE-64 10. ...

  2. (05)System Verilog 组合逻辑与时序逻辑区别

    (05)System Verilog 组合逻辑与时序逻辑区别 1.1 目录 1)目录 2)FPGA简介 3)System Verilog简介 4)System Verilog 组合逻辑与时序逻辑区别 ...

  3. Verilog HDL 基础

    Verilog HDL 基础 一.Verilog 的基本概念 1. 硬件描述语言HDL 1.1 特点: 描述电路的连接.描述电路的功能.在不同抽象级上描述电路. 描述电路的时序.表达具有并行性 1.2 ...

  4. Verilog 语言基础

    Verilog 语言基础 想要很详细的理解Verilog语言基础,建议先下载Robei软件,这样可以很形象化的把语句理解透彻. 1 Verilog 基础 1.1. 数据 (1)电路四种状态 Veril ...

  5. Verilog HDL基础知识

    Verilog HDL基础知识 Verilog HDL的语言要素 空白符 注释符 标识符和转义标识符 关键字 数值 1. 整数及其表示 2. 实数及其表示 3. 字符串及其表示 数据类型 Verilo ...

  6. Verilog组合逻辑设计

    一.实验项目名称: Verilog组合逻辑设计 二.实验目的: 使用ISE软件和Verilog语言进行组合逻辑的设计与实现. 三.实验内容: 1.3-8译码器的设计和实现. 2.4位并行进位加法器的设 ...

  7. Verilog HDL基础知识---之数据类型

    Verilog HDL基础知识之数据类型 数据类型 物理数据类型 连线型 寄存器型 连线型和寄存器型数据类型的声明 存储器型 抽象数据类型 整型 时间型 实型 参数型 kkkk我来啦 , 接上回写 数 ...

  8. Verilog语言基础语法

    Verilog基础知识 数字进制格式 标识符 数据类型 寄存器类型 线网类型 参数类型 运算符 运算优先级 数字进制格式 Verilog数字进制格式包括二进制,八进制,十进制,十六进制.常用为二进制, ...

  9. Verilog简单基础

    01 简介 关于Verilog verilog 以文本形式来描述数字系统硬件的结构和行为的语言. 表示逻辑电路图.逻辑表达式.数字逻辑系统所完成的逻辑功能 五个层次:系统级.算法级.寄存器传输级.门级 ...

最新文章

  1. 创建Student Course SC表
  2. window下安装Oracle11G安装
  3. Oracle数据库的视图
  4. 职业教育计算机课教学反思,关于高职计算机基础课的教学反思.doc
  5. IntelliJ IDEA 2020 如何同时启动多个服务
  6. 如何从0到1搭建物联网系统?
  7. linux从虚拟磁盘启动,Linux虚拟磁盘实战
  8. 对makefile中:单冒号普通规则和::双冒号规则的理解 -转
  9. python最简单的游戏源代码_Python 练习: 简单角色游戏程序
  10. 大数据分析-时间序列(pandas库 )
  11. 微信小程序 访问locolhost_微信小程序开发——本地调试
  12. 山东大学软件学院计算机组成原理课程设计实验二
  13. 使用UDP遇到的问题小结
  14. PSNR SSIM BD-rate BD-PSNR
  15. 一个屌丝程序员的青春(五一)
  16. 参考分享《Python深度学习》高清中文版pdf+高清英文版pdf+源代码
  17. lombok导入报错,版本1.18.12已在maven本地仓库中
  18. oracle 购买预估 硬件,2.2.2 硬件配置的预估
  19. ATL SERVER
  20. 齐供应TAPPI四碘化5,10,15,20-四(对-N,N,N三甲基苯胺基)卟啉敏化的钛酸盐纳米管(TAPPI-TNTs)高效的可见光催化剂岳

热门文章

  1. 统计学相关概念及机器学习中样本相似性度量之马氏距离
  2. C10:Unity3D制作智能家居设计软件——三步实现家具生长动画
  3. 【SDRAM】STM32外扩SDRAM学习总结 + CubeMX配置教程
  4. 学习OpenCV:滤镜系列(15)——羽化(模糊边缘)
  5. html图片拉伸整个页面,css如何让图片拉伸?
  6. 理解Apollo传感器标定文档
  7. elementui popper 当前页样式修改 更改出现位置
  8. 使用React头盔管理您的头脑
  9. 一文读懂安全攻防实战、CNVD漏洞平台
  10. 如何把PDF文件合并?这样合并其实很简单