Search code examples
randomerror-handlingvhdlleap-year

VHDL Case statement error


i create a function that generate a random number. That number represent an year. I need to find if that year is a leap-year. The range of generated numbers is between 2000 and 2017, so i think that i could use an case instead of applying a formula to find the leap years.

architecture arh_afisare of afisare is      
signal year: integer;
signal leap_year: integer;
begin
process
begin
    year <= random_gen(2000, 2017); 
    case year is
        when '2000' => leap_year <='1';
        when '2004' => leap_year <='1';
        when '2008' => leap_year <='1';
        when '2012' => leap_year <='1';
        when '2016' => leap_year <='1';
        when others => leap_year <='0';
    end case;
wait for 100 ns;
end process;
end architecture;

I get this error on every line with 'when' expect the last one.

Error: COMP96_0019: Afisare.vhd : (28, 9): Keyword 'others' expected.


Solution

  • Look at your case lines:

    when '2000' => leap_year <='1';
    

    2000 is an integer, but you have put single quote marks around it. This is not a valid construct; just delete the single quotes:

    when 2000 => leap_year <='1';
    

    Per the comment, the choice of integer for leap_year is a bit strange. If you define this with type std_logic, your assignment of leap_year <= '1' becomes valid. Alternatively, if integer is appropriate, change the assignment to leap_year <= 1 .