how to change variable in case statement VHDL

Discussion in 'Embedded Systems and Microcontrollers' started by vtbvtb, Sep 11, 2012.

  1. vtbvtb

    Thread Starter New Member

    Sep 11, 2012
    3
    0
    Hello,

    I have a problem with logic of case statement in vhdl. I wonder if the variable that selects the case condition can be changed within the statement. To clarify:
    Code ( (Unknown Language)):
    1.  
    2.  
    3. process(clk)
    4.  
    5. variable aaa: std_logic_vector(2 downto 0):="000";
    6.  
    7. case  aaa  is
    8.  
    9.     when  "000"  =>
    10.       if () then
    11.         something
    12.       end if;
    13.       aaa := aaa+1;
    14.  
    15.     when  "001" =>
    16.         if() then
    17.       something
    18.         elsif() then
    19.         something
    20.          else
    21.          something
    22.        end if;
    23.       aaa := aaa+1;
    24.  
    25.     when others =>
    26.       -- sequential statements
    27.  
    28.  
    29. end   case ;
    30.  
    31. end process;
    32.  
    33.  
    When I tried to synthesize a code with that algorithm, it displays an error. What is the problem here? Can't I change the variable within the case? Or the problem is about the if statements in the case? I know that it looks like a pl code instead of a HDL code, but I'm used to pl's, and getting started to VHDL
     
  2. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    We are no oracles, so unless you post the exact wording of the error I doubt that we can be of much help. I currently don't have the development suite running, so I cant try the code for myself.
     
  3. vtbvtb

    Thread Starter New Member

    Sep 11, 2012
    3
    0
    Code ( (Unknown Language)):
    1.  
    2. PROCESS (h_position, v_position)
    3. variable cnt : std_logic_vector(3 downto 0 ):="0000";
    4. variable decimalcnt: std_logic_vector(3 downto 0):="0000";
    5. BEGIN
    6. IF ((hareketsiz_hedef > "000") AND (h_position >= YK4) AND (h_position < YK4+YB4) AND (v_position >= DK4) AND (v_position < DK4+DB4)) THEN
    7. y <= GS4 & "00";
    8. cr <= CR4 & "00";
    9. cb <= CB4 & "00";
    10. ELSIF ((hareketsiz_hedef > "001") AND (h_position >= YK5) AND (h_position < YK5+YB5) AND (v_position >= DK5) AND (v_position < DK5+DB5)) THEN
    11. y <= GS5 & "00";
    12. cr <= CR5 & "00";
    13. cb <= CB5 & "00";
    14. ELSE
    15. if ( f='1') then
    16. case1: CASE cnt IS
    17. WHEN "0000" =>
    18. IF ((hareketsiz_hedef > "000") AND (h_position >= "1010001010") AND (h_position < "1010010100") AND (v_position >= "0110100100") AND (v_position < "0110100110")) OR
    19. ((hareketsiz_hedef > "000")AND (h_position >= "1010001010") AND (h_position < "1010001100") AND (v_position >= "0110100110") AND (v_position < "0110101110")) OR
    20. ((hareketsiz_hedef > "000")AND (h_position >= "1010001010") AND (h_position < "1010010100") AND (v_position >= "0110101100") AND (v_position < "0110101110")) OR
    21. ((hareketsiz_hedef > "000") AND (h_position >= "1010010010") AND (h_position < "1010010100") AND (v_position >= "0110100110") AND (v_position < "0110101110"))THEN
    22. y <= "0001000000";
    23. cr <= "1000000000";
    24. cb <= "1000000000";
    25. ELSIF((hareketsiz_hedef > "000") AND(h_position >= "1010001100") AND (h_position < "1010010010") AND (v_position >= "0110100100") AND (v_position < "0110101100")) THEN
    26. y <= "1110101100";
    27. cr <= "1000000000";
    28. cb <= "1000000000";
    29. END IF;
    30. cnt := cnt +1;
    31. WHEN "0001" =>
    32. IF((hareketsiz_hedef > "000") AND(h_position >= "1010010010") AND (h_position < "1010010100") AND (v_position >= "0110100110") AND (v_position < "0110101110"))THEN
    33. y <= "0001000000";
    34. cr <= "1000000000";
    35. cb <= "1000000000";
    36. END IF;
    37. cnt := cnt +1;
    38. WHEN "0010" =>
    39. IF ( (hareketsiz_hedef > "000")AND (h_position >= "1010001010") AND (h_position < "1010010100") AND (v_position >= "0110100100") AND (v_position < "0110100110")) OR
    40. ((hareketsiz_hedef > "000") AND (h_position >= "1010001010") AND (h_position < "1010001100") AND (v_position >= "0110101010") AND (v_position < "0110101110")) OR
    41. ((hareketsiz_hedef > "000")AND(h_position >= "1010001010") AND (h_position < "1010010100") AND (v_position >= "0110101100") AND (v_position < "0110101110")) OR
    42. ((hareketsiz_hedef > "000")AND (h_position >= "1010010010") AND (h_position < "1010010100") AND (v_position >= "0110100110") AND (v_position < "0110101010")) OR
    43. ((hareketsiz_hedef > "000") AND(h_position >= "1010001010") AND (h_position < "1010010100") AND (v_position >= "0110101000") AND (v_position < "0110101010"))THEN
    44. y <= "0001000000";
    45. cr <= "1000000000";
    46. cb <= "1000000000";
    47. END IF;
    48. cnt :=cnt+1;
    49. WHEN others => null;
    50. END CASE;
    51. case2: CASE decimalcnt IS
    52. WHEN "0000" =>
    53. IF ((hareketsiz_hedef > "000") AND(h_position >= "1001111011") AND (h_position < "1010000101") AND (v_position >= "0110100100") AND (v_position < "0110100110")) OR
    54. ((hareketsiz_hedef > "000")AND (h_position >= "1001111011") AND (h_position < "1001111101") AND (v_position >= "0110100111") AND (v_position < "0110101110")) OR
    55. ((hareketsiz_hedef > "000")AND (h_position >= "1010000011") AND (h_position < "1010000101") AND (v_position >= "0110100111") AND (v_position < "0110101110")) OR
    56. ((hareketsiz_hedef > "000") AND (h_position >= "1001111011") AND (h_position < "1010000101") AND (v_position >= "0110101100") AND (v_position < "0110101110"))THEN
    57. y <= "0001000000";
    58. cr <= "1000000000";
    59. cb <= "1000000000";
    60. ELSIF((hareketsiz_hedef > "000")AND(h_position >= "1001111101") AND (h_position < "1010000011") AND (v_position >= "0110100100") AND (v_position < "0110101100")) THEN
    61. y <= "1110101100";
    62. cr <= "1000000000";
    63. cb <= "1000000000";
    64. END IF;
    65. WHEN "0001" =>
    66. IF ((hareketsiz_hedef > "000")AND(h_position >= "1010000011") AND (h_position < "1010000101") AND (v_position >= "0110100100") AND (v_position < "0110101110"))THEN
    67. y <= "0001000000";
    68. cr <= "1000000000";
    69. cb <= "1000000000";
    70. END IF;
    71. WHEN "0010" =>
    72. IF ( (hareketsiz_hedef > "000")AND (h_position >= "1001111011") AND (h_position < "1010000101") AND (v_position >= "0110100100") AND (v_position < "0110100110")) OR
    73. ((hareketsiz_hedef > "000") AND (h_position >= "1001111011") AND (h_position < "1010000101") AND (v_position >= "0110101010") AND (v_position < "0110101110")) OR
    74. ((hareketsiz_hedef > "000")AND(h_position >= "1001111011") AND (h_position < "1010000101") AND (v_position >= "0110101100") AND (v_position < "0110101110")) OR
    75. ((hareketsiz_hedef > "000")AND (h_position >= "1001111011") AND (h_position < "1010000101") AND (v_position >= "0110100110") AND (v_position < "0110101010")) OR
    76. ((hareketsiz_hedef > "000") AND(h_position >= "1001111011") AND (h_position < "1010000101") AND (v_position >= "0110101000") AND (v_position < "0110101010"))THEN
    77. y <= "0001000000";
    78. cr <= "1000000000";
    79. cb <= "1000000000";
    80. END IF;
    81. WHEN "0011" =>
    82. IF ((hareketsiz_hedef > "000")AND(h_position >= "1001111011") AND (h_position < "1010000101") AND (v_position >= "0110100100") AND (v_position < "0110100110")) OR
    83. ((hareketsiz_hedef > "000") AND(h_position >= "1001111011") AND (h_position < "1010000101") AND (v_position >= "0110101100") AND (v_position < "0110101110")) OR
    84. ((hareketsiz_hedef > "000") AND(h_position >= "1001111011") AND (h_position < "1010000101") AND (v_position >= "0110100110") AND (v_position < "0110101110")) OR
    85. ((hareketsiz_hedef > "000") AND(h_position >= "1001111011") AND (h_position < "1010000101") AND (v_position >= "0110101000") AND (v_position < "0110101010"))THEN
    86. y <= "0001000000";
    87. cr <= "1000000000";
    88. cb <= "1000000000";
    89. END IF;
    90. WHEN others =>
    91. null; END CASE; end if;
    92. END IF;END PROCESS;
    93.  
     
  4. vtbvtb

    Thread Starter New Member

    Sep 11, 2012
    3
    0
    the code is too long to inspect, I'm sorry about that. Now I got rid of the error, code is implemented on fpga but I still have a problem. This is a video maker code and the aim is creating a counter on the screen. Variable "cnt" and "decimalcnt"should update on the screen but now, I only see a "0" which corresponds to where "decimalcnt" should appear. And "cnt" is not seen at all. However, "cnt" should have count from 0 to 2. I hope I could clarify the problem little bit.
     
  5. Brownout

    Well-Known Member

    Jan 10, 2012
    2,375
    998
    I think you need Libary unsigned and use unsigned.all in order to increment the std_logic_vector.
     
Loading...