View previous topic :: View next topic |
Author |
Message |
srikrishna
Joined: 06 Sep 2017 Posts: 82
|
What is the use of port_x_pullups ( ) |
Posted: Fri Nov 10, 2017 12:19 am |
|
|
I know external pull up (like pull up and pull down resistor). But can not understand what is internal pull up and its function.
The ccs c manual says
port_a_pullups (value)
It sets the input pullups. TRUE will activate, and a FALSE will
deactivate.
I can not understand the function of pull up. Anyone describe me briefly? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19529
|
|
Posted: Fri Nov 10, 2017 1:29 am |
|
|
This depends on your PIC.
Down to reading it's data sheet.
Now a lot of PIC's have a tiny 'programmable current source' on some pins. It's a MOSFET, and a couple of resistors, able to deliver a small current into the pin when turned on. The current is small. Typically equivalent to perhaps a 50KR resistor. On some PIC's this is just enabled/disabled for the whole port. On others there are individual enables for each bit. For chips that have it on the whole port, the syntax is simply:
port_a_pullups(TRUE);
to enable the whole port. On chips that have individual enables, the syntax is:
port_a_pullups(0b00001111);
or a similar pattern to enable it on individual bits (A0..A3 as shown).
Relatively few PIC's have the pullup on port A. The data sheet will tell you if yours does. Most do have some form on port B. Some have it on other pins as well.
A few of the higher PIC's (PIC24's etc.). have programmable pull-downs as well.
So the first thing to do is read the data sheet for the chip you are using.
It's under the section 'I/O Ports'.
For example, for a PIC16F1826:
Quote: |
12.3.1 WEAK PULL-UPS
Each of the PORTB pins has an individually configurable
internal weak pull-up. Control bits WPUB<7:0> enable or
disable each pull-up (see Register 12-11). Each weak
pull-up is automatically turned off when the port pin is
configured as an output. All pull-ups are disabled on a
Power-on Reset by the WPUEN bit of the OPTION
register.
|
So this one has individual pullups on portB. It actually also has one on A5 only.
There are literally thousands of instructions that may or may not apply to your chip. This is why you need to be reading the data sheet for the chip as one of the first documents. |
|
|
srikrishna
Joined: 06 Sep 2017 Posts: 82
|
|
Posted: Fri Nov 10, 2017 1:47 am |
|
|
And what its utilities? |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Fri Nov 10, 2017 4:14 am |
|
|
srikrishna wrote: | And what its utilities? |
They are pull-ups, they do the same job as external pull-ups. They can save on external components. However they do not work until the code switches them on, so do not pull-up the IO lines while the PIC is in reset/initialising. This can be a problem for some hardware, e.g. they can't prevent rubbish being sent out on an RS232 serial line at start-up, whereas an external pull-up would. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9232 Location: Greensville,Ontario
|
|
Posted: Fri Nov 10, 2017 6:20 am |
|
|
AS RF D says they can be used instead of real external resistors saving space and cost. However I've never used them in over 2 decades of 'playing with PICs'.
The cost 'savings' isn't really great. Maybe 1 cent per pin at most. So yes, IF you make 1,000s of boards it might add up to a dollar or two BUT forget to enable the internal pullups and it'll cost you big $$$ in R&D time to recode/recompile/reinstall...
The space 'savings' isn't much either and frankly I don't do itty, bitty, sub micro sized PCBs. I prefer my 4by6 inch PCB with lots of layout room where I can SEE PIC and pieces.
The HUGE reason I don't do it is some PICs have them, some have whole port pullups, some are individually enabled. Now IF you ONLY use ONE PIC for all projects and products (I only use 3), then you'll always (well hopefully) remember to enable the pullups. If you forget to do that even ONCE, then the cost to redo the software is HUGE compared to the small cost of installing 8 resistors that visually show you there are pullups. Also YOU get to choose the value of pullup. 'Soft' like 50K for power savings, 'hard' like 10K for consistent switch response.
The feature of internal PIC pin pullups is a nice idea but for me it's not one that I have used or care to. It'd be interesting to here from those that do use it and what what level of products it's in.
Jay |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1908
|
|
Posted: Fri Nov 10, 2017 7:01 am |
|
|
If management is counting pennies on every board produced, the internal pullups are attractive. If you are space constrained on your PCB, the internal pullups are attractive. If you are layer constrained on your PCB (which has implications regarding layout size/sprawl), again due to counting pennies, then internal pullups are attractive. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Nov 10, 2017 9:00 am |
|
|
You use the 18F2550.
Look in this section on page 379 of the 18F2550 data sheet:
Quote: | 28.3 DC Characteristics: PIC18F2455/2550/4455/4550 (Industrial)
PIC18LF2455/2550/4455/4550 (Industrial) |
http://ww1.microchip.com/downloads/en/DeviceDoc/39632e.pdf
It lists the manufacturing range of the pull-up current. This means
some chips from the silicon die could have 50ua pullup current,
or some could have 400ua, or anything in-between.
Code: |
IPU Weak Pull-up Current
Param
No. Description Min Max Conditions
D070 PortB weak pull-up current 50 µA 400 µA VDD = 5V, VPIN = VSS
D071 PortD weak pull-up current 50 µA 400 µA VDD = 5V, VPIN = VSS |
Let's convert the range of 50-400ua to resistance.
R = 5v / 50ua = 100K
R = 5v / 400ua = 12.5K
Let's say that you have 10pf of total capacitance on your pins.
This comes from the PIC and whatever chip you have connected to the
PIC pin, and from the traces on the circuit board and other sources.
What's the worst case time constant ? Use the largest resistance:
RC = 100K x 10 pf = 1 usec
It would take 2 time constants for the voltage to be pulled up from 0v
to 86.5% of the final value. If the Vdd is 5v, the voltage after 2 time
constants would be 4.325v. This is important because on many
peripheral devices (such as i2c) on the PIC, the data sheet says the Vih
voltage must be 0.8 x Vdd, or 4.0v.
So what's the purpose of all this discussion ?
It takes time for the weak internal pull-ups to pull up. In the case shown
above, it would take 2 usec minimum. In experiments, it appears to take
longer than that. There may be something else going on inside the PIC.
Perhaps there is an unspecified turn-on delay for the weak pullups.
So anyway, I will do this:
Code: |
port_b_pullups(0xFF); // Turn on all weak pull-ups on PortB
delay_us(10); // Allow time for them to pull up
|
In other words, do a delay before you start using the pins. That will allow
the pull-up voltage to be at the proper level of 5v. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19529
|
|
Posted: Fri Nov 10, 2017 1:32 pm |
|
|
A typical example of their use is one I did recently.
Had an SPI interfaced chip, that the customer after initial design, decided might not be present on some boards. The chip is guaranteed to return all 0's in the top byte after a data read. Simply programmed the pull-up 'on' for the data line, and then at the initial read, check the byte. If it is all zeros the chip is present, if not I just set a flag to stop talking to the chip.
Without the pull-ups there would have had to be a redesign to add a resistor, or the data on this line might be unreliable. With it, problem solved.... |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
Also for extreme power saving |
Posted: Mon Nov 13, 2017 10:16 am |
|
|
The software controlled pull-ups can also be useful when power savings is extremely important. You can have a pull-up when you need it but shut it off when you don't. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
|