Question

In: Electrical Engineering

Consider a finite state machine with a control input called mode. When mode = 0, the...

Consider a finite state machine with a control input called mode. When mode = 0, the machine operates as a mod-3 down counter, where the outputs are the count values. When mode = 1, the machine's output progresses through the last 4 digits of your WCU ID (1133) number (1 digit per clock cycle). Complete each of the steps which follow.

(a) Draw the state diagram for this machine.
(b) Write RTL Verilog code which implements this design. Submit your printed source code by the due date and time.
(c) Create a test bench to exercise the design through all of its states and functions. Submit your test bench source code and a simulation waveform. The simulation waveform must show the digits of your WCU ID and no one else's.

Solutions

Expert Solution

(b)


module fsm (clock, mode, Q);

input clock, mode;

output reg [1:0] Q;

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

reg [2:0] current_state, next_state = 3'b000;

always @ (posedge clock)

begin

   current_state <= next_state;

end

always @ (current_state, mode)

begin

   case (current_state)
       S0: next_state <= S1;
       S1: if (mode == 1'b1) next_state <= S3; else next_state <= S2;      
       S2: if (mode == 1'b1) next_state <= S1; else next_state <= S0;      
       S3: if (mode == 1'b1) next_state <= S4; else next_state <= S0;      
       S4: if (mode == 1'b1) next_state <= S5; else next_state <= S0;      
       S5: if (mode == 1'b1) next_state <= S1; else next_state <= S0;
   default : next_state <= S0;
   endcase

end

always @ (current_state)

begin

   case (current_state)
       S0: Q <= 2'b00;
       S1: Q <= 2'b01;      
       S2: Q <= 2'b10;      
       S3: Q <= 2'b01;      
       S4: Q <= 2'b11;      
       S5: Q <= 2'b11;
   default : Q <= 2'b00;
   endcase

end

endmodule

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
(c)


module tb_fsm ();

reg clock, mode;

wire [1:0] Q;

fsm uut (clock, mode, Q);

initial begin

clock = 1'b0;

mode = 1'b0;

#100;

mode = 1'b1;

#50;

mode = 1'b0;  

end

always #5 clock = ~clock;

endmodule


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


Related Solutions

Using behavioral VHDL, design a Moore-type finite state machine that detects input test vector that contains...
Using behavioral VHDL, design a Moore-type finite state machine that detects input test vector that contains the sequence of ‘100’. If the sequence ‘100’ 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 Moore-type model state diagram for the FSM. b) Write the VHDL code...
Using behavioral VHDL, design a Mealy-type finite state machine that detects input test vector that contains...
Using behavioral VHDL, design a Mealy-type finite state machine that detects input test vector that contains the sequence of ‘100’. If the sequence ‘100’ 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 code to...
Consider the finite state machine shown below that controls a two story elevator. The elevator has...
Consider the finite state machine shown below that controls a two story elevator. The elevator has a toggle button that can be in the UP position or the DOWN position, and an LED light that can be RED or GREEN . When the elevator is on the GROUND floor the light is RED, and when the elevator is on the FIRST floor the light is GREEN. Assume the existence of function enum Button getButton(); that returns a value of DOWN...
In C code Consider the finite state machine shown below that controls a two story elevator....
In C code Consider the finite state machine shown below that controls a two story elevator. The elevator has a toggle button that can be in the UP position or the DOWN position, and an LED light that can be RED or GREEN . When the elevator is on the GROUND floor the light is RED, and when the elevator is on the FIRST floor the light is GREEN. Assume the existence of function enum Button getButton(); that returns a...
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...
Design a system with one input called “Up” such that when “Up” equals 1, the machine...
Design a system with one input called “Up” such that when “Up” equals 1, the machine counts 2, 3, 4, 5, 6, and repeat. If the “Up” input equals 0, the machine counts down 6, 5, 4, 3, 2, and repeat. Show the State Transition Diagram, State Transition table, K-maps, and equations assuming JK flip flops and AND/OR/NOT combinational logic. Make sure to indicate on your State Transition Diagram what happens if the system initially is in one of the...
What is a finite-state machine ? What is a pushdown automaton ? What is a Turing...
What is a finite-state machine ? What is a pushdown automaton ? What is a Turing machine? What is a Turing complete language? Compare the finite-state machine , pushdown automaton , and Turing machine.?
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.
Code the FSM in C++, and show that the program works. Construct a Finite State Machine...
Code the FSM in C++, and show that the program works. Construct a Finite State Machine that models an old-fashioned soda machine that accepts nickels, dimes, and quarters. The soda machine accepts change until 35 cents have been put in. It gives change back for any amount greater than 35 cents. Then the customer can push buttons to receive either a cola, a root beer, or a ginger ale.
Write a VHDL code to implement a Finite State Machine that with an 8 bit sequence...
Write a VHDL code to implement a Finite State Machine that with an 8 bit sequence input (can be any sequence, but lets say it is 11001000), determine how many states there are as well; so if the input sequence is correct it will show the number 1 in a 7 segment display, otherwise it will be 0 in the same 7 segment display. If the input sequence is incorrect, start from the beginning.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT