HDLbits答案更新系列22(4.2 Build a circuit from a simulation waveform)

目录

前言

4.2 Build a circuit from a simulation waveform

4.2.1 Combinational circuit 1(Sim/circuit1)

4.2.2 Combinational circuit 2(Sim/circuit2)

4.2.3 Combinational circuit 3(Sim/circuit3)

4.2.4 Combinational circuit 4(Sim/circuit4)

4.2.5 Combinational circuit 5(Sim/circuit5)

4.2.6 Combinational circuit 6(Sim/circuit6)

4.2.7 Sequential circuit 7(Sim/circuit7)

4.2.8 Sequential circuit 8(Sim/circuit8)

4.2.9 Sequential circuit 9(Sim/circuit9)

4.2.10 Sequential circuit 10(Sim/circuit10)

结语

HDLbits网站链接


前言

今天这个小节内容算是数字IC工程师的看家本领了,看波形写代码,无论在笔试还是项目中,这都是基本功中的基本功,下面我们就开始吧。

4.2 Build a circuit from a simulation waveform

4.2.1 Combinational circuit 1(Sim/circuit1)

module top_module (
    input a,
    input b,
    output q );//

    assign q = a & b; // Fix me

endmodule

4.2.2 Combinational circuit 2(Sim/circuit2)

module top_module (
    input a,
    input b,
    input c,
    input d,
    output q );//

    assign q = ~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

画一个卡诺图,答案立马出来。

4.2.3 Combinational circuit 3(Sim/circuit3)

module top_module (
    input a,
    input b,
    input c,
    input d,
    output q );//

    assign q = b & d | b & c | a & d | a & c;

endmodule

和上一道题目做法相同,画卡诺图就好。

4.2.4 Combinational circuit 4(Sim/circuit4)

module top_module (
    input a,
    input b,
    input c,
    input d,
    output q );//

    assign q = b | c;

endmodule

同理。

4.2.5 Combinational circuit 5(Sim/circuit5)

module top_module (
    input [3:0] a,
    input [3:0] b,
    input [3:0] c,
    input [3:0] d,
    input [3:0] e,
    output reg [3:0] q );

    always@(*)begin
        case(c)
            0:begin
                q = b;
            end
            1:begin
                q = e;
            end
            2:begin
                q = a;
            end
            3:begin
                q = d;
            end
            default:begin
                q = 4'hf;
            end
        endcase
    end
    
endmodule

大家只要将C的值作为判定条件,这道题就容易多了。

4.2.6 Combinational circuit 6(Sim/circuit6)

module top_module (
    input [2:0] a,
    output reg [15:0] q ); 
    
    always@(*)begin
        case(a)
            0:begin
                q = 16'h1232;
            end
            1:begin
                q = 16'haee0;
            end
            2:begin
                q = 16'h27d4;
            end
            3:begin
                q = 16'h5a0e;
            end
            4:begin
                q = 16'h2066;
            end
            5:begin
                q = 16'h64ce;
            end
            6:begin
                q = 16'hc526;
            end
            7:begin
                q = 16'h2f19;
            end
        endcase
    end

endmodule

每个a值对应一个q值,这里由于case的所有情况都被囊获进去了,所以我没有写default,还是建议大家补充完整。

4.2.7 Sequential circuit 7(Sim/circuit7)

module top_module (
    input clk,
    input a,
    output q );
    
    always@(posedge clk)begin
        q <= ~a;
    end

endmodule

4.2.8 Sequential circuit 8(Sim/circuit8)

module top_module (
    input clock,
    input a,
    output p,
    output q );
    
    always@(*)begin
        if(clock)begin
        	p = a;
        end
    end
    
    always@(negedge clock)begin
        q <= p;
    end

endmodule

这道题可能解法不唯一,欢迎大家展示出自己的解法。

4.2.9 Sequential circuit 9(Sim/circuit9)

module top_module (
    input clk,
    input a,
    output [3:0] q );
    
    always@(posedge clk)begin
        if(a)begin
            q <= 4'd4;
        end
        else if(q == 4'd6)begin
            q <= 4'd0;
        end
        else begin
            q <= q + 1'b1;
        end
    end

endmodule

这道题目是一个计数器,只不过“复位信号”a为1时q为4。

4.2.10 Sequential circuit 10(Sim/circuit10)

module top_module (
    input clk,
    input a,
    input b,
    output q,
    output state  );
        
    always@(posedge clk)begin
        if(a == b)begin
        	state <= a;
        end
    end
    
    always@(*)begin
        q = a & ~b & ~state | ~a & ~b & state | a & b & state | ~a & b & ~state;
    end
    
    //q second way and third way
    //assign q = (a == b) ? state : ~state;
    //assign q = (a ^~ b) ? state : ~state;
    
endmodule

这道题可能方法不唯一,我想到的是这种方法,大家自己试试吧。

结语

今天更新的这个小节很重要,这是基本功,我也需要继续在这个方面下功夫。希望能和大家一起努力,共同进步~

HDLbits网站链接

https://hdlbits.01xz.net/wiki/Main_Page

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 18
    评论
《Spice: 电路模拟与分析指南》是一本关于电路模拟和分析使用的指南书籍。Spice(Simulation Program with Integrated Circuit Emphasis)是一种流行的电路仿真软件,它可以帮助工程师们设计、测试和分析各种类型的电路。 这本指南书籍首先介绍了Spice软件的基本原理和功能。它解释了Spice如何用数学模型来描述电子元件的行为,并利用这些模型来模拟和预测电路的性能。读者将学会如何使用Spice设置电路拓扑结构、选择元件参数和设置仿真参数。 随后,书中详细介绍了各种不同类型的电路和电子元件的模拟和分析技术。这些包括放大器、滤波器、振荡器、开关电路等。每一章节都包含具体的实例和实验,以帮助读者深入理解和掌握这些概念。 除了基础知识和技术外,这本指南还讨论了一些高级的主题,如内嵌模拟与混合信号电路设计。它向读者介绍了Spice如何与其他软件和工具进行集成,以实现更复杂的电路设计和分析。 最后,这本指南还包含了一些常见问题解答和实用技巧,以帮助读者解决在使用Spice时可能遇到的一些常见问题和困难。 总而言之,这本指南是一本全面而详细的关于Spice电路模拟和分析的指南。它适用于电子工程师、学生和任何对电路设计和分析感兴趣的人。读者将通过本书学会如何使用Spice软件,以提高电路设计的准确性和效率。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 18
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值