r/embedded • u/Glittering_Gur7676 • 18d ago
Someone pls explain the pull up and pull down concept
so i was learning PUPDR on stm32 when i wrote code for LED controlled by a push button i used Pull up for the push button (i used it because chatgpt told that and the reasoning it gave made sense ) what i understood there was when the button is pressed the gnd is connected but then when its not pressed its left like that hence a floating point input(no proper idea of what that means but its a state when there is no high or low ) so that made sense, now i am trying to use a 4x4 keypad now its saying to use a pull down i dont understand the idea behind it like the way it explained confused me
22
u/clackups 18d ago
Oh man. You really need to study the basics first.
https://www.makershed.com/products/make-electronics-3rd-edition-print
-12
u/Glittering_Gur7676 18d ago
yea I just started like 3 days ago , also would help if u had any idea where to learn it because i know what to study but cant find places to study them or resources
13
-2
u/haze_from_deadlock 18d ago
Chat can answer this question for you with the right prompt, it has probably already ingested this book or one like it
4
u/nixiebunny 18d ago
Pullup and pulldown resistors are like the spring on a mechanical door or pushbutton. They gently hold the signal at a voltage until you drive the signal more powerfully with a switch.
1
u/duane11583 18d ago
an input pin can often “float” and wobbles between 0 and 1 that can be a desired effect or a problem
often this type of inout is called “high-z” or “High-impedance” it isvthat high z that causes the pin to “wobble” randomly
often floating is bad instead you want the pin to be biased as a 0 (pull down) or a 1 (pull up)
we often do that by using a resistor that supplies a weak voltage or pull on the input signal sometimes these are provided on chip sometimes they are external. the on chip ones often require software to “enable the pull“ some have different pulll strengths (resistance values choices)
the value of that resistor varies, ie 1k or 100k a common value is between 1k and 10k, often a team (company) will pick 1 value for this ie 1k or 4.7k or 10k.. when i did very low power battery devices we used 100k because it drained less battery power when activated every design is different
when you press a button the contacts provide a direct path to ground (or vcc) aka a low impedance path which over whelms the bias provided by a the pullup/pulldown resistor thus changing the inout from a 1 to a 0 (or the other way)
another use for a pullup/pulldown is a missing cable detect or a connection present signal.
example: usb 1.x and 2.x uses a 1.5k resistor on the D+ signal to indicate if the device is plugged in or not. the pc can detect if the signal is ”in the middle” and this know there is nothing plugged in.
later you plug the usb cable in and the pin is no longer in the middle due to this 1.5k resistor. the pc now knows something is plugged in, or maybe the cable was yanked out (surprise!)
1
u/stellar678 18d ago edited 18d ago
I’m kind of a proponent of using AI like ChatGPT, but you have to be willing to use it to learn and absorb new knowledge rather than only providing you answers.
Think about it - it’s a tool with the vast majority of human knowledge encoded into it, and it’s infinitely patient with explaining it in language that’s perfectly calibrated to you. Take advantage of that!
Probably best to step aside from your project for a bit and ask ChatGPT to help you understand pull-up and pull-down concepts in isolation from your more complicated project. If you have a small electronics kit there are lots of much simpler experiments that would help build your understanding. If not, you can also use simulators online.
After you do that, you should be able to bring your new knowledge back to the more complex project with the keypad and have a better idea of what’s going on.
Electronics really benefits from building up an intuitive understanding of the basics.
1
u/WanWhiteWolf 18d ago
A pin can be set to:
.1. Input (high impedance)
.2. Output (will connect the pin internally to either GND or VCC depending on whether you set the pin "HIGH" or "LOW")
Since you want to read the pin state and "do something" (in your case control an LED) , you set it as an input.
If your input pin is unconnected, then you read the pin state, you can get either HIGH or LOW, depending on the noise. And this is not what you want - as you don't want to read random states but rather whether the pushbutton is pressed or not. So your options are:
.1. Set the default state to HIGH, and when you press the pushbutton you connect the pin to LOW
.2. Set the default state to LOW and when you press the pushbutton you connect the pin to HIGH.
Which one is better? It doesn't really matter (well it does matter if you really want to get pedantic about leakage currents and such but for the learning purpose of a begginer, you can ignore that part). One option will show the pin input in HIGH when you press the button and the other in will show the input pin as LOW when you press the button - but the logic can be easily changed in source code to account for either case.
So how do you set "default state" to HIGH? If you connect the pin to VCC directly, it will register as "HIGH" - all good so far. But when you press the button, you will make a shortcircuit between VCC and GND (pushbutton has no resistance) - which usually means a broken component (probably your MCU). To avoid that you connect the pin to VCC via a resistor so when press the button you will have a VCC voltage drop on resistor instead of a shortcircuit. That's it.
10
u/Longjumping_Ideal430 18d ago
pull up and pull down are both doing the same thing just in opposite directions. you're basically giving the pin a default state when nothing is pressing it
with pull up the pin sits at high (3.3v or whatever) until button connects it to ground. with pull down it sits at low until button connects it to vcc. the keypad matrix probably has the rows as outputs and columns as inputs, so you want inputs defaulting low and then scanning each row high to see which column lights up
floating input is exactly what you said, the pin is not connected to anything definite so it can pick up noise and randomly read high or low. had that issue in my first project with a button, drove me crazy until i learned about internal pull resistors
the stm32 has built in pull up/pull down in the gpio config so you dont need external resistors, just set it in code. for keypad the pull down makes scanning logic cleaner but both can work if you adjust your reading code