Question

In: Computer Science

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

Solutions

Expert Solution

Please please give me a thumbs up sir:

•Code for detecting 011 and 101 :

// Code your design here

module det( input clk,

input rstn,

input X,

output Z );

parameter S0 = 0,

S1 = 1,

S2 = 2,

S3 = 3,

S4 = 4; // defining states as parameters

reg [2:0] cur_state, next_state; //defining states as registers

reg Z;

always @ (posedge clk) begin

if (!rstn) begin

cur_state <= S0;

assign Z=0;

end

else

begin

cur_state <= next_state;

assign Z=0;

end

end

always @ (cur_state or X) begin

case (cur_state) // assigning next states and output

S0: begin

if (X) begin next_state <= S3;

assign Z=0;

end

else begin next_state <= S1;

assign Z=0;

end

end

S1: begin

if (X) begin next_state <= S2;

assign Z=0;

end

else begin next_state <= S1;

assign Z=0;

end

  

end

S2 : begin

if (X) begin next_state <= S3;

assign Z=1;

end

else begin next_state <= S0;

assign Z = 0;

end

  

end

S3: begin

if (X) begin next_state <= S2;

assign Z=0;

end

else begin next_state <= S4;

assign Z=0;

end

end

S4: begin

if (X) begin next_state <= S3;

assign Z = 1;

end

else begin next_state <= S0;

assign Z =0;

end

  

end

endcase

end

endmodule

•Testbench;

// Code your testbench here

// Code your testbench here

module tb;

reg clk,X,rstn;

wire Z;

det dut(.clk(clk),

.rstn(rstn),

.X(X),

.Z(Z));

initial

clk=1'b0;

always

#20clk=~clk;

initial

begin

X=0;

rstn=1;

  

#20

X=0;

rstn=0;

  

#20

X=1;

rstn=0;

  

#20

X=1;

rstn=0;

  

#20

X=0;

rstn=0;

  

#20

X=0;

rstn=0;

#20

X=1;

  

#20

X=0;

  

#20

X=1;

#20

X=0;

#20

X=0;

#20

X=1;

#20

X=1;

#20

X=0;

#20

X=0;

#20

X=0;

#20

X=0;

end

initial

  

#1300 $finish;

  

initial

  

begin

  

$dumpfile("dump.vcd");

  

$dumpvars;

  

end

endmodule


Related Solutions

draw state machine and write verilog code of an ALU unit that shifts left when the...
draw state machine and write verilog code of an ALU unit that shifts left when the control signal 'OP' is 00, shifts right when control is ''01'' and increments when control is ''10''. Fpr control ''11'' , it does nothing. inputs are Date [3:0] and clk, and the output is Out [3:0]
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
Design a Verilog code for 64x64 array multiplier. Use behavioral Verilog description with full adders and/or...
Design a Verilog code for 64x64 array multiplier. Use behavioral Verilog description with full adders and/or half adders. Please include testbench
Now considering an SR NAND latch as a finite state machine, please draw the corresponding state...
Now considering an SR NAND latch as a finite state machine, please draw the corresponding state transition diagram. You don’t have to show the outputs in the diagram.
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.
Analyze the following Verilog code and write down its output as pictured in the code. module...
Analyze the following Verilog code and write down its output as pictured in the code. module blocking; reg [0:7] A, B; initial begin: init1 A = last decimal digit of your ID; #1 A = A + 1; // blocking procedural assignment B = A + 1; $display("Output 1: A= %b B= %b", A, B ); A = last decimal digit of your ID; #1 A <= A + 1; B <= A + 1; #1 $display ("Output 2: A=...
Question: In the following MIPS assembly code, translate all the instructions to their corresponding machine code...
Question: In the following MIPS assembly code, translate all the instructions to their corresponding machine code in hexadecimal format. This code is stored in the memory from address 0x2fff0004. Loop: lw $t0, 4($s0)             addi $t1, $t1, -15             sll $t1, $t1, 2             beq $t1, $s1, Exit             addi $s0, $s0, 4             j Loop Exit: …
Write down the VERILOG code for an XOR gate and the testbench code to test it
Write down the VERILOG code for an XOR gate and the testbench code to test it
Please code C# 10. Write a program that allows a user to input names and corresponding...
Please code C# 10. Write a program that allows a user to input names and corresponding heights (assumed to be in inches). The user can enter an indefinite number of names and heights. After each entry, prompt the user whether they want to continue. If the user enters true, ask for the next name and height. If the user enters false, display the name of the tallest individual and their height. Sample run: “Name?” James “Height?” 50 “Continue?” True “Name?”...
1.Write verilog code for a 8:1 Mux using the blocks of 2:1 Mux; Draw the block...
1.Write verilog code for a 8:1 Mux using the blocks of 2:1 Mux; Draw the block diagram for this design and write the truth table to prove that the design works as intended. 2. Write verilog code for a 16:1 Mux using the blocks of 4:1 Mux; Draw the block diagram for this design and write the truth table to prove that the design works as intended.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT