Forum Discussion

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

Odd 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'

3 Replies

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

    Your code doesn't control the segment display directly, so I can't tell you what's the problem.

    However I see that 'pin' changes from 0 to 8: is this correct? Or maybe you were supposed to use a 0 to 7 range?

    Infact in the following case statement you only account for these 8 values.

    With the code you have written PinNumber keeps the "111" status twice.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Check the actual pin assignment in the compilation report! I guess, you mean with "unused outputs" that you didn't assign pin locations for these pins. Quartus will assign arbitrary pins for it, possibly causing unwanted effects in your circuit.

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

    Cris72: Yes, it's a mistake, the pin is supposed to go up to 7 then drop back to 0.

    FvM: I'll get rid of the unused pins next time I have access to the board and see if it solves the problem. I had assumed that unused pins went unused.