Digital Clock
Digital Clock
Digital Clock
Table of Contents
1.0
INTRODUCTION ........................................................................................................................... 4
1.1
OBJECTIVES .............................................................................................................................. 4
1.1.1
1.1.2
1.2
OVERVIEW ............................................................................................................................... 4
1.3
1.4
Counter .................................................................................................................................... 5
1.5
LED .......................................................................................................................................... 5
1.6
2.0
METHODOLOGY ........................................................................................................................... 6
2.1
Compilation ............................................................................................................................. 7
2.2
2.3
3.0
IMPLEMENTATION ..................................................................................................................... 10
3.1
3.2
Loading verilog HDL codes into Cyclone II FPGA Experiment board. ........................................ 14
4.0
RESULTS ..................................................................................................................................... 15
5.0
CONCLUSION ............................................................................................................................. 16
6.0
References ................................................................................................................................. 17
Table of figures
Figure 1: Full compilation........................................................................................................................ 7
Figure 2: Pins assignment. ....................................................................................................................... 8
Figure 3: Schematic diagram for digital clock. .......................................................................................... 9
Figure 4 : Cyclone II FPGA Experiment Board ......................................................................................... 10
Figure 5 : USB-Blaster .......................................................................................................................... 14
Figure 6 : Cyclone II FPGA board display the results. ............................................................................ 15
1.0 INTRODUCTION
Digital clock means clock is using ciphers to display time digitally which is completely different
from Analog Clock, where the time is displayed by mechanical hands. Digital clocks are often
made up by electronic drives; the word "digital" refer only to the display and not the drive
mechanism. All type of Clock that is analog and digital clocks both can be driven either
mechanically or electronically.
1.1 OBJECTIVES
1.1.1
General Objective:
The main objective of this project was to design and implementation of digital clock using
Verilog HDL.
1.1.2
Specific Objectives
1.2 OVERVIEW
A digital clock has been designed and implemented as presented in this report. It displays the
time on seven segment led displays and time from 00:00:00 to 23:59:59 .Which means it display
hours, minutes, and seconds .It made up by 7 segment LED patterns with two bits key enable
signal, 25 bits Counters, Registers.
1.4 Counter
Apart from the clock there is counter which plays a major role in this project. It was used to
count and increment the output before next state to occur during display of seven segment
display and normally works on positive edge clock. Counters in the tens place resent on
achieving a value of 5, 5 and 2 (with the units counter on 3) for seconds, minutes and hours
respectively. This is because the LED accepts only one character at a time, and converting a
binary number into a two decimal digit number. The three counters are updated using the same
method of concurrent always blocks and a counter generating a 1Hz signal.
1.5 LED
To display data on the LED, one needs to first initialize the LED on power-on. The LED connects
to the FPGA through a 4-bit data bus and three control bits. Since the data bus is also shared
with the onboard Magic SOPC, it is necessary to write a logical high bit at all times while using
the LED. A schematic diagram is given in the user manual, which has been reproduced here for
convenience. The three most significant bits are decoded to generate the enable signal and are
used as the selection signal for multiplexing .As it shown on program codes in section 2.0 we
use timing of 0.5second for 50Hz to count up by increment of 1 bit and when it reaches
maximum bit value {25 bits} it clear the counter to zero and start again to count. The three
most significant bits are decoded to generate the enable signal and are used as the selection
signal for multiplexing.
2.0 METHODOLOGY
This section presents the methods used to implement the design of a digital clock. Hardware
Descriptive Language used in the design of digital clock and implemented using the Magic SOPC
experiment box. Typical digital clocks applied were of the 50 or 60 hertz oscillation of AC
power or a 32,768 hertz crystal oscillator as in a quartz clock to keep time, a frequency of 1
Hertz was used in this particular experiment. Most digital clocks display the hour of the day
in 24 hour format. A more commonly used hour sequence option is 12 hour format (with some
indication of AM or PM). Emulations of analog-style faces often use an LCD screen, and these
are also sometimes described as digital.
2.1 Compilation
Here is where .v file named as clock (clock.v) is simulated to see whether the written Verilog
codes had some errors or not. The figure below presents the full compilation of the Verilog
codes for the digital clock which was successful compiled as it shown below.
3.0 IMPLEMENTATION
The implementation of the digital clock design was done using Cyclone II Altera FPGA
experiment board as shown below. This part involves Verilog HDL codes used to design digital
clock.
10
11
3'd2:disp_dat = 4'ha;
3'd3:disp_dat = hour[11:8];
3'd4:disp_dat = hour[15:12];
3'd5:disp_dat = 4'ha;
3'd6:disp_dat = hour[19:16];
3'd7:disp_dat = hour[23:20];
endcase
case(count[17:15])
3'd0:dig_r = 8'b11111110;
3'd1:dig_r = 8'b11111101;
3'd2:dig_r = 8'b11111011;
3'd3:dig_r = 8'b11110111;
3'd4:dig_r = 8'b11101111;
3'd5:dig_r = 8'b11011111;
3'd6:dig_r = 8'b10111111;
3'd7:dig_r = 8'b01111111;
endcase
end
always @(posedge clk)
begin
case(disp_dat)
4'h0:seg_r = 8'hc0;
4'h1:seg_r = 8'hf9;
4'h2:seg_r = 8'ha4;
4'h3:seg_r = 8'hb0;
4'h4:seg_r = 8'h99;
4'h5:seg_r = 8'h92;
4'h6:seg_r = 8'h82;
4'h7:seg_r = 8'hf8;
4'h8:seg_r = 8'h80;
4'h9:seg_r = 8'h90;
4'ha:seg_r = 8'hbf;
default:seg_r = 8'hff;
endcase
if((count[17:15]== 3'd2)&sec)
seg_r = 8'hff;
end
//Timing processing section
always @(negedge sec or negedge key_done[1])
begin
if(!key_done[1])
begin
hour = 24'h0;
end
else if(!keyen)
12
begin
hour[3:0] = hour[3:0] + 1'b1;
if(hour[3:0] == 4'ha)
begin
hour[3:0] = 4'h0;
hour[7:4] = hour[7:4] + 1'b1;
if(hour[7:4] == 4'h6)
begin
hour[7:4] = 4'h0;
hour[11:8] = hour[11:8] + 1'b1;
if(hour[11:8] == 4'ha)
begin
hour[11:8] = 4'h0;
hour[15:12] = hour[15:12] + 1'b1;
if(hour[15:12] == 4'h6)
begin
hour[15:12] = 4'h0;
hour[19:16] = hour[19:16] + 1'b1;
if(hour[19:16] == 4'ha)
begin
hour[19:16] = 4'h0;
hour[23:20] = hour[23:20] + 1'b1;
end
if(hour[23:16] == 8'h24)
hour[23:16] = 8'h0;
end
end
end
end
end
end
endmodule
13
3.2 Loading verilog HDL codes into Cyclone II FPGA Experiment board.
The processing of loading was done using USB-Blaster via JTAG and AS pins. Figure below shows the
USB-Blaster.
Figure 5 : USB-Blaster
14
4.0 RESULTS
The below photo shows the results after loading Verilog HDL codes into experiment board. It was able to
display hours, minutes and seconds then counts from 00:00:00 to 23:59:59.
15
5.0 CONCLUSION
The objectives of this project were met and a digital clock has been designed and implemented
as presented in this report. The Verilog HDL codes for program counts hours from 00:00:00 to
23:59:59 was successful implemented and also pins assignment was done successful .It displays
the time on seven segment led displays and time from 00:00:00 to 23:59:59 which means it
display hours, minutes, and seconds .
16
6.0 References
1. Digital vlsi system design by Seetharaman Ramachandran
2. Prototyping by verilog examples by Pong P.Chu
3. http://www.sunburstdesign.com/papers/CummingsSNUG2003Boston_SystemVerilog_VHD
L.pdf
4. D. Michael Miller; Mitchell A. Thornton (2008). Multiple valued logic: concepts and
representations. Synthesis lectures on digital circuits and systems.
5. http://en.wikipedia.org/wiki/Digital_clock
17