Altera_Forum
Honored Contributor
13 years agoNewb question- If statements
Im new to programming in VHDL and I seem to be having some difficulty with a particular set of if statements. I understand how conditional statements work, but for whatever reason Im not getting the output I expect. The output never appears to hit the 2nd elsif statement. Ive tried a combination of else-ifs, ifs, and if-else staements to get the result I expect : from 0 to 27000000 clkout goes high, 27000000 to 54000000 clkout goes low, 54000000 to 81000000 goes high, 81000000 goes low and cnt finishes. Here is the snippet of code:
PROCESS(clk,sel,en) VARIABLE cnt: INTEGER RANGE 0 to 81000000; BEGIN IF(en='1') THEN reset <= '0'; IF(clk' EVENT and clk = '1') THEN IF(cnt = 81000000)THEN clkout <= '0'; ELSIF(cnt = 27000000)THEN clkout <= '0'; ELSIF(cnt = 54000000)THEN clkout <= '1'; ELSE cnt:=cnt+1; clkout <= '1'; END IF; END IF; ELSE clkout <='0'; reset <='1'; cnt:= 0; sel <= "00"; END IF; END PROCESS;