Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > How to make Clock Divider

Reply
Thread Tools

How to make Clock Divider

 
 
dadili dadili is offline
Junior Member
Join Date: Dec 2011
Posts: 4
 
      12-10-2011
I have to make clock divider from 50MHz to 2.5 Hz. I have no idea how to do it. can someone help me, write the code or explain to me.
 
Reply With Quote
 
 
 
 
jeppe jeppe is offline
Senior Member
Join Date: Mar 2008
Location: Denmark
Posts: 348
 
      12-11-2011
Try something like this:

Code:
process( Clk_50MHz)
   variable Count20: integer range 0 to 20000000;
begin
    if Rising_edge( Clk_50MHz) then
         if Count20>1 then
             Clk_2p5Hz <= '0';
             Count20 := Count20-1; 
        else
             Clk_2p5Hz <= '1';     
             Count20 := 20000000;
        end if; 
   end if;
end process;
 

Last edited by jeppe; 12-11-2011 at 01:34 PM.. Reason: Noticed 2.5Hz ... not 2.5 MHz
Reply With Quote
 
 
 
 
jeppe jeppe is offline
Senior Member
Join Date: Mar 2008
Location: Denmark
Posts: 348
 
      12-11-2011
The 2p5Hz will however be short (say 20 nanosec) but its possible to make it wider
(try this yourself)
 
Reply With Quote
 
dadili dadili is offline
Junior Member
Join Date: Dec 2011
Posts: 4
 
      12-11-2011
can you explain me this part

why this range to 20000000
Quote:
variable Count20: integer range 0 to 20000000;

what is it working here?

Quote:
if Count20>1 then
Clk_2p5Hz <= '0';
Count20 := Count20-1;
else
Clk_2p5Hz <= '1';
Count20 := 20000000;
end if;
 
Reply With Quote
 
jeppe jeppe is offline
Senior Member
Join Date: Mar 2008
Location: Denmark
Posts: 348
 
      12-11-2011
50MHz = 50.000.000 Hz
50.000.000 Hz / 2,5Hz = 20.000.000 = 20000000
Hence must you count 20 million pulses of the 50MHz frequiency to make one
pulse of the 2,5 Hz signal.

This answer both questions I believe.
 
Reply With Quote
 
dadili dadili is offline
Junior Member
Join Date: Dec 2011
Posts: 4
 
      12-11-2011
can I do it like this?

Code:
entity clock is
port
(
       clk: in std_logic;
       clok_o: buffer std_logic
);
end clock;

architecture Desc of clock is
begin
process(clk)
      variable count: integer range 0 to 20000000;
      begin
             if (clk'event and clk='1') then
             count:=count+1;
             if(count>=20000000) then
                  clk_o<=not clk_o;
                  count:=0;
end if;
end if;
end process;
end Desc;
 

Last edited by dadili; 12-11-2011 at 06:37 PM..
Reply With Quote
 
jeppe jeppe is offline
Senior Member
Join Date: Mar 2008
Location: Denmark
Posts: 348
 
      12-11-2011
Yes

But in this case should you change 20000000 to 10000000
then clk_o will get 50% as '0' and 50% as '1' of the 1/2.5 time period
 
Reply With Quote
 
dadili dadili is offline
Junior Member
Join Date: Dec 2011
Posts: 4
 
      12-11-2011
Thanks for your help, but I dont understand why 10000000?
 
Reply With Quote
 
jeppe jeppe is offline
Senior Member
Join Date: Mar 2008
Location: Denmark
Posts: 348
 
      12-12-2011
In my first example did you get:
19.999.999 clock periodes with clk_o = '0'
and
1 clock period with clk_o = '1'

In your (good) solution will you now get.

10.000.000 clock periodes with clk_o = '0'
and
10.000.000 clock periodes with clk_o = '1'

(Clock periodes of 50 MHz)

Your welcome
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
clock divider by 2 martstev@gmail.com VHDL 3 08-16-2006 05:06 AM
MCU clock divider vs. VHDL divider Matt Clement VHDL 3 04-28-2006 01:24 PM
Error in clock divider from FAQ yolanda3000@freenet.de VHDL 2 09-06-2005 01:16 PM
Clock Divider Mohammed A khader VHDL 4 03-14-2005 11:46 AM



Advertisments