Community
cancel
Showing results for
Did you mean: Honored Contributor I
864 Views

## New Guy Needs Help with vectors

I have a code for a MUX whereby I have an input named SW which comprises of SW (0 through 3). I am using case statement for a seven segment display. This is just to show 0 all the way to F. I copied this code from another program I used when I had the NEXYS4 DDR FPGA development board which used the Vivado IDE. For example

case SW is

when "00000"=> a_to_g <="1000000";

when "00001"=> a_to_g <="1111001";

when "00010"=> a_to_g <="0100100";

when "00011"=> a_to_g <="0110000";

when "00100"=> a_to_g <="0011001"; etc.....

So the first instance would yield a 0 on the seven segment display. Then a 1, 2, 3, etc.... So I am trying to do this from 0 through F so I am wondering how to declare SW because SW actually SW(0), SW(1) SW(2), SW(3), and SW(4). In the beginning of the code, I declared SW as such. SW : in STD_LOGIC_VECTOR (4 downto 0);. Can anyone help me to make this happen. I am sure there is a way but I can not figure it out. I was used to using vivado IDE using the NEXYS4 DDR. When I used to declare SW as a vector in vivado, it automatically had be declare each individual SW(0 through 4). Please help. Thank you.
5 Replies Honored Contributor I
32 Views

Don't quite understand the question as you can just use a std_logic_vector as you suggest. Why not pay the code and specify what the problem is. Honored Contributor I
32 Views

The code is as follows.

----------------------------------------------------------------------------------

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

entity MUX_0thruF is

Port ( SW : in STD_LOGIC_VECTOR (4 downto 0);

SEL : in STD_LOGIC;

a_to_g : out STD_LOGIC_VECTOR (6 downto 0);

an : out STD_LOGIC_VECTOR (7 downto 0);

dp : out STD_LOGIC;

LD0 : out STD_LOGIC);

end MUX_0thruF;

architecture Behavioral of MUX_0thruF is

begin

LD0 <= SW(4);

dp <= not SW(4);

process(SW)

begin

case SW is

when "00000"=> a_to_g <="1000000";

when "00001"=> a_to_g <="1111001";

when "00010"=> a_to_g <="0100100";

when "00011"=> a_to_g <="0110000";

when "00100"=> a_to_g <="0011001";

when "00101"=> a_to_g <="0010010";

when "00110"=> a_to_g <="0000010";

when "00111"=> a_to_g <="1111000";

when "01000"=> a_to_g <="0000000";

when "01001"=> a_to_g <="0011000";

when "01010"=> a_to_g <="0001000";

when "01011"=> a_to_g <="0000011";

when "01100"=> a_to_g <="1000110";

when "01101"=> a_to_g <="0100001";

when "01110"=> a_to_g <="0000110";

when "01111"=> a_to_g <="0001110";

when "1----"=> a_to_g <="0000000";

when others => a_to_g <="1111111";

end case;

end process;

process(SEL)

begin

case SEL is

when '0' => an <= "11111110";

when '1' => an <= "01111111";

when others => an <= "11111111";

end case;

end process;

end Behavioral;

The problem I am having is the last part

process(SEL)

begin

case SEL is

when '0' => an <= "11111110";

when '1' => an <= "01111111";

when others => an <= "11111111";

end case;

end process;

I want to be able to use a switch to turn on one seven segment display then switch to another if I choose to. However that would entail shutting all the seven segment displays except for one. Then turning that one off and turning the other one on. This would also mean that instead of declaring the actual parts of the seven segment display, I would have to declare a whole display to be able to turn in on or off. I do not see a pin assignment for the whole display. I was able to do that for the switches which was declared as a vector and for the "a_to_g". I was able to use the pin assighments and declare what each one is. However I do not see where in the pin declaration, how to declare a whole segment display. The only information I am seeing is HEX0, HEX0, HEX0, .... So I originally thought I can declare a whole dislay as HEX0 but the system is telling me that is not a valid pin assignment. Can someone help me with this please. Also, I do not see a pin assignment for the decimal point or dp. Thank you. Honored Contributor I
32 Views

There isn't a single pin for turning the whole 7seg off. You can use another bit (switch) as part of the select to determine if each segment should be on or off. Honored Contributor I
32 Views

--- Quote Start ---

There isn't a single pin for turning the whole 7seg off. You can use another bit (switch) as part of the select to determine if each segment should be on or off.

--- Quote End ---

So then I can omit the SEL declaration and switch statement at the bottom altogether? This would mean that I only use the display on that one display I chose. Is that correct? Also, if I wanted to switch between one display or another, then would have to declare a_to_g1 and a_to_g2. In this manner, I would be able to declare the something to the effect of the following?

if SEL <= '1', then (a_to_g1 and not a_to_g2)

if SEL <= '0', then (not a_to_g1 and a_to_g2) Honored Contributor I
32 Views

Something like that, but written with the correct syntax 