Altera_Forum
Honored Contributor
15 years agoOdd Bug
Hello, I am very new to Altera and microchip programming. Today I wrote(with a lot of code borrowed from a book) a program that does what it's supposed to do, but also something else that it's not.
Here's the program: LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; ENTITY Clockdiv IS PORT ( Clk25Mhz: IN STD_LOGIC; Clk, Clk2: OUT STD_LOGIC; PinNumber: OUT STD_LOGIC_VECTOR(2 DOWNTO 0)); END Clockdiv; ARCHITECTURE Behavior OF Clockdiv IS CONSTANT max: INTEGER := 25000000; CONSTANT half: INTEGER := max/2; SIGNAL count: INTEGER RANGE 0 TO max; SIGNAL pin: INTEGER RANGE 0 TO 7; SIGNAL state: STD_LOGIC; BEGIN PROCESS(Clk25Mhz) BEGIN IF Clk25Mhz'EVENT and Clk25Mhz = '1' THEN IF count < max THEN count <= count + 1; ELSE count <= 0; END IF; IF count = half THEN IF pin < 8 THEN pin <= pin + 1; ELSE pin <= 0; END IF; END IF; IF pin = 7 THEN Clk <= '1'; Clk2 <= '0'; ELSE Clk <= '0'; Clk2 <= '1'; END IF; CASE pin IS WHEN 0 => PinNumber <= "000"; WHEN 1 => PinNumber <= "001"; WHEN 2 => PinNumber <= "010"; WHEN 3 => PinNumber <= "011"; WHEN 4 => PinNumber <= "100"; WHEN 5 => PinNumber <= "101"; WHEN 6 => PinNumber <= "110"; WHEN OTHERS => PinNumber <= "111"; END CASE; END IF; END PROCESS; END Behavior; It's supposed to flash the leds, in a pattern that will show binary numbers from 0 to 111 increasingly and then start over and just keep doing that. Which it does very well, but it also changes two segments on bcd display every time all the 3 led lights are on. The pin assigments are for the three rightmost green lights on the desk assigned to the vector and one input for 50mhz clock. I know there are unused outputs and signals in the program, I left it as it is in case something causes the error. I've tried it with the red leds and it produced the same problem, except with a different segment of the bcd number. Didn't have more time to experiment with unfortunately. The altera desk is EP2C35F672C6. I don't know if someone will be able to recreate the problem, but at least someone can tell me if it's a bug in the desk/software or a fault in my program. Keep on truckin'