Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

Cant Decrement Clock!??

Altera_Forum
Honored Contributor II
1,251 Views

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;
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
385 Views

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?
0 Kudos
Reply