EmbDev.net

Forum: FPGA, VHDL & Verilog Digital clock 7-seg display NEXYS-3


von peterkraft (Guest)


Rate this post
useful
not useful
Hi,
I have to do a project in VHDL on NEXYS3 Spartan6 FPGA board.
I tried many things but nothing actually worked for me. Could anyone 
possibly help me and write the code how to make a digital clock based on 
7 segment display?
It should display hours and minutes, contain 2 switches to increment 
hours and minutes and have a diode ticking every seconds.
Id like to see as primitive code as its possible to understand easily.
Thanks for help

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
peterkraft wrote:
> help me and write the code
Whoms homework is this?
Why don't you start with something and when you encounter a specific 
problem then you ask for a hint.

> have a diode ticking every seconds.
Start with this task. Give your own try two evenings. At least...

Afterwards there's a super simple solution for a stop watch:
http://www.lothar-miller.de/s9y/archives/88-VHDL-vs.-Verilog-am-Beispiel-einer-Stoppuhr.html
It's fairly easy to understand and adapt to your job. Try Google 
translate, it's German.

von peterkraft (Guest)


Rate this post
useful
not useful
1
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.std_logic_arith.all;
4
use ieee.std_logic_unsigned.all;
5
6
entity clockdigit is
7
port (clk1 : in std_logic;
8
      seconds : out std_logic_vector(5 downto 0);
9
      minutes : out std_logic_vector(5 downto 0);
10
      hours : out std_logic_vector(2 downto 0)
11
     );
12
end clockdigit ;
13
14
architecture Behavioral of clockdigit  is
15
signal sec,min,hour : integer range 0 to 60;
16
signal count : integer :=1;
17
signal clk : std_logic :='0';
18
begin
19
20
21
process(clk1)
22
begin
23
if(clk1'event and clk1='1') then
24
count <=count+1;
25
if(count = 50000000) then
26
clk <= not clk;
27
count <=1;
28
end if;
29
end if;
30
end process;
31
32
process(clk)
33
begin
34
35
if(clk'event and clk='1') then
36
sec <= sec+ 1;
37
if(sec = 59) then
38
sec<=0;
39
min <= min + 1;
40
if(min = 59) then
41
hour <= hour + 1;
42
min <= 0;
43
if(hour = 23) then
44
hour <= 0;
45
end if;
46
end if;
47
end if;
48
end if;
49
50
end process;
51
52
end Behavioral;




I've done something like this, but I still dont know how to display it 
on 7-seg display. Id like to display hours and minutes, and make a 
ticking diode every second. Could you possibly help with the code?

: Edited by Moderator
von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
peterkraft wrote:
> I've done something like this
It is NOT a proper way to generate clocks inside a FPGA. You will get a 
warning for such a design style. Use clock-enable signals for that.

> if(count = 50000000) then
This is the well known "off-by-one" error. Not much of a problem here, 
because it will get only 1/50000000 deviation for your clock. That means 
your clock will be off by one second after almost a year due to that 
error. But when you would do that to count milliseconds, then the 
deviation would be a quarter of an hour...

> Could you possibly help with the code?
Did you click on that link?
There you can see 1. how to use the numeric_std package and 2. how to 
use clock enables and 3. how to get the digits to the display and 4. 
that it is much better to count each of the 4 digits by its own, so it 
can easily be displayed. Because with your code you encounter the 
problem to fiddle the 4 digits out the hours and miuntes.

BTW:
> I've done something like this
Pls use the [vhdl] tags to wrap your code.

: Edited by Moderator
von C. A. Rotwang (Guest)


Rate this post
useful
not useful
write your code more readable:

>
1
process(clk)
2
begin
3
 if rising_edge(clk) then
4
--add 'tick every second' condition here
5
  if sec = 59 then
6
   sec <= 0;
7
  else
8
   sec <= sec + 1;
9
  end if;
10
11
  if min = 59 then
12
   min <= 0;
13
  else
14
   min <= min + 1;
15
  end if;
16
17
  if hour = 23 then
18
   hour <= 0;
19
  else
20
   hour <= hour + 1;
21
  end if;
22
 --add closing end if of tick condition here 
23
 end if;
24
end process;

von Sidney Smith Oteggewo Osojoh Ebot (Guest)


Attached files:

Rate this post
useful
not useful
This design can be helpful

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.