Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

Cant Decrement Clock!??

I've been messing around with this program for quite a while now and have run out of ideas. Im can t get the clock to increment when enable -which is assigned to a switch- is high, but I am not able to get the clock to decrement when enable is low. Any help or insight is appreciated.

Thanks.

Signal counter, counter2 : INTEGER;

PROCESS(enable, clock_50)

--VARIABLE counter: INTEGER;

BEGIN

IF(clock_50 = '1' AND clock_50'EVENT) then

IF(enable = '1') THEN

IF (counter = 52428800/15) THEN --Speed of the on board clk (50Mhz)

counter <= 0;

toggle_clk <= NOT toggle_clk;

ELSE

counter <= counter + 1;

counter2 <= counter2 + 1;

END IF;

ELSE

counter <= 0;

toggle_clk <= '0';

END IF;

END IF;

END PROCESS;

--Decelarate

PROCESS(enable, clock_50)

--VARIABLE counter2: INTEGER;

BEGIN

counter2 <= counter;

toggle_clk2 <= toggle_clk;

IF(clock_50 = '1' AND clock_50'EVENT) then

IF(enable = '0') THEN

IF (counter2 = 52428800/22) THEN --Speed of the on board clk (50Mhz)

counter2 <= 0;

toggle_clk2 <= not toggle_clk2;

ELSE

counter2 <= counter2 - 1;

--counter <= counter -1;

END IF;

ELSE

counter2 <= 0;

toggle_clk2 <= '0';

END IF;

END IF;

END PROCESS;

1 Reply

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    First you are assigning a value to counter2 from both processes, which will give strong results in simulation and will give you an error when synthesizing.

    Second, in your decelerate process, you must remember that the complete process is executed each time there is a change on the sensitivity list. This means that at each change of enable or clock_50 (including falling edges) the first two lines will be executed, and you set the values of counter2 and toggle_clk2 with counter and toggle_clk. This will probably cancel the decreasing you wanted to do.

    Why don't you put everything in a single process?