Question

Design a Verilog model that describes the following state diagram. (Test bench and simulation are not required) 1. 01 10 1- 1
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer 1)

Verilog code

module state_diagram_moore (clk, rst, x, z);
input clk;
input rst;
input [1:0] x;
output [1:0] z;

parameter D = 2'b00,
A = 2'b01,
B = 2'b10,
C = 2'b11;

//Internal reg and wires decalarations
reg [2:0] cur_state, next_state;

// current state logic
always @(posedge clk)
begin
if(rst)
cur_state <= A;
else
cur_state <= next_state;
end

// Logic for next state and output
always @(*)
begin
case(cur_state)
A : begin
if (x == 2'b00)
next_state = C;
else if ((x == 2'b01) || (x == 2'b10))   
next_state = D;
end

B : begin
if (x == 2'b01)
next_state = A;
else if (x == 2'b10)   
next_state = B;
end

C : begin   
if (x == 1'b1)
next_state = D;
else if (x == 2'b00)
next_state = B;
else if (x == 2'b01)   
next_state = C;
end

D : begin
if (x == 2'b00)
next_state = B;
else if (x == 2'b01)   
next_state = D;
else if (x == 2'b10)   
next_state = C;
end

default : begin next_state = A; end
endcase
end

assign z = cur_state;

endmodule

Answer 2)

Verilog Code


module bin_gray_counter (clk, rst, M, count);
input clk;
input rst;
input M;
output [2:0] count;

parameter S0 = 3'b000,
S1 = 3'b001,
S2 = 3'b010,
S3 = 3'b011,
S4 = 3'b100,
S5 = 3'b101,
S6 = 3'b110,
S7 = 3'b111;

//Internal reg and wires decalarations
reg [2:0] cur_state, next_state;

// current state logic
always @(posedge clk)
begin
if(rst)
cur_state <= S0;
else
cur_state <= next_state;
end

// Logic for next state and output
always @(*)
begin
case(cur_state)
S0 : begin next_state = M ? S1 : S1 ; end
S1 : begin next_state = M ? S3 : S2 ; end
S2 : begin next_state = M ? S6 : S3 ; end
S3 : begin next_state = M ? S2 : S4 ; end
S4 : begin next_state = M ? S0 : S5 ; end
S5 : begin next_state = M ? S4 : S6 ; end
S6 : begin next_state = M ? S7 : S7 ; end
S7 : begin next_state = M ? S5 : S0 ; end
endcase
end

assign count = cur_state;

endmodule

Testbench for above code

module testbench;
reg clk, rst;
reg M;
wire [2:0] count;

bin_gray_counter DUT (.clk(clk), .rst(rst), .M(M), .count(count));

always
#5 clk = !clk;

initial
begin
clk = 1'b0;
rst = 1'b1;
M = 1'b0;
repeat(2)
@(negedge clk);
rst = 1'b0;
M = 1'b0;
repeat(16)
@(negedge clk);
M = 1'b1;
repeat(16)
@(negedge clk);
M = 1'b0;
repeat(7)
@(negedge clk);
$finish;
end
  
initial
begin
$recordfile("file1.trn");
$recordvars();
end

endmodule

@ Baseline▼.0 i Cursor-Baseline-55,000,000f Baseline - 100,000,000fs 200,000,000fs 0,000,000fs Name Cur 1 12 3 4 5 6 7 0 1 2

Add a comment
Know the answer?
Add Answer to:
Design a Verilog model that describes the following state diagram. (Test bench and simulation are not required) 1. 01 10 1- 10 10 01 01 10 or 01) 01 Design a Verilog model that describes a synchr...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (4 pts) Write a behavioral Verilog module to implement a counter that counts in the following seq...

    Verilog! NOT VHDL Please (4 pts) Write a behavioral Verilog module to implement a counter that counts in the following sequence: 000, 010, 100, 110, 001, 011, 101, 111, (repeat) 000, etc. Use a ROM and D flip-flops. Create a test bench for your counter design and run functional simulation in ModelSim. (4 pts) Write a behavioral Verilog module to implement a counter that counts in the following sequence: 000, 010, 100, 110, 001, 011, 101, 111, (repeat) 000, etc....

  • C. The task is to create a complex counter that can count in binary or in...

    C. The task is to create a complex counter that can count in binary or in Gray code, depending on the value of a mode input: "A synchronous 3-bit counter has a mode control input m. When m = 0, the counter steps through the binary sequence 000, 001,010, 011, 100, 101, 110, 111, and repeat. When m = 1, the counter advances through the Gray code sequence 000, 001,011, 010, 110, 111, 101, 100, and repeat. (USE JK FLIP...

  • Design a synchronous counter that has the following sequence: 000, 010, 101, 110 and repeat. The...

    Design a synchronous counter that has the following sequence: 000, 010, 101, 110 and repeat. The undesired states 001, 011, 100 and 111 must always go to 000 on the next clock pulse.

  • Can anyone solve this? i dont understand? verilog 1. (30 pts) Design a mod-6 counter. A...

    Can anyone solve this? i dont understand? verilog 1. (30 pts) Design a mod-6 counter. A mod-6 counter updates its output per clock rising edge according to the following sequence: 000, 001, 010, 011, 100, 101 (then repeat the pattern....). en is enable control (synchronous high active), resetn is reset control (asynchronous low active signal to reset counting sequence to 000) Complete the following Verilog code: en module mod6(clock, resetn, en, z); zI2:0] clock resetn Endmodule

  • Use D flip-flops to design a 3-bit counter

    Use D flip-flops to design a 3-bit counter which counts in the sequence: 110, 100, 101, 111, 011, 010, 001, (repeat) 110, . . .   In this case, what will happen if the counter is started in state 000?

  • Question 4 State Machines (25 marks) a. (5 marks) A 3-bit Gray code counter advances on...

    Question 4 State Machines (25 marks) a. (5 marks) A 3-bit Gray code counter advances on positive clock edges and generates outputs in the sequence: 000, 001, 011, 010, 110, 111, 101, 100. Draw the assigned state table for a state machine implementing this counter. b. (10 marks) For the Gray code counter in part a, derive (unoptimised) equations for the next state as a function of the current state. c. (10 marks) Consider the following sequence detector. In each...

  • Finite state machine (FSM) counter design: Gray codes have a useful property in that consecutive numbers differ in only a single bit position. Table 1 lists a 3-bit modulo 8 Gray code representing the...

    Finite state machine (FSM) counter design: Gray codes have a useful property in that consecutive numbers differ in only a single bit position. Table 1 lists a 3-bit modulo 8 Gray code representing the numbers 0 to 7. Design a 3-bit modulo 8 Gray code counter FSM. a) First design and sketch a 3-bit modulo 8 Gray code counter FSM with no inputs and three outputs, the 3-bit signal Q2:0. (A modulo N counter counts from 0 to N −...

  • -Design a synchronous counter using D FFs that has the following sequence: 000, 010, CBA 101,...

    -Design a synchronous counter using D FFs that has the following sequence: 000, 010, CBA 101, 110, and repeat. The undesired (unused) states must always go to 000 on the next clock pulse. СВА 001 0,1,2 3,4,5 6,7,8,9 100 111

  • will give thumbs up need answer asap P3.94pts Implement a 3-bit synchronous gray code down-counter with...

    will give thumbs up need answer asap P3.94pts Implement a 3-bit synchronous gray code down-counter with positive-edge-triggered D flip-flops using graphical symbols of D flip-flops and any logic gates. You can refer to the table below to understand the 3-bit gray code (The desired behavior is as follows: 000 100 101 111 - 110 - 010011001 → 000 → ...). Decimal 1 Gray code 000 001 011 010 110 111 101 100 5 6

  • verilog code needed for the counter using the JK flip flop please include the testbench, thanks!...

    verilog code needed for the counter using the JK flip flop please include the testbench, thanks! Successfully completing a System Verilog +80Pts. Implementation showing the full sequence of ABC readouts Pre-Laboratory Exercise: You are to design a counter that will count through a sequence either forward or reverse. You will have two control inputs: Direction, and Reset'. Sequence #2: 000 100 110 111 101001 → 011 010 → 000... {Gray code} When Direction=0 follow the order listed above. When Direction...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT