Forum Discussion

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

LED toggle

I'm trying what I thought would be a very simple programme to turn alternate LEDs ON and OFF every half second, but it isn't working as it should. It starts off OK, with the LEDs toggling about every half a second, but the period soon increases, so that after 5 or 6 iterations, the LEDs are turning on/off about every second, then every 2 seconds, etc. After 15-20 seconds, one LED stays ON all the time, the other OFF. Following is the code I'm using :-

ENTITY LEDToggle IS

PORT

(

clk :in STD_LOGIC;

led0 :out STD_LOGIC;

led1 :out STD_LOGIC

);

END LEDToggle;

ARCHITECTURE behaviour OF LEDToggle IS

SIGNAL COUNT : INTEGER RANGE 0 TO 50000000;

BEGIN

PROCESS (clk)

BEGIN

IF clk'event and clk='1' THEN -

COUNT<=COUNT+1;

IF COUNT < 24999999 then

LED0<='1';

LED1<='0';

ELSIF COUNT>24999998 AND COUNT<49999999 THEN

LED0<='0';

LED1<='1';

ELSE

COUNT<=0;

END IF;

END IF;

END PROCESS;

END behaviour;

I'm using an EPM240T100C5 development board with a 50MHz oscillator. The LED's are on pins 2 and 8 and I'm using the clock on pin 14.

Regards

11 Replies

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

    hi

    thanks again. I found out how to set the clock speed on the menu bar using your suggestions above,and I'll check it out using different clock pins.

    regards