Download presentation
Presentation is loading. Please wait.
Published byMildred Reeves Modified over 7 years ago
1
Embedded Systems Programming (What they do and when / how to use them)
Pullup resistors (What they do and when / how to use them) 1
2
Resistors – How they work
A resistor is a device which restricts the flow of electrical current. The amount of current flowing through a particular resistor is a liner function of the voltage across the resistor and the actual amount of resistance the resistor has (e.g. a 100 Ohm resistor restricts current more than a 10 Ohm resistor). The relationship between Voltage (V measured in Volts), Current (I measured in Amps) and Resistance (R measured in Ohms) is given by Ohms law: V = I * R This can be re-arranged: I = V / R Example 5V Voltage difference across the resistor is 5V – 0V = 5V Current = 5Volts / 1000 Ohms = 5 milliAmps 1KΩ resistor Current flow 0V 2 Embedded Systems Programming II Richard Anthony, Computer Science, The University of Greenwich
3
Pullup resistors – Why they are needed
An input pin with nothing connected to it could read as either a ‘0’ or a ‘1’. Generally when an input pin is not used in the design, you will not read it in the software, so this is not a problem. However, some types of input device only pull the input pin in one direction; consider a simple switch: Two switches both closed = short ! both open = ? Single throw switch closed = 0, open = ? Double throw switch position1 = 0, position2 = 1 Vcc (5V) Vcc (5V) Vcc (5V) Microcontroller Microcontroller Microcontroller Input pin Input pin Input pin Limited applicability Bad Bad Gnd (0V) Gnd (0V) Gnd (0V) 3 Embedded Systems Programming II Richard Anthony, Computer Science, The University of Greenwich
4
Pullup resistors – The concept
A microcontroller needs only a very small current flow on an input pin to signal a logic level. If a resistor (up to about 10KΩ) is used to connect, the port pin will register the value in the same way as if a direct connection to +Vcc or Gnd was made. The use of a resistor enables a predictable port bit reading even if only a simple switch or input device that only pulls the pin in one direction, is used. Vcc (5V) 1KΩ resistor Single throw switch with pullup resistor closed = 0 (relatively large current flows through switch, overpowers resistor current) open = 1 (small current flows through resistor) Microcontroller Input pin Good Gnd (0V) Embedded Systems Programming II Richard Anthony, Computer Science, The University of Greenwich
5
Pullup resistors – Internal, programmable pullup resistors
Gnd (0V) Vcc (5V) Input pin Microcontroller pullup resistor S/w controlled switch – allows setting the pullup resistors on/off from within a program To minimise the number of external components needed, and to maximise flexibility, the ATMEL microcontrollers have internal pullup resistors which can be connected / disconnected programmatically (i.e. from within a program). Single throw switch with internal pullup resistor selected on closed = 0 (relatively large current flows through switch, overpowers resistor current) open = 1 (small current flows through resistor) This configuration requires less external components (cheaper, smaller system size, quicker to build) Embedded Systems Programming II Richard Anthony, Computer Science, The University of Greenwich
6
Pullup resistors – Programming the internal pullup resistors
Programming the pullups requires an extra step when setting up the ports. A ‘1’ is set in the PORTn register to set the pullup resistor for each bit. This must be done after the port bit has been set for input direction, otherwise you are just setting the output bit value! Example: set the pullup resistors on for port B bit 3 and all bits of port C ldi TEMP, 0b out DDRB, TEMP // set all bits of port B for input ldi TEMP, 0b out PORTB, TEMP // set the pullup resistor for bit 3 of port B out DDRC, TEMP // set all bits of port C for input ldi TEMP, 0b out PORTC, TEMP // set all pullup resistors on for port C Note that using the pullup resistors makes sense only when the port pin is used as a digital input. Do not use when the pin is used as an output, or when analogue inputs are used. Embedded Systems Programming II Richard Anthony, Computer Science, The University of Greenwich
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.