0

On my BASYS-3 board I want to use 4 of the switches and output different things depending on the combination of these switches. For example, if switch 12 is turned on I want a value assigned to a signal. I managed to upload my code onto the board but when I flicked through the switches nothing happened on the display.

Below is part of my constraints file for this segment of code:

#Switches
#SW12
set_property -dict { PACKAGE_PIN W2   IOSTANDARD LVCMOS33 } [get_ports {i_SW[0]}]
#SW13
set_property -dict { PACKAGE_PIN U1   IOSTANDARD LVCMOS33 } [get_ports {i_SW[1]}]
#SW14
set_property -dict { PACKAGE_PIN T1   IOSTANDARD LVCMOS33 } [get_ports {i_SW[2]}]
#SW15
set_property -dict { PACKAGE_PIN R2   IOSTANDARD LVCMOS33 } [get_ports {i_SW[3]}] 

and this is how I have written it in the port map of my top level entity:

i_SW : in STD_LOGIC_VECTOR (3 downto 0)

to then be called in this fashion in a separate entity:

case i_SW is
    when "1000" => -- data select 0
        --doesn't matter ;
        --doesn't matter ;

This code is supposed to read the switch values and store it in the STD_LOGIC_VECTOR and then read it for the case statement. For example, if SW12 was flicked on I would expect the vector to hold "1000" and so it would go into that case.

I am wondering whether I have written this in the incorrect format and there's a different way to do it? Should I store it in an array and the declare that array in the port map to then use in other entities?

Thank you

EDIT: When I simulate the code it shows me that i_SW is 'U' which I believe means uninitialized but that is probably just a problem with my testbench.

3
  • 1
    It looks like you are on the right track. Since "nothing happened on the display", first try sending a fixed pattern to the output, see if that works. If it does, then try copying inputs to outputs, and see if they respond when you change inputs. Add your processing only after you know outputs and inputs are all working. Commented Dec 7, 2020 at 16:27
  • Hi Ben, thank you for the reply. I didn't say this as I didn't think it was important but now I'm thinking it may be. When I turned on the board the display showed 0000 which is my final case statement (if others => 0000). Would this change your answer at all? Commented Dec 7, 2020 at 16:39
  • I would still follow the same steps of using extremely simple VHDL first, to verify that your port and pin mappings are working the way that you expect. Commented Dec 7, 2020 at 17:46

1 Answer 1

1

The vector is declared with downto, so the order of elements is 3,2,1,0 and "1000" corresponds to SW15, not SW12.

Also, the switches may be low-active, a lot of development boards are wired like this -- then you'd have to invert the values as well.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Simon, thank you for the reply. You say that "1000" corresponds to SW15 however when I plugged the board in and I turned on all of the switches one after the other to see whether anything had been mis-represented SW15 did no more to my display than flicking SW12 did. I don't believe the the switches are low-active but again, thank you for your reply.
The switches are SPDT. In any event there's a '1' position and a '0' position. A more interesting issue might be 'does the code simulate?'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.