Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
797 Views

First VHDL project and i am having plenty of problems.

I am trying to write a code that displays weight and height on a 7 segment display depending on the push button that is pressed. 

I am using clk and clk2 as the push button.  

 

F0 and F1 represent the two digit 7 segment displays. 

 

Height and Weight are set using 5 switches each. 

 

 

Now i am getting an error when ever i use the if statement if clk='1' then () end if  

 

and more errors when ever include process without it the code runs other than the part at the bottom where i am trying to turn 3 leds on and off depending on the value of the weight and height 

 

 

 

 

 

 

 

 

 

 

LIBRARY ieee; USE ieee.std_logic_1164.all; ENTITY Proj IS PORT ( weight: IN STD_LOGIC_VECTOR(4 DOWNTO 0) ; height: IN STD_LOGIC_VECTOR (4 DOWNTO 0 ); clk : IN std_logic; clk2: IN std_logic; F0: OUT STD_LOGIC_VECTOR (6 downto 0); F1: OUT STD_LOGIC_VECTOR (6 downto 0); L1: OUT STD_logic; L2: OUT STD_LOGIC; L3: OUT STD_LOGIC ); END Proj; ARCHITECTURE func OF Proj IS BEGIN process(F0 , weight , clk ) begin WITH weight SELECT F0<= "0000001" WHEN "00000" , "0000001" WHEN "00001" , "0000001" WHEN "00010" , "0000001" WHEN "00011" , "0000001" WHEN "00100" , "0000001" WHEN "00101" , "0000001" WHEN "00110" , "0000001" WHEN "00111" , "0000001" WHEN "01000" , "0000001" WHEN "01001" , "1001111" WHEN "01010" , "1001111" WHEN "01011" , "1001111" WHEN "01100" , "1001111" WHEN "01101" , "1001111" WHEN "01110" , "1001111" WHEN "01111" , "1001111" WHEN "10000" , "1001111" WHEN "10001" , "1001111" WHEN "10010" , "1001111" WHEN "10011" , "0010010" WHEN "10100" , "0010010" WHEN "10101" , "0010010" WHEN "10110" , "0010010" WHEN "10111" , "0010010" WHEN "11000" , "0010010" WHEN "11001" , "0010010" WHEN "11010" , "0010010" WHEN "11011" , "0010010" WHEN "11100" , "0010010" WHEN "11101" , "0000110" WHEN "11110" , "0000110" WHEN "11111" ; with weight SELECT F1<= "0000001" WHEN "00000" , "1001111" WHEN "00001" , "0010010" WHEN "00010" , "0000110" WHEN "00011" , "1001100" WHEN "00100" , "0100100" WHEN "00101" , "0100000" WHEN "00110" , "0001111" WHEN "00111" , "0000000" WHEN "01000" , "0000100" WHEN "01001" , "0000001" WHEN "01010" , "1001111" WHEN "01011" , "0010010" WHEN "01100" , "0000110" WHEN "01101" , "1001100" WHEN "01110" , "0100100" WHEN "01111" , "0100000" WHEN "10000" , "0001111" WHEN "10001" , "0000000" WHEN "10010" , "0000100" WHEN "10011" , "0000001" WHEN "10100" , "1001111" WHEN "10101" , "0010010" WHEN "10110" , "0000110" WHEN "10111" , "1001100" WHEN "11000" , "0100100" WHEN "11001" , "0100000" WHEN "11010" , "0001111" WHEN "11011" , "0000000" WHEN "11100" , "0000100" WHEN "11101" , "0000001" WHEN "11110" , "1001111" WHEN "11111" ; end process; process (F0 , clk2 , height) begin F0<= "0000001" WHEN height="00000" else "0000001" WHEN height="00001" else "0000001" WHEN height="00010" else "0000001" WHEN height="00011" else "0000001" WHEN height="00100" else "0000001" WHEN height="00101" else "0000001" WHEN height="00110" else "0000001" WHEN height="00111" else "0000001" WHEN height="01000" else "0000001" WHEN height="01001" else "1001111" WHEN height="01010" else "1001111" WHEN height="01011" else "1001111" WHEN height="01100" else "1001111" WHEN height="01101" else "1001111" WHEN height="01110" else "1001111" WHEN height="01111" else "1001111" WHEN height="10000" else "1001111" WHEN height="10001" else "1001111" WHEN height="10010" else "1001111" WHEN height="10011" else "0010010" WHEN height="10100" else "0010010" WHEN height="10101" else "0010010" WHEN height="10110" else "0010010" WHEN height="10111" else "0010010" WHEN height="11000" else "0010010" WHEN height="11001" else "0010010" WHEN height="11010" else "0010010" WHEN height="11011" else "0010010" WHEN height="11100" else "0010010" WHEN height="11101" else "0000110" WHEN height="11110" else "0000110" WHEN height="11111" ; F1<= "0000001" WHEN height="00000" else "1001111" WHEN height="00001" else "0010010" WHEN height="00010" else "0000110" WHEN height="00011" else "1001100" WHEN height="00100" else "0100100" WHEN height="00101" else "0100000" WHEN height="00110" else "0001111" WHEN height="00111" else "0000000" WHEN height="01000" else "0000100" WHEN height="01001" else "0000001" WHEN height="01010" else "1001111" WHEN height="01011" else "0010010" WHEN height="01100" else "0000110" WHEN height="01101" else "1001100" WHEN height="01110" else "0100100" WHEN height="01111" else "0100000" WHEN height="10000" else "0001111" WHEN height="10001" else "0000000" WHEN height="10010" else "0000100" WHEN height="10011" else "0000001" WHEN height="10100" else "1001111" WHEN height="10101" else "0010010" WHEN height="10110" else "0000110" WHEN height="10111" else "1001100" WHEN height="11000" else "0100100" WHEN height="11001" else "0100000" WHEN height="11010" else "0001111" WHEN height="11011" else "0000000" WHEN height="11100" else "0000100" WHEN height="11101" else "0000001" WHEN height="11110" else "1001111" WHEN height="11111" ; end process; L1 <= '1' WHEN ( weight>'30' AND weight<'15' ) ELSE '0'; L2 <= '1' WHEN ( height>'30' AND weight<'10' ) ELSE '0'; L3 <= '1' WHEN L1='0' AND L2='0' ELSE'0' ; END func;
0 Kudos
4 Replies
Altera_Forum
Honored Contributor I
55 Views

First off, you should not be using the push buttons as clocks. It will be a very bad signal and will bounce, giving you lots of edges on each press. Also, it will not be possible to do timing analysis, and the signal will vary with temperature. I dont actually see any clock usage in your processes. 

 

I suggest you source a real clock from a crystal on the board or from a PLL on the chip (that will need a clock from a crystal). 

 

Second, unless you are using vhdl 2008, with..select is not allowed inside a process 

 

Finally - did you draw your circuit on paper before you wrote any code? VHDL is a hardware description language so unless you know what the circuit is you will not be able to write any HDL.
Altera_Forum
Honored Contributor I
55 Views

its not really a clock , i dont know why i called it clk i am just used to it.  

its just a signal to choose which output to show. 

 

i think my problem is the With-Select inside a process.  

 

What can i replace it with. 

 

or can i use something else other than an if function ? i tried ANDing but it isnt working.
Altera_Forum
Honored Contributor I
55 Views

i did this instead 

 

F1<= "0000001" WHEN weight="00000" AND clk='1' else "0000001" WHEN weight="00001" AND clk='1' else "0000001" WHEN weight="00010" AND clk='1' else "0000001" WHEN weight="00011" AND clk='1' else "0000001" WHEN weight="00100" AND clk='1' else "0000001" WHEN weight="00101"AND clk='1' else "0000001" WHEN weight="00110" AND clk='1' else "0000001" WHEN weight="00111" AND clk='1' else "0000001" WHEN weight="01000" AND clk='1' else "0000001" WHEN weight="01001" AND clk='1' else "1001111" WHEN weight="01010" AND clk='1' else "1001111" WHEN weight="01011" AND clk='1' else "1001111" WHEN weight="01100" AND clk='1' else "1001111" WHEN weight="01101" AND clk='1' else "1001111" WHEN weight="01110" AND clk='1' else "1001111" WHEN weight="01111" AND clk='1' else "1001111" WHEN weight="10000" AND clk='1' else "1001111" WHEN weight="10001" AND clk='1' else "1001111" WHEN weight="10010" AND clk='1' else "1001111" WHEN weight="10011" AND clk='1' else "0010010" WHEN weight="10100" AND clk='1' else "0010010" WHEN weight="10101" AND clk='1' else "0010010" WHEN weight="10110" AND clk='1' else "0010010" WHEN weight="10111" AND clk='1' else "0010010" WHEN weight="11000" AND clk='1' else "0010010" WHEN weight="11001" AND clk='1' else "0010010" WHEN weight="11010" AND clk='1' else "0010010" WHEN weight="11011" AND clk='1' else "0010010" WHEN weight="11100" AND clk='1' else "0010010" WHEN weight="11101" AND clk='1' else "0000110" WHEN weight="11110" AND clk='1' else "0000110" WHEN weight="11111" AND clk='1' else "0000001" WHEN height="00000" AND clk2='1' else "0000001" WHEN height="00001" AND clk2='1' else "0000001" WHEN height="00010" AND clk2='1' else "0000001" WHEN height="00011" AND clk2='1' else "0000001" WHEN height="00100" AND clk2='1' else "0000001" WHEN height="00101" AND clk2='1' else "0000001" WHEN height="00110" AND clk2='1' else "0000001" WHEN height="00111" AND clk2='1' else "0000001" WHEN height="01000" AND clk2='1' else "0000001" WHEN height="01001" AND clk2='1' else "1001111" WHEN height="01010" AND clk2='1' else "1001111" WHEN height="01011" AND clk2='1' else "1001111" WHEN height="01100" AND clk2='1' else "1001111" WHEN height="01101" AND clk2='1' else "1001111" WHEN height="01110" AND clk2='1' else "1001111" WHEN height="01111" AND clk2='1' else "1001111" WHEN height="10000" AND clk2='1' else "1001111" WHEN height="10001" AND clk2='1' else "1001111" WHEN height="10010" AND clk2='1' else "1001111" WHEN height="10011" AND clk2='1' else "0010010" WHEN height="10100" AND clk2='1' else "0010010" WHEN height="10101" AND clk2='1' else "0010010" WHEN height="10110" AND clk2='1' else "0010010" WHEN height="10111" AND clk2='1' else "0010010" WHEN height="11000" AND clk2='1' else "0010010" WHEN height="11001" AND clk2='1' else "0010010" WHEN height="11010" AND clk2='1' else "0010010" WHEN height="11011" AND clk2='1' else "0010010" WHEN height="11100" AND clk2='1' else "0010010" WHEN height="11101" AND clk2='1' else "0000110" WHEN height="11110" AND clk2='1' else "0000110" WHEN height="11111" ; F0<= "0000001" WHEN weight="00000" AND clk='1' else "1001111" WHEN weight="00001" AND clk='1' else "0010010" WHEN weight="00010" AND clk='1' else "0000110" WHEN weight="00011" AND clk='1' else "1001100" WHEN weight="00100" AND clk='1' else "0100100" WHEN weight="00101" AND clk='1' else "0100000" WHEN weight="00110" AND clk='1' else "0001111" WHEN weight="00111" AND clk='1' else "0000000" WHEN weight="01000" AND clk='1' else "0000100" WHEN weight="01001" AND clk='1' else "0000001" WHEN weight="01010" AND clk='1' else "1001111" WHEN weight="01011" AND clk='1' else "0010010" WHEN weight="01100" AND clk='1' else "0000110" WHEN weight="01101" AND clk='1' else "1001100" WHEN weight="01110" AND clk='1' else "0100100" WHEN weight="01111" AND clk='1' else "0100000" WHEN weight="10000" AND clk='1' else "0001111" WHEN weight="10001" AND clk='1' else "0000000" WHEN weight="10010" AND clk='1' else "0000100" WHEN weight="10011" AND clk='1' else "0000001" WHEN weight="10100" AND clk='1' else "1001111" WHEN weight="10101" AND clk='1' else "0010010" WHEN weight="10110" AND clk='1' else "0000110" WHEN weight="10111" AND clk='1' else "1001100" WHEN weight="11000" AND clk='1' else "0100100" WHEN weight="11001" AND clk='1' else "0100000" WHEN weight="11010" AND clk='1' else "0001111" WHEN weight="11011" AND clk='1' else "0000000" WHEN weight="11100" AND clk='1' else "0000100" WHEN weight="11101" AND clk='1' else "0000001" WHEN weight="11110" AND clk='1' else "1001111" WHEN weight="11111" AND clk='1' else "0000001" WHEN height="00000" AND clk2='1' else "1001111" WHEN height="00001" AND clk2='1' else "0010010" WHEN height="00010" AND clk2='1' else "0000110" WHEN height="00011" AND clk2='1' else "1001100" WHEN height="00100" AND clk2='1' else "0100100" WHEN height="00101" AND clk2='1' else "0100000" WHEN height="00110" AND clk2='1' else "0001111" WHEN height="00111" AND clk2='1' else "0000000" WHEN height="01000" AND clk2='1' else "0000100" WHEN height="01001" AND clk2='1' else "0000001" WHEN height="01010" AND clk2='1' else "1001111" WHEN height="01011" AND clk2='1' else "0010010" WHEN height="01100" AND clk2='1' else "0000110" WHEN height="01101" AND clk2='1' else "1001100" WHEN height="01110" AND clk2='1' else "0100100" WHEN height="01111" AND clk2='1' else "0100000" WHEN height="10000" AND clk2='1' else "0001111" WHEN height="10001" AND clk2='1' else "0000000" WHEN height="10010" AND clk2='1' else "0000100" WHEN height="10011" AND clk2='1' else "0000001" WHEN height="10100" AND clk2='1' else "1001111" WHEN height="10101" AND clk2='1' else "0010010" WHEN height="10110" AND clk2='1' else "0000110" WHEN height="10111" AND clk2='1' else "1001100" WHEN height="11000" AND clk2='1' else "0100100" WHEN height="11001" AND clk2='1' else "0100000" WHEN height="11010" AND clk2='1' else "0001111" WHEN height="11011" AND clk2='1' else "0000000" WHEN height="11100" AND clk2='1' else "0000100" WHEN height="11101" AND clk2='1' else "0000001" WHEN height="11110" AND clk2='1' else "1001111" WHEN height="11111" AND clk2='1';  

 

 

and it works thanks for the help.
Altera_Forum
Honored Contributor I
55 Views

You could have used an if statemend and case statement inside the process: 

 

process(weight, clk) begin if clk = '1' then case weight is when "00000" => when "00001" => ..... end case end if; end process;
Reply