Question

In: Electrical Engineering

Write Verilog code for a Moore detector that detects sequences 10111 and 10101 on its j...

Write Verilog code for a Moore detector that detects sequences 10111 and 10101 on its j input and creates a pulse of exactly one clock duration on its output. The output becomes 1 if either of the sequences, or an overlap of the two is detected. A) Show the state diagram of this machine. B) Write complete Verilog for the design. C) Write a testbench and test your state machine using ModelSim.

Solutions

Expert Solution

B.

module moore_detector ( input clk, data_in, reset,
output reg detected
);

reg [2:0] state;
parameter S0=0, S1=1, S2=2, S3=3, S4=4, S5=5, S6=6;

always @ (posedge clk or reset) begin
if (reset)
state <= S0;
else
case (state)
S0: if (data_in) state <= S1; else state <= S0;
S1: if (data_in) state <= S1; else state <= S2;
S2: if (data_in) state <= S3; else state <= S0;
S3: if (data_in) state <= S4; else state <= S5;
S4: if (data_in) state <= S6; else state <= S2;
S5: if (data_in) state <= S6; else state <= S0;
S6: if (data_in) state <= S1; else state <= S2;
default: state <= S0;
endcase
end
  
always @ (state) begin
case (state)
S0: detected = 1'b0;
S1: detected = 1'b0;
S2: detected = 1'b0;
S3: detected = 1'b0;
S4: detected = 1'b0;
S5: detected = 1'b0;
S6: detected = 1'b1;
default: detected = 1'b0;
endcase
end

endmodule

C.

module tb_moore;

// Inputs

reg clk;

reg data_in;

reg reset;

// Outputs

wire detected;

// Instantiate the Unit Under Test (UUT)

moore_detector uut (

.clk(clk),

.data_in(data_in),

.reset(reset),

.detected(detected)

);

initial begin

// Initialize Inputs

clk = 0;

data_in = 0;

reset = 1;

// Wait 100 ns for global reset to finish

#100;

  

// Add stimulus here

end

always begin

#10 clk = ~clk;

end

always begin

reset = 1'b0;

data_in = 1'b0;

#20;

data_in = 1'b1;

#20;

data_in = 1'b0;

#20;

data_in = 1'b1;

#20;

data_in = 1'b0;

#20;

data_in = 1'b1;

#20;

data_in = 1'b0;

#20;

data_in = 1'b0;

#20;

data_in = 1'b0;

#20;

end

  

endmodule


Related Solutions

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=...
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
imulate/ code in verilog: Develop an electronic key system using the FSM (moore) methology. Use from...
imulate/ code in verilog: Develop an electronic key system using the FSM (moore) methology. Use from student ID and use the last 4 digits:(0864) if the number is <5 then = 1 if the number is >=5 then = 0 example: 8012345. Take last 4 digits (2345) which makes it 0001. In my case, the last 4 digits are 0864, which makes it 0110 features of FSM (moore FSM): input 4 bits serially, if the sequence is correct, then you...
Write a Verilog code to implement 16 bit LFSR
Write a Verilog code to implement 16 bit LFSR
Write Verilog code using for 3:8 Decoders with Quartus-II CAD software?? and write code of Full...
Write Verilog code using for 3:8 Decoders with Quartus-II CAD software?? and write code of Full adder using 2 half adder ?
Write a verilog code for 5 to 8 multiplier using fourbit adder
Write a verilog code for 5 to 8 multiplier using fourbit adder
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.
design a sequence detector that detects the sequence: 110. The device has one input x and...
design a sequence detector that detects the sequence: 110. The device has one input x and one output Y. When the input sequence is set to 1 followed by a 1 followed by a 0, then Y is set to 1 otherwise Y is set to 0. Use J-K flip-flops and minimum number of states is designing this detector and show the followings: a) Show the state diagram b)Show the state table for this detector
Currently, this model detects the overlapping sequence "101" ----> REDESIGN the Moore FSM below to detect...
Currently, this model detects the overlapping sequence "101" ----> REDESIGN the Moore FSM below to detect the NEW sequence "011" , simulate using the same test bench, and create a Moore Transition Diagram for the new sequence 011. module moore_seq (    input clock, reset, x,    output reg z ); //assign binary encoded codes to the states A through D parameter    A = 2'b00,    B = 2'b01,    C = 2'b10,    D = 2'b11; reg [1...
write a verilog code to implement a digital system that has an odd counter that counts...
write a verilog code to implement a digital system that has an odd counter that counts from 1 to 11. Also, this system has an output Y that detects a specific number in the odd counter. Test your code when you detect the number 3, the output Y is 1, if the counter value is set to 3, otherwise 0.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT