Help with connecting a pushbutton

Anything about FPGA boards, like how to assemble SMD components, find low-voltage regulators, FPGA configuration...

Help with connecting a pushbutton

Postby itx » Sat Nov 21, 2009 3:15 pm

Hello there.
Im very new to fpgas, and overall this type of thing, and i seem to have run into a problem.

The idea is simple-just to connect a pushbutton, but i can't seem to work with it. This is how i connected it
Image

and this is the code that i use

Code: Select all
module button(clk,PB, LED1,LED2);

input clk;
input PB; 

output LED1;
output LED2;


reg r1, r2;
always @(posedge clk) begin
  r1 <= PB;
  r2 <= r1;
end
assign LED1 = r2;
assign LED2 = ~r2;

endmodule

(found part or it somewhere in the forum)
One LED is always on, and nothing else happens whether i push the button or not.

What am i doing wrong?
itx
 
Posts: 8
Joined: Sat Nov 21, 2009 2:58 pm

Postby vlado » Mon Nov 23, 2009 7:11 pm

Why you don't use only one signal to assign?
Moreover, pushbutton will produce many glitches, so you must use digital filter and/or capacitor, to reduce them. Put capacitor parallel to button.
vlado
 
Posts: 29
Joined: Mon Apr 16, 2007 5:40 pm

Postby itx » Tue Nov 24, 2009 12:11 pm

Hey,
thanks for the reply.
What do you mean by
Why you don't use only one signal to assign?


If this is what you're talking about, then i do not know. I've seen it several times tho.. Perhaps somebody could explain.
Code: Select all
  r1 <= PB;
  r2 <= r1;


As for the pushbutton, I know that it will produce gliches. I need a debouncer for that, or a hardware solution( like a cap. that you mentioned). This was purely for testing if the fpga gets any signals from the button, which it didn't.

Anyway I have solved the button problem, stupid me for not paying enough attention to the manual and not selecting the right pins.
itx
 
Posts: 8
Joined: Sat Nov 21, 2009 2:58 pm

Postby itx » Sat Nov 28, 2009 2:07 pm

Well, that works too. thanks

Next question:
How do I connect two pushbuttons?

Adding a second one the same way as i added the first one( imagine those 3 branches copied and connect in parallel, the input pin is different ofcourse), somehow makes both LED's shine , when just one button is pushed.
This is the code i use as an example
Code: Select all
module button(clk,PB1,PB2,LED1,LED2);

input clk;
input PB1;
input PB2; 

output LED1;
output LED2;

assign LED1 = ~PB1;
assign LED2 = ~PB2;

endmodule
itx
 
Posts: 8
Joined: Sat Nov 21, 2009 2:58 pm

Postby moth » Sat Nov 28, 2009 7:06 pm

I am really new to this, too, but the only thing I can think of is you using the same pin in the pin planner for both inputs. When you fix this, please post back. I want to learn a bit, too :D

By the way, both LEDs shine regardless of which button you press, or only one specific button shines both LEDs?

And why are you negating the inputs for assignment?
moth
 
Posts: 5
Joined: Thu Nov 26, 2009 9:45 pm

Postby itx » Sat Nov 28, 2009 9:00 pm

Hey there, thanks for the reply.

This time I'm sure that i set up the pin planner correctly. PB1 pin is different than PB2.

And the LEDs shine regardless of the button. If i press PB1 - both leds shine, if i press PB2 - both leds shine again. Pushing them both at the same time also makes both leds shine.

I assume you're asking about the ~PB ? Due to the way the buttons are connected, the input is '1' when the button is depressed, and '0' when the button is pressed. This would mean that the LED's are ON when the button is depressed. Negating PB inverts that, so that leds shine when the button is pushed.

Or, atleast thats how I understand it. I have never before seen this method of connecting a pushbutton in the first place. The more you learn...
itx
 
Posts: 8
Joined: Sat Nov 21, 2009 2:58 pm

Postby moth » Sat Nov 28, 2009 10:00 pm

In my (limited) understanding, there can't be any problem with your code or FPGA configuration if you're really using that code and if the pins are right. Maybe you're missing something in your buttons' circuitry.

If you posted schematics here again, maybe I could help you better, I'm not sure if I get your explanation of paralleling the "branches". Make sure you only fork the terminals of your circuit going to ground and VCCIO and keep the rest separate. Also keep in mind that I'm also new to electronics.... :oops:

-- edit --

And please make sure you include the LED connections too, just in case.

-- edit 2 --

I would try wiring stuff like this (I don't know how you did it):
Image

If you use only one resistor, I think what you are reporting would happen, as any contact - caused by any of the buttons - to ground would ground both pins.
Last edited by moth on Sun Nov 29, 2009 1:23 am, edited 2 times in total.
moth
 
Posts: 5
Joined: Thu Nov 26, 2009 9:45 pm

Postby itx » Sun Nov 29, 2009 8:40 am

Moth, you're awesome!

I did not use 2 resistors - that was my problem. Thought that only one would suffice. :oops: Shame on me. (Do I get minus points for not being specific enough? :D )

While toying with the fpga, I noticed that just by connecting the input pin - to a button - to ground achieves the same result. Is this an incorrect way of connecting a button?

Thanks a lot guys
itx
 
Posts: 8
Joined: Sat Nov 21, 2009 2:58 pm

Postby moth » Sun Nov 29, 2009 5:32 pm

I also thought that connecting pins like that was right, but I heard some guys saying that "dangling" pins (those not connected to either ground or source) are at an "undefined" state. That is, it's not clear whether they are high or low.

I'm not sure, but I'd guess some manufacturers would arbitrarily decide to set all non-connected pins to high, for example, so you're safer off always connecting everything. It's like a good practice, I think.

And, by the way, I think a resistor between the pins and either source or ground is always also a good idea. I guess it will minimize the amount of current flow while achieving the same result. Not sure what the consequences are. Probably less power consuption, less heat dissipating in the IC and thus maybe longer component duration. Unsure, thought.. If anybody else could clarify this here, I'd be glad, too.

-- edit --

itx, do you like video-games and, particularly, game development?
moth
 
Posts: 5
Joined: Thu Nov 26, 2009 9:45 pm

Postby itx » Sun Nov 29, 2009 9:55 pm

The undefined pin explanation makes perfect sense, thanks.

Might I ask where you learned all of this?
-

As for the video games, yeah, i like them. Who doesn't though. Game development is a whole different question, to which I don't have an answer. Simply because I have never tried anything related to that. Would have loved to toy with it though :)
itx
 
Posts: 8
Joined: Sat Nov 21, 2009 2:58 pm

Postby moth » Sun Nov 29, 2009 11:20 pm

First, it may make sense, but keep in mind that I'm not sure this is true XD You should ask somebody with better electronics background.

I believe I bought this NOR gates IC (SN74LS02N) one day and its pins were all high when not connected. I asked a friend of mine why this happened, and he explained me this thing about pins being at an "undefined" state when not connected. I'm not sure about the manufacturers thing I said. That was just my guess.

The only thing I ever really seriously read about electronics, as far as I can remember, was some slides from a course called "Design Your Own Console" by André LaMothe I found somewhere.. I won't post links here as I'm sure it is prohibited, but I can mail you some tips on the subject, if you know what I mean :lol: Drop me a mail at amascout at gmail dot com if you are interested.
moth
 
Posts: 5
Joined: Thu Nov 26, 2009 9:45 pm

Postby tkbits » Mon Nov 30, 2009 5:50 pm

It depends on the technology.

TTL inputs like the ones in the 74xx chips will act as if connected to high, if unconnected.

This is definitely not true of MOS inputs (CMOS, nMOS, pMOS). If you wave a finger in front of a floating (unconnected) CMOS input, it can switch between sensing as high or low.

Remove the resistor and see if you can turn the LED on and off just by waving your finger over the floating input pin. The FPGA might enable internal pullups on input pins - disable them if possible.

Or hook up a relay (via a transistor). If the floating input is sensitive, you can hear the relay click on and off as you wave your finger over the floating input.
tkbits
 
Posts: 114
Joined: Mon Aug 02, 2004 10:36 pm

Postby moth » Mon Nov 30, 2009 9:57 pm

Just in case, reading tkbits' posts I found the term "high impedance". Here is the link: http://en.wikipedia.org/wiki/High_impedance

Isn't that precisely the subject? XD
moth
 
Posts: 5
Joined: Thu Nov 26, 2009 9:45 pm


Return to General boards