importance of Pull-up and Pull-down resistors in AVR/ARM

Under progress

Introduction: Here, i will focus on the basics of pull-up and pull-down resistors, what are these resistors, why do we need them and what should be their values. All these will be discussed in great details in application to the AVR micro-controllers(ATmega328P) and ARM micro-controller(STM32F0).

Let say you want to read the status of a pin using the external interrupt in uC and the uC pin is connected to a switch that can either be at pressed state or at unpressed state. But when it comes to a uC pin, it can either be at high logic, low logic or floating. 

When we are using a switch at the pin of uC as shown in figure-1.A below, then there is a problem when switch is not pressed the uC pin will be floating, and hence can be treated as high/low. Means it is at undefined state that may result in undesired behavior. However, when the switch is pressed, pin is pulled down to the GND, and it will be treated as low by the uC.

Pull-up resistor:

Now, switch is connected with a resistor as shown in figure-1.B. Let see what happens when the switch in not pressed, the logic high will be available at the uC pin because the pin will be pulled to High by the 4.7k resistor, and hence the resistor is called as pull-up resistor. while in the case, when the swtich is pressed, the uC pin goes low and can be treated as low logic. 

Figure-1

When we are using a pull-up resistor, pin state remains high until the switch is unpressed. However, this solves the problem of floating pin.

Pull-down resistor:

For some application you may need this pin to remain at low logic, you can use pull down resistor as shown in figure-2. In pull-down resistor use case, when the switch is pressed the pin goes high(shown in figure-2.A), and in the case when switch is unpressed the uC pin is pulled to GND by the 10k resistor(shown in figure2.B), and hence called as pull down resistor.

Figure-2

you might be thinking, pressing the switch in figure-2.A, doesn't short the pin with 5V directly?
yes, you are right. But the pins configured as input are said to be in Hi-impedance state(order of mega ohms) and a nominal current flow into the uC. so it is not a problem.


Can you use a switch without using any external pull-up/pull-down resistance and make sure that there is no floating pin problem?

Yes, you can, by using the internal pull-up/pull-down resistor present inside the uC chip, these are present in almost every modern day uCs, are controlled by the software.

values of these internal resistor are of the order of kilo-ohms between the 20k to 50k. Exact values for a particular uC can be found in datasheet.

Let say you want to pull-up the digital pin-3 in input mode of arduino uno board, then all you need to write in the sketch is...

PinMode(3,INPUT_PULLUP);
and
pinMode(3,INPUT_PULLDOWN); to configure the digital pin-3 in input pull-down mode.

To acitivate the input pull-up, you could also write the 
pinMode(3,INPUT);
digitalWrite(3,HIGH);
and
pinMode(3,INPUT);
digiralWrite(3,LOW); to configure the digital pin-3 in input pull-down mode.

put an image of GPIO port structure

GPIO structure of STM32F micro-controllers:
let say you have configured a pin in output pushpull configuration. As the output control unit of output buffer receives 0/1-logic then it turns the NMOS/PMOS accordingly to get the 0/1 logic at the output respectively.

As the ARM micro-controller is turned on, the input to the output push-pull is undefined, and the output, right at the output buffer is also undefined.

To avoid this undefined state, you must active the internal pull-up/pull-down resistor to make sure that there is a defined state 0/1 at the I/O-pin.

let say you have activated the internal pull-up resistor(Rpu). Now, the undefined state is also pulled to 1-logic.
One can write the digitalWrite 0/1 to output control unit to acheive logic-0/1 at the I/O pin without using the internal pull-up/pull-down resistor. But, it is not always possible to do so, because there are many function in the ARM development library that leaves the pin in undefined state. for example HAL_TIM_ PWM_STOP() leaves the input pin in undefined state. Hence one has to know about the use of internal resistor to manage these kind of problems.



Application:
Now i will be talking about the application of push-pull configuration together with the use of internal resistance.




Can we drive an LED using the internal Pull-pu resistor?
No,because it will burn the uC.


what will happen if we GND the digital pin configured as output?
Digital Pin: The different Arduinos are actually mostly built from relatively robust microcontrollerss, but: Microcontrollers have datasheets where the maximum current you may source from a pin is specified, and your exceeding that rating, definitely, if you're shorting to ground. Don't do this.

Comments