- Joined
- Apr 3, 2011
- Messages
- 4
- Reaction score
- 0
Hi, I'm losing it or seriously lacking sleep.
I have a simple circuit that is to be driven by a timer output similar to an 8254 operating in mode 2. So simple its unbelievable. However I synthesis the code below and the falling edge of clkout is always generated when the count is 0. If modulus is loaded with 3 then I expect so 3,2,1,3,2,1 repeating with the clkout going low on 1 and coming high on 0 as the reload occurs.
clkout is delayed one clock. Now I realise this due to the signal queue, however if I set clkout low when count = 2 it make no difference. In fact irrespective of the compare & reload value clkout always go low when the count is 0.
Any ideas anyone?
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
entity CLOCK_DIVIDER is
port(
reset: in std_logic;
clk: in std_logic;
modulus:in std_logic_vector (15 downto 0); -- modulo divider
enable: in std_logic;
clkout: out std_logic -- divided output
);
end entity;
architecture RTL of CLOCK_DIVIDER is
begin
pDivide: process(clk, reset, enable)
variable count: natural;
begin
if (reset = '0') then
count := 0;
clkout <= '1';
elsif falling_edge(clk) then
if (enable = '1') then
if (count = 1) then
clkout <= '0';
elsif (count = 0)
clkout <= '1';
count = modulus;
else
count := count - 1;
end if;
else
count := count;
end if;
end if;
end process;
end architecture RTL;
I have a simple circuit that is to be driven by a timer output similar to an 8254 operating in mode 2. So simple its unbelievable. However I synthesis the code below and the falling edge of clkout is always generated when the count is 0. If modulus is loaded with 3 then I expect so 3,2,1,3,2,1 repeating with the clkout going low on 1 and coming high on 0 as the reload occurs.
clkout is delayed one clock. Now I realise this due to the signal queue, however if I set clkout low when count = 2 it make no difference. In fact irrespective of the compare & reload value clkout always go low when the count is 0.
Any ideas anyone?
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
entity CLOCK_DIVIDER is
port(
reset: in std_logic;
clk: in std_logic;
modulus:in std_logic_vector (15 downto 0); -- modulo divider
enable: in std_logic;
clkout: out std_logic -- divided output
);
end entity;
architecture RTL of CLOCK_DIVIDER is
begin
pDivide: process(clk, reset, enable)
variable count: natural;
begin
if (reset = '0') then
count := 0;
clkout <= '1';
elsif falling_edge(clk) then
if (enable = '1') then
if (count = 1) then
clkout <= '0';
elsif (count = 0)
clkout <= '1';
count = modulus;
else
count := count - 1;
end if;
else
count := count;
end if;
end if;
end process;
end architecture RTL;