NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Basic Electronics » Not meeting input Voltage Threshold, amplify? and Do I need a buffer? (Button input, LED output)
April 12, 2011 by Ever25 |
Same project two issues that I'm trying to resolve and understand. 1) I have been trying to use a button debounce circuit using a tacile pushbutton connected to a Hex inverter w/ Schmitt triger input (DM74ALS14) to input a HIGH to an input on the 168 micro. According to the data sheet (if I'm understanding this correctly) the Voh Min value is Vcc-2 (I am using a VCC of +5V, so my Voh Min "should be" ~3.0V) and when I actually measure the output of the inverter IC I get about 2.1V. From the 168 data sheet it says that the input threshold is ~3.0V (Vih ~ 0.6Vcc = 3.0V, assuming a Vcc of +5V). So i'm assuming that if I am understanding this correctly then my IC output to my micro is just too low for it to recognize the input as a HIGH (Logic 1). Please feel free to correct me if I am not following the right path/thought process here. So if this is my problem would I be able to use a BJT to boost the output of the IC to the input of the micro to get my desired threshold voltage? Or would that be an incorrect way to approach this problem?2) Omitting the inverter IC and just using the output from the tact button I can get micro to read the single pushbutton as an input and my LED will light. Problem occurs if I attach more than one pushbutton as an input on PORTB (PB4 and PB5) then neither button will activate the code for the pushbutton to light the LED (I'll try to put up the code but basically PORTB is looking for any input to go LOW, which will trigger a LED on PORTC (PC5) to turn on). Do I need to buffer the outputs of the pushbuttons with an opamp/BJT/MOS? Or do I really need to be looking at Interrupts for this type of process |
---|---|
April 12, 2011 by bretm |
Can you step back a level and give us the bigger picture? Making an LED light up when you push either of two buttons doesn't require any signal conditioning or debouncing, so it seems like we're missing part of the picture.
|
April 12, 2011 by mongo |
If you are having trouble driving an input, there may be the chance that it is still configured as an output... Just a thought, as I don't know what you have at the moment. If it is actually an input, yes, a BJT will do the job. Keep in mind though, that a transistor alone typically inverts the signal when used in the switching configuration. If you want to drive the input with an active high, it would require a PNP BJT like a 2n 2907 or 3906. The transistor would take an active low through a resistor. If you want to drive the input like a TTL signal, an NPN transistor like a 2N2222 or 3904 will do. Same conventions, only the opposite polarities. You might need a 4.7K resistor from v+ to the collector and the junction of the two is the signal out to the MCU input. |
April 12, 2011 by Ever25 |
Here's what I have code wise. I'm sure there are better ways to do this, but I'm still trying to learn. This is the code if I dont use the debounce circuit, since I wasent getting the output voltage that was high enough for the MCU to read a HIGH value.
|
April 13, 2011 by bretm |
This waits until all PINB bits except PB3 go to zero. If you want to wait until PB3 goes to zero, remove the ~ How are you buttons connected? Usually you just connect a switch to ground and to the pin, and voltage levels are not an issue. Or is it not a button? |
April 13, 2011 by Ever25 |
@ Bretm Yes, sorry the way I last was playing with the code I only had the code reacting to a logic LOW from PB3 although I have tried having the code respond to any input on PORTB
Yet in both instances of code, if I have only one push button attached to PORTB (say PB3) then the code runs fine and my LED's react as I expect them to. But if I attach a second button to PORTB (say PB3 & PB4, with either version of the code) then the MCU doesnt recognize a logic LOW to either input pin, even if it is coded to only look for an input from PB3. I hope I'm explaining it clearly, im not always good at that. For the push button connection I have a +5 Vcc source connected to one side of a tact pushbutton switch through a 10k resistor, which is holding it to a static HIGH (+5V) value. The other side of the button is connected to GND with a 0.1uF cap in parallel with the button (http://www.ikalogic.com/debouncing.php look at figure 2A this is how I currently have it on my breadboard) |
April 13, 2011 by bretm |
In your code you're enabling the MCU's pull-up resistor. Since you have your own external pull-up resistor you shouldn't use the MCU's. Leave PORTB at zero. You've said what the output levels of the inverter are, but what are the on and off voltage levels at the button output without any inverter or transistor connected? Are you seeing those same voltage levels when you connect that circuit to the MCU pin? If they're not pretty close then the pin isn't configured for floating input. With the button circuit you pointed to, there should be no problem with intermediate voltages. You should be getting a clean +5V or 0V unless the capacitor is broken or the switch doesn't have a low enough "closed" resistance. Try a different capacitor, and measure the switch's resistance when open (should be megaohms) and closed (should be fractional ohms). |
April 13, 2011 by bretm |
while(PINB == 0) isn't right either. That will wait any input goes high, i.e. until any button is not pressed. If you want to wait until any of PB3, PB4, or PB5 are pressed (go low), you want
where BUTTONS is defined as ((1<<PB3)|(1<<PB4)|(1<<PB5)) |
April 13, 2011 by Ever25 |
@Bretm ok I get what you mean by needing
had to rewrite out the math but I see that PB3 on PORTB is looking for the pin to go to a logic zero no button pressed PINB sees 00001000 (assuming no other connections are HIGH) button pressed PINB sees 00000000
So not using the circuit with the inverter piece just the pushbutton connected as in the previous link I have an output when not pressed of ~4.8V (so effectivly Vcc (+5V)) connected to PB3, and when the button is pressed ~0V connected to PB3 When the button/switch is open (+5V to PB3) measuring in parallel with the button (I think this is what you were asking about) I have ~1.8M-Ohms and with the button/switch closed (0V to PB3) I measure about 0.5 Ohms. So this looks as you were saying it should be. So I added the code for deactivating the pull-up resistors on the inputs of PORTB
and I'm not sure but that may have helped the issue I was having where if you have two buttons connected then the MCU won't recognize a logic LOW from either input. However I ran into a different problem that maybe I'm not understanding the logic on. I added the following in line with your suggestion
Now with this code uploaded I only get the rest of the code to run when both buttons connected to PB3 and PB4 are pressed but not one or the other as I think the code should be running |
April 13, 2011 by bretm |
With
I would it expect it to require both buttons to be pressed, just like you said it's doing. What you want is
which will loop until either button is pressed. |
April 14, 2011 by Ever25 |
Thanks for your help Bretm, your right that works just the way it should now. I guess I'm just not totally getting how the MCU reads inputs. so I understand (at least I think I do) that with the code
the loop reads what is on the inputs connected to PORTB because of the PINB command, compares it with the mask value ( & BUTTON : where BUTTON = ((1<<PB3)|(1<<PB4)) ) then checks to see if it is equivilent to the value stored in the 'BUTTON' variable. I hope i'm getting this right. so for
I am not getting the correct function i'm expecting because it is looking for a boolean value to be compared (maybe made equivilent to is a better description) but doesnt see one. Or is that line of code looking for a different logic pattern that I guess I'm not seeing? |
April 14, 2011 by Ever25 |
@ mongo I'm going to try use an amplifer today and see if I can get it to work (and understand what its doing, and how its doing it) but I have a question. If I'm looking to amplfy a DC voltage signal then would it make a difference which transistor type I use (PNP vs NPN) since a DC signal has zero frequency it shouldn't be inverted anyway. If I use it in a basic switching mode could I not use an NPN Trans with a Vsource of my desired output level (+5V) to be output to the MCU input pin(s)? Obviously I would have to change my code to respond to logic HIGHs and not logic LOWs. I'll work on that today and see what I find. |
April 14, 2011 by Noter |
Here is a good explaination of transistor circuits - |
April 14, 2011 by bretm |
The expression in while(...) is just compared against zero and the loop happens as long as the expression is non-zero. When you use a boolean expression it's equal to 0 for false and 1 for true. When you don't use a boolean expression, such as when you do while(PINB & BUTTON) it's equivalent to while ((PINB & BUTTON) != 0) which means it will loop as long as either of the two input pins are not zero. They are not zero when they are not pressed, so it loops as long as either of them is not pressed, which is the same as saying that both of them must be pressed to exit the loop. |
Please log in to post a reply.
Did you know that you need to think about wires differently when you're transmitting signals more than a few inches? Learn more...
|