Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

[SOLVED] help:make the clock divider twice as fast or 2 Hz.

Status
Not open for further replies.

saUNT

Newbie level 3
Joined
Apr 26, 2015
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
36
Hello, I hope you guys doing well.
This is one part of a school project, I did the other parts but I'm stuck on this one:

"This given module take the 50 MHz clock_50 of the DE2 board and divides down to generate a CLKout of 1 Hz. Modify this given module to make the clock twice as fast or 2 Hz"

and here is the code:

Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
 
entity DIVIDER is
port ( CLKin: in std_logic;
reset: in std_logic;
CLKout: out std_logic);
end DIVIDER;
 
architecture behavioral of DIVIDER is
signal count: integer:=0;
signal temp : std_logic := '1';
begin
process(CLKin,count,reset)
begin
if(reset='1') then count<=0; temp<='1';
elsif(CLKin'event and CLKin='1') then count <=count+1;
if (count = 25000000) then temp <= NOT temp; count<=0;
end if;
end if;
CLKout<= temp;
end process;
end behavioral;

 
Last edited by a moderator:

TrickyDicky

Advanced Member level 5
Joined
Jun 7, 2010
Messages
7,025
Helped
2,058
Reputation
4,133
Reaction score
2,010
Trophy points
1,393
Activity points
38,602
What exactly is the problem (apart from the fact that clock dividers like this are bad practice)?
 

saUNT

Newbie level 3
Joined
Apr 26, 2015
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
36
The teacher is wanting to "Modify this given module to make the clock twice as fast or 2 Hz" but i really don't understand what he is asking
 

fouwad

Full Member level 4
Joined
Nov 29, 2009
Messages
197
Helped
19
Reputation
38
Reaction score
17
Trophy points
1,298
Location
Pakistan
Activity points
2,447
if (count = 25000000) then temp <= NOT temp; count<=0;

just make the value half, problem solved
 
  • Like
Reactions: saUNT

    saUNT

    points: 2
    Helpful Answer Positive Rating

std_match

Advanced Member level 4
Joined
Jul 9, 2010
Messages
1,163
Helped
441
Reputation
882
Reaction score
407
Trophy points
1,363
Location
Sweden
Activity points
8,927
The original code has a very common bug. "count" will go from 0 to 25000000 and then start from zero again. That is a 25000001 cycle interval, so the frequency divisor is 50000002, not 50000000.

Also, "count" as an integer without range will probably synthesize to 32 bits. I doubt that the synthesis tool is smart enough to reduce it to 25 bits, which is enough. Either put a range on "count", or define it as "unsigned" with the correct size.
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top