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

本文深入讲解了数字IC工程师必备技能:如何从仿真波形中解析并编写电路代码。涵盖组合逻辑电路与时序逻辑电路的设计,通过具体实例演示了Verilog HDL语言的应用,包括卡诺图简化、case语句使用及计数器实现等关键概念。

目录

前言

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

内容概要:本文系统研究了在有限控制集约束下,三相并网逆变器中电流与功率双模态模型预测控制(MPC)的等效机理及其性能边界。通过构建精确的预测模型,设计合理的代价函数,并结合Simulink仿真与Matlab代码实现,深入分析了电流预测控制与功率预测控制两种策略在动态响应速度、稳态精度、谐波抑制能力和抗扰性等方面的差异与内在联系。研究揭示了在特定系统参数和运行条件下,两种控制模式之间的等效转化机制,并界定了各自的适用范围与性能极限。同时,探讨了多模态控制的切换逻辑、实时性优化及预测模型不确定性对控制性能的影响,旨在提升逆变器在复杂电网环境下的综合控制品质与鲁棒性。; 适合人群:具备电力电子、自动控制或新能源并网等相关专业背景,熟悉Matlab/Simulink仿真环境,从事研究生及以上层次科研或从事高端电力电子装备研发的工程技术人员。; 使用场景及目标:①深入理解模型预测控制在并网逆变器中的具体实现方法与理论基础;②掌握电流与功率双模态MPC控制器的设计、仿真建模与性能对比评估流程;③为高动态、高精度并网控制系统的方案选型、参数优化与工程化应用提供坚实的理论依据和技术参考。; 阅读建议:建议结合所提供的Simulink仿真模型与Matlab源代码进行同步实验验证,重点关注预测模型的建立过程、控制律的数学推导以及不同工况下的仿真结果对比分析,宜配合现代控制理论、电力电子变换技术及并网标准等相关资料进行系统性学习。
评论 19
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值