aravind wrote:
> There is a 20 bit counter,with two inputs ,on the rising edge of one
> input the counter must increment and on the rising edge of the other
> input the counter must decrement.
> this is for a 1MB FIFO buffer using single port external SRAM,I'm using
> Xilinx ISE tool.according to the xilinx tool you cannot have two
> (rising_edge()) statements in a single process.
>
> How do you code it?
>
Two ideas
Idea a:
=======
1. Assure both inputs are synchronised to the counter's clock
2. If you have to synchronise your inputs choose the counter's clock frequency
according to following formula:
fcnt > 1/(2 * (min(thmin(i1), tlmin(i2)), min(thmin(i2), tlmin(i2)))
with
i1 and i2: designating the two inputs
thmin: minimum high time
tlmin: minimum low time
3. The counter's code:
signal cnt20 : unsigned(19 downto 0);
signal i1, i2 : std_ulogic; -- inputs 1, 2
signal i1_old, i2_old : std_ulogic -- differentiated inputs 1, 2
p_cnt20 : process (clk,reset)
begin
if reset = ActiveResetLevel then
cnt20 <= (others => '0');
i1_old <= '1';
i2_old <= '1';
elsif (clk'event and clk = '1') then
if i1_old = '0' and i1 = '1' and -- rising edge of i1
i2_old = '0' and i2 = '1' then -- rising edge of i2
NULL;
elsif i1_old = '0' and i1 = '1' then -- rising edge of i1
cnt20 <= cnt20 + 1;
elsif i2_old = '0' and i2 = '1' then -- rising edge of i2
cnt20 <= cnt20 - 1;
end if;
end if;
end process;
Idea b:
=======
1. use one 20 bit counter for each clock domain and
(1a. eventually encode with Gray code for only one bit changes)
2. synchronise both counter outputs for the result clock domain
(2a. decode the Gray encoded counter values if Gray encoded)
3. substract one result from the other for the SRAM address.
Cheers
Wolfgang