21BLC1374 Lab4
21BLC1374 Lab4
Submitted By
21BLC1374 – Pranav Pratap Patil
Submitted To
Dr. Sahthivel S M
DATE: 12/08/2024
[21BLC1374] Lab 4 – Four Bit Up-Down Counter 12/08/2024
Slot: L33+L34
LAB - 4
Four Bit Up-Down Counter
AIM: To Design a 4bit Up-Down Counter, Interface it with a BCD to 7-segment display and
utilizing a clock divider to ensure readability of the output in both Up and Down Modes and
implement on the DE2-115 board.
Hardware Required: Altera Cyclone IV E DE2-115 Kit, USB Cable, Power Supply
Procedure:
1. Start Quartus Prime Lite Edition.
2. Go To : File → New Project Wizard.
3. Set The Working Directory and Name of the Project and Create an Empty Project.
4. Set Family to “Cyclone IV E”, Package to “FBGA”, Pin Count to “780” , Core Speed
Grade to “7” and Set Device as “EP4CE115F29C7”.
5. Set Simulation Tool to “ModelSim” and Format to “Verilog HDL”.
6. Verify all details in Summary are Acurate then click Finish.
7. Go To : File → New → “Verilog HDL File”, To create a New File.
8. Code the Apropriate Verilog Program in the File and Save It.
9. Once Done, Go To : Processing → Start Compilation, To compile the Verilog Code.
10. To Perform RTL Simulation Go To : Tools → Run Simulation Tool → RTL Simulation.
11. Perform The Necessary Simulations in ModelSim and Verify The Output.
12. Once Code Is Verified Close ModelSim, Go To : Assignments → Pin Planner.
13. Assign Necessary Input Output Pins and Recompile using Step 9.
14. To Flash The Code in the Kit, Connect the Power Supply to the Kit and Connect the
Provided USB Cable.
15. Go To : Tools → Programmer, Select USB-Blaster, and Click Start.
16. On Succesful Flashing Verify The Output
Code:
module main_counter(
input Clock, Reset, UpDown, // UpDown is the switch to toggle between up
and down counter
output [6:0] HEX0, // Seven-segment display output Right
output [6:0] HEX1 // Seven-segment display output Left
);
wire Slow_Clk_Out;
wire [3:0] Count_Out;
module clkdivider(
input clk, rst,
output slowclk
);
reg [25:0] count;
always @(posedge clk)
begin
if(rst) count <= 0;
else count <= count + 1;
end
assign slowclk = count[25];
endmodule
module four_bit_counter(
input clk, rst, up_down,
output reg [3:0] q
);
always @(posedge clk)
begin
if(rst) q <= 4'b0000;
else if(up_down) q <= q + 4'b0001; // Up counter
else q <= q - 4'b0001; // Down counter
end
endmodule
module bcd_to_7segment (
input [3:0] bcd,
output reg [6:0] seg0,
output reg [6:0] seg1
);
Hardware Implementation:
Pin Planner:
Output:
Case 1: 7-Segment Showing 04
Inference:
We have understood how to program a 4 Bit Up-Down Counter and Linked it to a Clock
Divider to Slow Down The Transitions and Connect it to a BCD to 7-Segment Module to
display the count on the 7-Segment Display on the DE2-115 Board.
Result:
Thus, we have successfully designed a 4bit Up-Down Counter, Interfaced it with a BCD to 7-
segment display and utilized a clock divider to ensure readability of the output in both Up and
Down Modes and implemented on the DE2-115 board.