HDLBits(13)2.24

3 电路

3.1 组合逻辑

3.1.4 卡诺线路图(Karnaugh Map to Circuit)

  • Kmap1(3-variable)

out = a + ab +ac = a & (a^b) & (a^c) = a | b | c 

module top_module(
    input a,
    input b,
    input c,
    output out  ); 
    assign out = a|b|c;
endmodule
  •  Kmap2(4-variable)

module top_module(
    input a,
    input b,
    input c,
    input d,
    output out  ); 
    assign out = (~b&~c)|(~a&~d)|(b&c&d)|(a&c&d);
endmodule
  •  Kmap3(4-variable)

*d 既可视为1,也可视为0

module top_module(
    input a,
    input b,
    input c,
    input d,
    output out  ); 
    assign out = (~b&c)|a;
endmodule
  • Kmap4(4-variable)

 
module top_module(
    input a,
    input b,
    input c,
    input d,
    output out  ); 
    assign out = (~a&~b&~c&d)|(~a&b&~c&~d)|(a&b&~c&d)|(a&~b&~c&~d)|(~a&b&c&d)|(a&~b&c&d)|(~a&~b&c&~d)|(a&b&c&~d);
endmodule
  • Minimum SOP and POS

具有四个输入(a、b、c、d)的单输出数字系统在输入上出现 2、7 或 15 时生成逻辑 1,当输入上出现 0、1、4、5、6 、9、10、13 或 14 出现时生成逻辑 0。数字 3、8、11 和 12 的输入条件在此系统中永远不会出现。例如,7 对应于 a、b、c、d 分别设置为 0、1、1、1。

确定最小SOP形式(积之和 最小项)的输出out_sop,以及最小POS形式(和之积 最大项)的输出out_pos。

module top_module (
    input a,
    input b,
    input c,
    input d,
    output out_sop,
    output out_pos
); 
    assign out_sop = (~a&~b&c)|(c&d);
    assign out_pos = c&(~b|d)&(~a|d);
endmodule
  • Karnaugh map

module top_module (
    input [4:1] x, 
    output f );
    assign f = (~x[1]&x[3])|(x[2]&x[4]);
endmodule
  • K-map implemented with a multiplxer

对于下面的卡诺图,给出使用一个 4 对 1 多路复用器和尽可能多的 2 对 1 多路复用器的电路实现,但使用尽可能少。不允许使用任何其他逻辑门,并且必须使用a和b作为多路复用器选择器输入,如下面的 4 对 1 多路复用器所示。您只实现了标记为top_module的部分,以便整个电路(包括 4 对 1 多路复用器)实现 K-map。

    

module top_module (
    input c,
    input d,
    output [3:0] mux_in
); 
    assign mux_in[0] = c|d;
    assign mux_in[1] = 0;
    assign mux_in[2] = ~d;
    assign mux_in[3] = c&d;
endmodule

 

 

3.2 时序逻辑

3.2.1 锁存器与触发器(Latches and Flip-Flops)

  • Dff(D Flip-Flops)(D触发器)

D触发器是一种存储位并定期更新的电路,通常在时钟信号的上升沿触发。

当使用时钟控制的always 块时,逻辑合成器会创建 D 触发器。D触发器是“组合逻辑块后接触发器”的最简单形式,其中组合逻辑部分只是一条线。创建一个 D 触发器。

module top_module (
    input clk,    // Clocks are used in sequential circuits
    input d,
    output reg q );//
 
    // Use a clocked always block
    //   copy d to q at every positive edge of clk
    //   Clocked always blocks should use non-blocking assignments
    always @(posedge clk) begin
        q<=d;
    end
endmodule

绝大多数时候,我们不会在 Verilog 代码中显示例化一个触发器,我们在时钟敏感的 always 块中的语句一般都会被综合工具转换为相应的触发器。

D 触发器可以认为是一个触发器和一段最简单的组合逻辑块的组合。其中组合逻辑块仅仅是一段 wire。(q 直接输出了触发器的存储值)

  • Dff8

创建一个8位D触发器,所有的Dff都应由时钟上升沿触发

module top_module (
    input clk,
    input [7:0] d,
    output [7:0] q
);
    always @(posedge clk) begin
        q<=d;
    end
endmodule
  • Dff8r(DFF with reset)

创建一个8位具有高电平有效同步复位的 D 触发器,所有的Dff都应由时钟上升沿触发

module top_module (
    input clk,
    input reset,            // Synchronous reset
    input [7:0] d,
    output [7:0] q
);
    always@(posedge clk) begin
       if(reset)
           q<=8'd0;
       else
           q<=d; 
    end
endmodule

复位电路对于那些经常需要恢复到初始状态的电路是必要的,复位相较于断电重新加载程序恢复到初始状态的速度要快得多。

  • Dff8p(DFF with reset value)

创建 8 位具有高电平有效同步复位的 D 触发器。触发器必须重置为 0x34 而不是零。所有 DFF 都应由clk的下降沿触发。将寄存器重置为“1”有时称为“预设(preset)”

module top_module (
    input clk,
    input reset,
    input [7:0] d,
    output [7:0] q
);
    always @(negedge clk)
        begin
            if(reset)
                q <= 8'h0x34;
            else
                q <= d;
        end
endmodule

 

posted @   LhTian21  阅读(77)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Blazor Hybrid适配到HarmonyOS系统
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· 解决跨域问题的这6种方案,真香!
· 一套基于 Material Design 规范实现的 Blazor 和 Razor 通用组件库
· 分享4款.NET开源、免费、实用的商城系统
点击右上角即可分享
微信分享提示