Question

In: Electrical Engineering

Write the Verilog code and test bench for the following circuits: - Mealy State machine design...

Write the Verilog code and test bench for the following circuits:

- Mealy State machine design for a Serial Adder Circuit

- Moore State Machine design for a Serial Adder Circuit

Solutions

Expert Solution

Mealy state machine design for serial adder:

State diagram for serial adder

module SA(

    input A,

    input B,

    output F,

    output Cout,

    input clk,

    input rst

    );

// Define State Codes

localparam S0 = 2'b00;

localparam S1 = 2'b01;

localparam S2 = 2'b10;

localparam S3 = 2'b11;

reg [1:0] pState, nState;

// Combinational Logic: Next State Logic

always @ (pState, A, B)

begin

    case (pState)

        S0:begin

            if (A == 1'b0 && B == 1'b0)

                nState = S0;

            else if (A == 1'b1 && B == 1'b1)

                nState = S2;

            else

                nState = S1;

            end

        S1:

            if (A == 1'b0 && B == 1'b0)

                nState = S0;

            else if (A == 1'b1 && B == 1'b1)

                nState = S2;

            else

                nState = S1;

        S2:

            if (A == 1'b0 && B == 1'b0)

                nState = S1;

            else if (A == 1'b1 && B == 1'b1)

                nState = S3;

            else

                nState = S2;

        S3:

            if (A == 1'b0 && B == 1'b0)

                nState = S1 ;

            else if (A == 1'b1 && B == 1'b1)

                nState = S3;

            else

                nState = S2;

        default:

            nState = S0;

    endcase

end

// State Registers

always @ (posedge(clk), posedge(rst))

begin

    if (rst == 1'b1)

        pState <= S0;

    else

        pState <= nState;

end

// Output Logic

assign F = (pState == S1 || pState == S3) ? 1'b1 : 1'b0;

assign Cout = (pState == S2 || pState == S3) ? 1'b1 : 1'b0;

endmodule

2. Verilog code for Moore type srials adder:

module sadd (a, b, s, clock, clear);
> parameter s0 = 1'b0, s1 = 1'b1;
> input a, b, clock, clear;
> output s;
> reg s;
> reg ps, ns;
>
> always @(posedge clock or posedge clear) begin
> if (clear) begin
> ps = s0;
> end
> else begin
> ps = ns;
> end
> end
>
> always @(ps or a or b) begin
> case (ps)
> s0: begin
> case ({a,b})
> 2'b00: begin
> ns = s0;
> s = 1;
> end
> 2'b01: begin
> ns = s1;
> s = 0;
> end
> 2'b10: begin
> ns = s1;
> s = 0;
> end
> 2'b11: begin
> ns = s1;
> s = 1;
> end
> s = 0;
> end
> 2'b01: begin
> ns = s0;
> s = 1;
> end
> 2'b10: begin
> ns = s0;
> s = 1;
> end
> 2'b11: begin
> ns = s1;
> s = 0;
>
> end
> default: begin
> ns = s0;
> s = 0;
> end
> endcase
> end
> s1: begin
> case ({a,b})
> 2'b00: begin
> ns = s0;
> default: begin
> ns = s0;
> s = 0;
> end
> endcase
> end
> default: begin
> ns = s0;
> end
> endcase
> end
>
> endmodule


Related Solutions

Write the VERILOG code for an arithmetic/logic unit (ALU) with a test bench that does the...
Write the VERILOG code for an arithmetic/logic unit (ALU) with a test bench that does the following with 4 bit inputs , and can be tested in on nexys 4 board This is to be implement on : ISE Design Suite - Xilinx /* ALU Arithmetic and Logic Operations ---------------------------------------------------------------------- |ALU_Sel| ALU Operation ---------------------------------------------------------------------- | 0000 | ALU_Out = A + B; ---------------------------------------------------------------------- | 0001 | ALU_Out = A - B; ---------------------------------------------------------------------- | 0010 | ALU_Out = A * B;...
Can anyone write a Verilog code and a test bench for a universal shift register with...
Can anyone write a Verilog code and a test bench for a universal shift register with 4 bits using D flip flop? Thanks
Using the conditional assignment statements, write the verilog code for 16:1 Mux. Write the test bench...
Using the conditional assignment statements, write the verilog code for 16:1 Mux. Write the test bench for this module.
code an 8 bit LFSR random number generator in system verilog. Write a test bench, load...
code an 8 bit LFSR random number generator in system verilog. Write a test bench, load the seed 11111111, and generate the first 10 random numbers.
First, draw the state machine for the following program. Then write the corresponding Verilog behavioral code....
First, draw the state machine for the following program. Then write the corresponding Verilog behavioral code. Input: X - 1 bit number Output: Z - 1 bit number Clock: clk (State will change at positive edge of the clock) Output will be equal to one if Xn-2 Xn-1 Xn = 011 or Xn-2 Xn-1 Xn = 101
Implement a 4x4 multiplier using gate level (verilog code and test bench)
Implement a 4x4 multiplier using gate level (verilog code and test bench)
Implement a JK Flip flop using behavioral modeling in verilog, also write its test bench code.
Implement a JK Flip flop using behavioral modeling in verilog, also write its test bench code.
use modelsim write Verilog code for the following digital logic circuits and then simulate them by...
use modelsim write Verilog code for the following digital logic circuits and then simulate them by writing a testbench module for each of them , (a)The FSMs for the snail problem that is in the slides (a snail crawls over a tape that has 0 and 1 and smiles if it has detected the '10' bits using both Moore and Mealy FSM. Note that the pattern is '10' not '01' as in the slides. (b) A rock-paper-scissor game played by...
Design B: Using behavioral VHDL, design a Mealy-type finite state machine that detects input test vector...
Design B: Using behavioral VHDL, design a Mealy-type finite state machine that detects input test vector that contains the sequence of ‘10’. If the sequence ‘10’ is detected, the output Z should go high. The input is to be named W, the output is to be named Z, a Clock input is to be used and an active low reset signal (Resetn) should asynchronously reset the machine. a) Draw the Mealy-type state diagram for the FSM. b) Write the VHDL...
verilog code of a 64 x64 array with 128 parameters please include test bench
verilog code of a 64 x64 array with 128 parameters please include test bench
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT