VHDL Pins logic

Thread Starter

Dritech

Joined Sep 21, 2011
907
Hi all,

I was using a VHDL code which consists from switches. I used the following code to detect the switch activity:

if (SW = '1') then

When looking at the datasheet of the FPGA board I realized that the pins are connected with pullup resistors and a switch to ground.
Should the code be: if (SW = '0') then ?

If so, why is the program working fine with: if (SW = '1') then ?

Also, what is meant by: (others => '0'); ?

Thanks in advance and sorry for my poor English.
 

tshuck

Joined Oct 18, 2012
3,534
Hi all,

I was using a VHDL code which consists from switches. I used the following code to detect the switch activity:

if (SW = '1') then

When looking at the datasheet of the FPGA board I realized that the pins are connected with pullup resistors and a switch to ground.
Should the code be: if (SW = '0') then ?

If so, why is the program working fine with: if (SW = '1') then ?
...probably because there isn't much of a difference in a closed switch versus an open switch from an external point of view.

This means your switch is actually open (no current between connections) when the statements after your if statement are evaluated.

Also, what is meant by: (others => '0'); ?
It means all other bits than those specified are '0'.

If you had a four-bit std_logic_vector, named data_bus, then
Code:
data_bus <= (others => '0');
is equivalent to
Code:
data_bus <= "0000";
This is quite useful when using large vectors.
 
Top