i want to get the clock frequency divide by 5, can i do it with integer type or i need something else to run the decimal number?
library ieee;
use ieee.std_logic_1164.all;
use IEEE.NUMERIC_STD.ALL;
entity divide_clk is
port( clk: in std_logic;
clk_out: out std_logic);
end divide_clk;
architecture behave of divide_clk is
signal count: integer range 0 to 24999999:= 0;
signal temp : std_logic := '0';
begin
process(clk)
begin
if (clk'event and clk='1') then
if (count = 2.5) then
temp <= not(temp);
count <= 0;
else
count <= count + 1;
end if;
end if;
end process;
clk_out <= temp;
end behave;
Best Answer
If you want to generate a 50% duty cycle divided clock in VHDL, using only rising_edge of clock, the divided clock's period should be multiples of 2. Since 5 is an odd num, you have to make use of falling_edge of the main clock too. You have to generate two 2/5 duty cycle clocks phase shifted by half period of the main clock. Then you can "OR" it to get the required clock which is of 1/5th frequency and 50% duty cycle.
Something like this:
Code Sample: