Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Divide by n

Reply
Thread Tools

Divide by n

 
 
Mushmech
Guest
Posts: n/a
 
      04-11-2004
Trying to come up with a simple divide by 16 counter. Please Help!


 
Reply With Quote
 
 
 
 
valentin tihomirov
Guest
Posts: n/a
 
      04-11-2004
constant DIVIDER: integer:= 16;
signal OVERFLOW: boolean;
singnal CNT, CNT_NEXT: integer range 0 to DIVIDER - 1;

OVERFLOW <= (CNT = DIVIDER - 1);

process(CNT: integer)
begin
if OVERFLOW then
CNT_NEXT <= CNT + 1;
else
CNT_NEXT <= 0;
end if;
end process;

process (CLK, RST)
begin
if RST = '1' then
CNT <= 0;
else if CLK = '1' and CLK'event then
CNT <= CNT_NEXT;
end if;
end process;


 
Reply With Quote
 
 
 
 
Charles M. Elias
Guest
Posts: n/a
 
      04-12-2004
"Mushmech" <> wrote in message news:<IM2ec.57861$z%>...
> Trying to come up with a simple divide by 16 counter. Please Help!


This is a variation on the divider in the VHDL FAQ; if the modulus is
even, the output clock is symmetrical, otherwise the high and low
clock output times differ by 1 clock period:

--------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.all;
--------------------------------------------------------------------------------
entity clock_divider is
generic(modulus: in positive range 2 to integer'high);
port( clk_in : in std_logic;
enable : in std_logic := '1';
reset : in std_logic := '0';
clk_out : out std_logic );
end clock_divider;

architecture behavior of clock_divider is
begin
process (clk_in, reset, enable )

variable count: natural range 0 to modulus - 1;

begin
if reset = '1' then
count := 0;
clk_out <= '0';
elsif rising_edge( clk_in ) then
if enable = '1' then
if count = modulus - 1 then
count := 0;
else
count := count + 1;
end if; --count = modulus - 1
else
count := count;
end if; --enable = '1'
if count >= modulus/2 then
clk_out <= '0';
else
clk_out <= '1';
end if; --count >= modulus/2
end if; --rising_edge( clk_in )
end process;
end behavior;


Charles
 
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
NEED HELP: multiply and divide with integer in VHDL ledinhkha@gmail.com VHDL 2 12-15-2005 08:06 AM
Re: code help and std_logic divide climberjc VHDL 0 12-08-2005 08:36 PM
Divide by 2 counter Ash12 VHDL 2 02-28-2005 06:00 AM
Unsupported error,& Right operand of "Divide" operator must be a power of 2.. Kim JM VHDL 1 04-02-2004 06:58 PM
std_logic_vector divide Ciar?n Hughes VHDL 2 10-04-2003 01:34 PM



Advertisments
 



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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57