Altera_Forum
Honored Contributor
13 years agoStrange Behavior when using case statement on EPM3128A
I have been having a problem with a project that I am doing and have asked many people in the office to no eval.
I am using an Altera EPM3128A Device with a GCLK1 speed of 24MHz, I then devide this down in the device to a very slow speed ( >1Hz) so that I can see the behavior of some LED's that are attached to the device. I have a case statement that switches a green LED on and a Red one off and advances the case statement. The next case switches the red LED on and green LED off, the next case is then set to the original case. (The LEDs are active 0) The problem that I am having is that on startup of the device, both LED's are coming on together. These is never a state in the program when both of the LED's are on together. The program then runs as expected. If I set one off the states so that both of the LED's are off then on startup only the LED that is turned on during one of the states will display. Again the program will then run as expected I have attached my code and would be grateful of any pointers that you can give or any explanations as to what is going on.library ieee;
use ieee.std_logic_1164.all;
entity USBDownloader is
generic ( CLK_DIVIDER_6 : integer :=20000000);--------DO NOT CHANGE--------
port(
----------------------CLOCKS--------------------------------------
SYS_CLK_IN : in std_logic;
CLK_6MHz : out std_logic;
ULED : out std_logic;
RLED : out std_logic
);
end entity USBDownloader;
architecture rtl of USBDownloader is
type case_counter_type is (a, b, c);
-- Declare Constants and Variables
signal CLK_TEMP_6 : std_logic := '0';
signal CNT_6 : integer range 0 to 20000000 := 0 ;
signal case_counter : case_counter_type := a;
begin
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
process ( CLK_TEMP_6)
begin
if rising_edge (CLK_TEMP_6) then
case case_counter is
when a =>
ULED <= '0';----GREEN LED ON-----
RLED <= '1';
case_counter <= b;
when b =>
ULED <= '1';
RLED <= '0';-------RED LED ON-----
case_counter <= a;
when others =>
null;
end case;
END IF;
END PROCESS;
process (SYS_CLK_IN)
begin
if (SYS_CLK_IN'event and SYS_CLK_IN='1') then
CNT_6 <= CNT_6 + 1;
if ( CNT_6 = CLK_DIVIDER_6-1 ) then
CLK_TEMP_6 <= not CLK_TEMP_6;
CNT_6 <= 0;
end if;
end if;
end process;
CLK_6MHz <= CLK_TEMP_6 ;
---------------------------------------------------------------------------------------------------------------------------------
end rtl; Many thanks