Altera_Forum
Honored Contributor
12 years agoClock divider
Hi all
Again with VHDL problems :p I need a clock divider to run a Z80. My board fréquency is 50Mhz and I need 3,57Mhz. I found this code but it doesn't seem working with all "constant CLK_SLOW_FREQ" library IEEE; use IEEE.STD_LOGIC_1164.ALL; use ieee.numeric_std.all; use ieee.math_real.all; entity CPU_CLOCK is port (CLKIN : in std_logic; CLKOUT : out std_logic ); end entity CPU_CLOCK; architecture arch of CPU_CLOCK is constant CLK_MASTER_FREQ: natural := 50000000; constant CLK_SLOW_FREQ: natural := 3570000; constant MAX_COUNT: natural := CLK_MASTER_FREQ/CLK_SLOW_FREQ; shared variable counter: natural := 0; begin clock_proc: process(CLKIN) begin if rising_edge(CLKIN) then counter := counter + 1; if (counter >= MAX_COUNT) then counter := 0; CLKOUT <= '1'; else CLKOUT <= '0'; end if; end if; end process; end arch;