CSC347-ENS211 – Lab 12 Wheel-of-Fortune (Solution)

$ 20.99
Category:

Description

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

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

2. 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

3. 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

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

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
// Link to your project
3. Copy the link of your design from the address bar of the browser.
4. 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

Reviews

There are no reviews yet.

Be the first to review “CSC347-ENS211 – Lab 12 Wheel-of-Fortune (Solution)”

Your email address will not be published. Required fields are marked *