代码编织梦想

目录

第161题:Mux

第162题:Add/sub

第163题:Case statement

第164题:Combinational circuit 1

第165题:Combinational circuit 2

第166题:Combinational circuit 3

第167题:Combinational circuit 4

第168题:Combinational circuit 5

第169题:Combinational circuit 6

第170题:Sequential circuit 7


第161题:Mux

module top_module 
(
    input   [1:0] sel   ,
    input   [7:0] a     ,
    input   [7:0] b     ,
    input   [7:0] c     ,
    input   [7:0] d     ,
    output  [7:0] out  
);

    wire [7:0] mux0, mux1;
    mux2 mux2_inst1 ( sel[0],    a,    b, mux0 );
    mux2 mux2_inst2 ( sel[0],    c,    d, mux1 );
    mux2 mux2_inst3 ( sel[1], mux0, mux1,  out );

endmodule

第162题:Add/sub

module top_module 
( 
    input               do_sub          ,
    input         [7:0] a               ,
    input         [7:0] b               ,
    output reg    [7:0] out             ,
    output reg          result_is_zero
);

    always @(*) begin
        case (do_sub)
          0: out = a+b;
          1: out = a-b;
        endcase

        if (out==8'b0)
            result_is_zero = 1;
        else
            result_is_zero = 0;
    end

endmodule

第163题:Case statement

module top_module 
(
    input       [7:0]   code    ,   
    output reg  [3:0]   out     ,
    output reg          valid=1 
);

     always @(*)
        case (code)
            8'h45: {out,valid} = {4'd0,1'b1};
            8'h16: {out,valid} = {4'd1,1'b1};
            8'h1e: {out,valid} = {4'd2,1'b1};
            8'h26: {out,valid} = {4'd3,1'b1};
            8'h25: {out,valid} = {4'd4,1'b1};
            8'h2e: {out,valid} = {4'd5,1'b1};
            8'h36: {out,valid} = {4'd6,1'b1};
            8'h3d: {out,valid} = {4'd7,1'b1};
            8'h3e: {out,valid} = {4'd8,1'b1};
            8'h46: {out,valid} = {4'd9,1'b1};
            default: {out,valid} = {4'd0,1'b0};
        endcase

endmodule

第164题:Combinational circuit 1

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

assign q = a&b;

endmodule

第165题:Combinational circuit 2

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

第166题:Combinational circuit 3

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

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

endmodule

第167题:Combinational circuit 4

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

assign q = b|c;

endmodule

第168题:Combinational circuit 5

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

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

endmodule

第169题:Combinational circuit 6

module top_module 
(
    input   [2:0]   a,
    output  [15:0]  q 
); 

always@(*)
    case(a)
        0   :   q = 16'h1232;
        1   :   q = 16'haee0;
        2   :   q = 16'h27d4;
        3   :   q = 16'h5a0e;
        4   :   q = 16'h2066;
        5   :   q = 16'h64ce;
        6   :   q = 16'hc526;
        7   :   q = 16'h2f19;
        default:q = 16'bx;
    endcase

endmodule

第170题:Sequential circuit 7

module top_module 
(
    input       clk ,
    input       a   ,
    output      q 
);

always@(posedge clk)
    q <= ~a;

endmodule

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_62179548/article/details/130033799

pcb模块化设计24——dcdc电源模块pcb布局布线设计规范-爱代码爱编程

目录 PCB模块化设计24——DCDC电源模块PCB布局布线设计规范1、DCDC电源概述2、BUCK DC-DC工作时的电流通路3、DCDC设计1、芯片手册的下载2、原理图分析3、布局1、CIN、 CBYPASS、

fpga 20个例程篇:20.usb2.0/rs232/lan控制并行dac输出任意频率正弦波、梯形波、三角波、方波(三)-爱代码爱编程

        如图1所示是USB2.0/RS232/ETH控制并行DAC输出任意频率正弦波、梯形波、三角波、方波的整体设计示意图,可以看到上位机通过RS232串口、ETH千兆网口以及USB2.0接口和FPGA建立通信,通过不同的接口发送报文,FPGA在指令解析模块中把相关设置和参数再下发到任意波(方波、三角波、梯形波)发生器模块和正弦波发生器模块,最后通

异步fifo原理及实现-爱代码爱编程

异步FIFO主要用作跨时钟域的数据缓存,设计时的要点在于判断FIFO的空满状态。 一、代码中的重要参数 1、FIFO:First Input First Output,即先入先出队列,本质是RAM。 2、wr_clk:写时

二、总线频率设置-爱代码爱编程

总线频率设置源码 # < board\vbird\mini2440\lowlevel_init.S > #define BWSCON 0x48000000 /* BWSCON */ #define DW8 (0x0) #define DW16 (0x1) #define DW32 (0x2) #define WAIT (0

sv testbench 案例学习与思考-爱代码爱编程

引言 关于Systemverilog语法学习的专栏博客已经告一段落,现在结合 chipverify 官网给出的几个testbench 案例,利用 QuestaSim 平台实做一些练习。 设计 // ---- ---- Design module // 简述:数据地址选通 module switch #( parameter ADDR_