# CSC347-ENS211 Lab 12-Wheel-of-Fortune Solved

30.00 \$ 15.00 \$

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: . ` zip` solution files instantly, after Payment

## Description

Rate this product

Objective

In this lab you will use a register and a counter to design a simple electric wheel of fortune game machine.

Introduction

The wheel of fortune you are designing works as follows. At the startup, the LED lights continuously rotate around using a bit pattern “00000001”, and at the same time the seven segment display continuously increments at a fast speed. The digit starts from 0000 and increments to FFFF and repeats. When a user presses a stop button, the LED rotation stops and the seven segment displays the number caught at the positive transition of the stop button press. When the user releases the button, it starts the whole process again, i.e., the LED lights rotates around, and the seven segment display increments the four digit hex number at a fast speed. The LED movements should be slow enough to be visible. However, the numbers on the seven segment display should be fast enough, so that it is hard to recognize except when it is stopped. In order to accomplish this, we need to create the following modules

• A ring counter (or shift register) to rotate LEDs
• A counter to increment number

The diagram of the system is shown below:

Lab Procedure

1. Build an 8-bit ring counter

A ring counter is a Shift Register (a cascade connection of flip-flops) with the output of the last flip flop connected to the input of the first. It is initialized such that only one of the flip flop output is 1 while the reminder is 0. The 1 bit is circulated so the state repeats every 8 clock cycles. Below is the circuit for an 8-bit ring counter. A skeleton of the Verilog description is provided, with some details missing. Your task is to fill in the blanks.

module ring_counter(clk, reset, stop, direction, Q);

input clk, reset, stop, direction;

output [7:0] Q;

reg [7:0] Qtemp = 8’b00000001;

always @(posedge clk)

begin

if (reset == 1’b1)

Qtemp <= 8’b00000001;

else if (stop == 1’b1)

Qtemp <= 8’b00000001;

else if (direction == 1’b1)

Qtemp <= {Qtemp[0],Qtemp[7:1]};    //shifting right

else

Qtemp <= {Qtemp[6:0],Qtemp[7]};    //shifting left

end

assign Q = Qtemp;

endmodule

1. Build a bidirectional (up/down) counter.

Bidirectional counters, also known as Up/Down counters, are capable of counting in either up or down direction through any given count sequence and they can be reversed at any point within their count sequence by using an additional control input as shown below. Also the counter should have the functions to reset the count to zero, and stop counting. Again, a skeleton of the Verilog description of the counter is provided, with some details erased. Your task is to fill in the blanks.

module counter(clk, reset, stop, direction, count);

input clk, direction;  // clock, direction for counting up or down

input reset, stop;

output reg [3:0] count=0;

always @(posedge clk)

begin

if (reset == 1’b1)

count <= 0; // reset the counter

else if (stop == 1’b1)

count <= count; // do nothing

else if (direction == 1’b1)

count <= count + 1; // count up

else

count <= count – 1; // count down

end

endmodule

1. Build top-level LED wheel of fortune

Based on the diagram in the first page, write Verilog code to implement the wheel of fortune circuit. Once again, a skeleton of the Verilog description is provided, with some details erased. Fill in the blanks so your Verilog description exactly matches the circuit in the first page.

module wheeloffortune(clock, reset, stop, direction, LEDs, count);

input clock, reset, stop, direction;

output [7:0] LEDs;

output [3:0] count;

ring_counter U1(clock, reset, stop, direction, LEDs);  // instantiate the ring counter

counter U2(clock, reset, stop, direction, count);  // instantiate counter

endmodule

1. Testbench: create a Verilog testbench to test your wheel of fortune module and perform the simulation to check if it is working.
2. module test;
3. reg clock, reset, stop, direction; // input
4. wire [7:0] LEDs; // output
5. wire [3:0] count; // output
6. wheeloffortune uut(clock, reset, stop, direction, LEDs, count); // instantiate the module
7.      initial
8.         begin
9.         clock = 0; // start the simulation
10.         forever  #5 clock = ~clock;  // toggle clock
11.         #500 \$finish;  // stop the simulation
12.      end
13.   initial begin
14.       \$dumpfile(“dump.vcd”); \$dumpvars(1, test); // create a waveform file
15.       \$monitor( “stop= %b, LEDs = %b, count= %b”, stop, LEDs, count);  // print the outputs
16.        // Initialize Inputs
17.          reset = 1;              // reset the circuit
18.          stop = 0;               // stop the simulation
19.          direction = 1;          // counting up
20.          #23  reset = 0;         // disable reset, start counting
21.          #80  stop = 1;          // pause counting and light movement
22.          #20  stop = 0;          // resume counting and light movement
23.          #20 direction =0;       // change direction of moving lights and couting
24.          #150 stop = 1;          // pause counting and light movement
25.          #20  stop = 0;          // resume counting and light movement
26.          #50  reset = 1;         // reset the circuit
27.          #20 \$finish;            // stop the simulation
28.         end
29. endmodule

Submission Instructions:

Lab work submission

1. Take a screenshot of your wavefroms.
2. Add the following information as comments to the beginning of your code. Make sure to click the “Save” button to save your project, then take a screenshot of your code.

// Author:    Name

// Lab 12:  Wheel-of-Fortune

2. On the Blackboard, click on Lab 12. Attach the screenshots from the first two steps and paste the link from Step 3 into the Comments area, then click the “Submit” button.

No report is needed for this lab.

https://www.edaplayground.com/x/mtrR

// Author: Gianna Rose

// Lab 12

// https://www.edaplayground.com/x/mtrR

module test;

reg clock, reset, stop, direction; // input

wire [7:0] LEDs; // output

wire [3:0] count; // output

wheeloffortune uut(clock, reset, stop, direction, LEDs, count); // instantiate the module

initial

begin

clock = 0; // start the simulation

forever  #5 clock = ~clock;  // toggle clock

#500 \$finish;  // stop the simulation

end

initial begin

\$dumpfile(“dump.vcd”); \$dumpvars(1, test); // create a waveform file

\$monitor( “stop= %b, LEDs = %b, count= %b”, stop, LEDs, count);  // print the outputs

// Initialize Inputs

reset = 1;              // reset the circuit

stop = 0;               // stop the simulation

direction = 1;          // counting up

#23  reset = 0;         // disable reset, start counting

#80  stop = 1;          // pause counting and light movement

#20  stop = 0;          // resume counting and light movement

#20 direction =0;       // change direction of moving lights and couting

#150 stop = 1;          // pause counting and light movement

#20  stop = 0;          // resume counting and light movement

#50  reset = 1;         // reset the circuit

#20 \$finish;            // stop the simulation

end

endmodule

// Author: Gianna Rose

// Lab 12

// https://www.edaplayground.com/x/mtrR

module ring_counter(clk, reset, stop, direction, Q);

input clk, reset, stop, direction;

output [7:0] Q;

reg [7:0] Qtemp = 8’b00000001;

always @(posedge clk)

begin

if (reset == 1’b1)

Qtemp <= 8’b00000001;

else if (stop == 1’b1)

Qtemp <= 8’b00000001;

else if (direction == 1’b1)

Qtemp <= {Qtemp[0],Qtemp[7:1]};    //shifting right

else

Qtemp <= {Qtemp[6:0],Qtemp[7]};    //shifting left

end

assign Q = Qtemp;

endmodule

module counter(clk, reset, stop, direction, count);

input clk, direction;  // clock, direction for counting up or down

input reset, stop;   // reset, stop signal

output reg [3:0] count = 0; // output register

always @(posedge clk)

begin

if (reset == 1’b1)

count <= 0; // reset the counter

else if (stop == 1’b1)

count <= count; // do nothing

else if (direction == 1’b1)

count <= count + 1; // count up

else

count <= count – 1; // count down

end

endmodule

module wheeloffortune(clock, reset, stop, direction, LEDs, count);

input clock, reset, stop, direction;

output [7:0] LEDs;

output [3:0] count;

ring_counter U1(clock, reset, stop, direction, LEDs);  // instantiate the ring counter

counter U2(clock, reset, stop, direction, count);  // instantiate counter

endmodule