Question

In: Electrical Engineering

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 two users (A and B) to indicate who's won or draw then they input their choice. Hint: A's output is 1 if A has won, both A's and B's signals is 0 if it was a draw.

Solutions

Expert Solution

Verilog code:-

module morfsm(din, reset, clk, y);
output reg y;
input din;
input clk;
input reset;
reg [1:0] cst, nst;
parameter S0 = 2'b00,
          S1 = 2'b01,
          S2 = 2'b10,
always @(cst or din)
 begin
 case (cst)
   S0: if (din == 1'b1)
          begin
         nst = S1;
          y=1'b0;
          end
      else
          begin
          nst = cst;
          y=1'b0;
          end  
S1: if (din == 1'b0)
          begin
        nst = S2;
          y=1'b0;
          end
       else
          begin
          nst = cst;
          y=1'b0;
          end
S2: if (din == 1'b1)
          begin
         nst = S1;
          y=1'b1;
          end    
            else
          begin
          nst = S0;
          y=1'b1;
          end  
   default: nst = S0;
  endcase
end
always@(posedge clk)
begin
 if (reset)
   cst <= S0;
 else
   cst <= nst;
end
endmodul:-

Test Bench:-

module morfsm_tb;
reg din,clk,reset;
wire y;
morfsm m1(din, reset, clk, y);
initial
begin
reset=0       ;clk=0;din=0;
$monitor($time, , ,"c=%b",clk,,"y=%b",y,,"r=%b",reset,,"d=%b",din);
#10 din=1;
#10 din=1;
#10 din=1;
#10 din=0;
#10 din=1;
#10 din=0;
#10 din=1;
#10 din=0;
#10 din=1;
//#5 reset=1;
//#5 reset=0;

end
always
#5 clk=~clk;
initial
#100 $finish ;
endmodule

Verilog Code:-


module melfsm(din, reset, clk, y);
output reg y;
input din;
input clk;
input reset;
reg [1:0] cst, nst;
parameter S0 = 2'b00,
          S1 = 2'b01,
          S2 = 2'b10,
always @(cst or din)
begin
case (cst)
   S0: if (din == 1'b1)
          begin
         nst = S1;
          y=1'b0;
          end
      else
          begin
          nst = cst;
          y=1'b0;
          end
S1: if (din == 1'b0)
          begin
        nst = S0;
          y=1'b1;
          end
       else
          begin
          nst = cst;
          y=1'b0;
          end
   default: nst = S0;
endcase
end
always@(posedge clk)
begin
if (reset)
   cst <= S0;
else
   cst <= nst;
end
endmodule

Test Bench:-

module melfsm_tb;
reg din,clk,reset;
wire y;
melfsm m1(din, reset, clk, y);
initial
begin
reset=0       ;clk=0;din=0;
$monitor($time, , ,"c=%b",clk,,"y=%b",y,,"r=%b",reset,,"d=%b",din);
#5 din=1;
#5 din=1;
#5 din=1;
#10 din=0;
#10 din=1;
#10 din=0;
#10 din=1;
#10 din=0;
#5 din=1;
//#5 reset=1;
//#5 reset=0;

end
always
#5 clk=~clk;
initial
#80 $finish ;
endmodule

Related Solutions

Write the VERILOG code for an arithmetic/logic unit (ALU) following , and can be tested in...
Write the VERILOG code for an arithmetic/logic unit (ALU) following , 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; ---------------------------------------------------------------------- | 0011 | ALU_Out = A / B; ---------------------------------------------------------------------- |...
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
In digital logic circuits, what are the maximum number of inputs for the following gates: AND...
In digital logic circuits, what are the maximum number of inputs for the following gates: AND OR NOR XOR(is it 2?) XNOR (is it 2?) NAND
Digital Logic Design Lab Prove the following Boolean Algebra theorems and properties by constructing Logic Circuits...
Digital Logic Design Lab Prove the following Boolean Algebra theorems and properties by constructing Logic Circuits for each theorem/properties using our educational simulation software: Q1-a) The Distributive Property:     a + ( b . c ) = ( a + b ) . ( a + c ) Q1-b) The Distributive Property:     a . ( b + c ) = ( a . b ) + ( a . c )
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;...
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.
Using the principles and components of digital and linear logic circuits design a circuit that is...
Using the principles and components of digital and linear logic circuits design a circuit that is able to open and close the door of a garage of vehicles according to the following conditions: a) The door will open in the following cases: a.1) a manual push-button is activated and there is sunlight. a.2) the button is not activated, there is no sunlight and the light of a vehicle is detected. b) The door must close after 30 seconds of opening....
write an Arithmetic Logic Unit (ALU) in verilog.
write an Arithmetic Logic Unit (ALU) in verilog.
Write a verilog code for digital clock and display it’s seven segment using fpga?
Write a verilog code for digital clock and display it’s seven segment using fpga?
1. a) Given the two Verilog code segments, derive the schematics for the logic that will...
1. a) Given the two Verilog code segments, derive the schematics for the logic that will be synthesized from these blocks. BLOCK 1 input Y; reg A, B; always @(posedge clk) begin A = Y; B = A; end BLOCK 2 input Y; reg A, B; always @(posedge clk) begin A <= Y; B <= A; end b) Define setup time by using timing diagrams. Explain what would happen if any one of these timing requirements are violated. c) Describe...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT