PDA

View Full Version : PortD on 18f4550 cofig pullup for switches



Bonxy
- 13th April 2009, 18:17
Hi all

I have a 18f4550 and want to have port D as inputs and connect switches to portd.1 - portd.6

I think i need to set portE.7 to enable portD pullups ??? (porte.7 = 1) ???

the switches will be from the portD pin to ground (active low)

I do not want to use external pullup resistors


Any ideas please :-)

mister_e
- 13th April 2009, 20:26
Datasheet have to be your friend.

Step #1: Download the datasheet
http://ww1.microchip.com/downloads/en/DeviceDoc/39632D.pdf

Step #2: Go to table 1-3, and there, you discover that weak pull-ups are only available on PORTB

Step #3: make a decision, use external ones, or move on PORTB.


Case you move on PORTB, you go to section 10.2, then you discover

Each of the PORTB pins has a weak internal pull-up. A
single control bit can turn on all the pull-ups. This is
performed by clearing bit, RBPU (INTCON2<7>). The
weak pull-up is automatically turned off when the port
pin is configured as an output. The pull-ups are
disabled on a Power-on Reset.

You could still decide to don't use any pull-up, or pull-down, it's doable, and if your software is properly done, you can even attach 2 push button per I/O (one to vdd, the other to Vss) ... it will work, but a real waste of time IMHO.

Bonxy
- 14th April 2009, 09:57
Hi Steve

I read the datasheet before i post my message :-/, to me the datasheet says that bit7 on port E set the pull-ups for portD on 18f4550 ?.

Anyway, i could use portB,

I want to have switches that can be active low and active high,

can this be done without resistors ?

thx :-)

Tom@Nottingham
- 14th April 2009, 11:02
I have read the data sheet and have set registers as below for 4550
TRISA = %00111111'An 0-4
TRISB = %00011111'An 8-12
TRISC = %00000000'All output
TRISD = %00000000'All output
TRISE = %00000111'An 5-7
ADCON1 = %00000000'A/D channel All
ADCON2 = %10000011'Right justify for 10 bit
INTCON2 = %10000000'Set to disable pullup on An 8-12?

I cannot disable the weak pullups on portb, can someone please show me how this is done, is pbaden involved?

Thanks

mister_e
- 14th April 2009, 15:55
Ouch,mmm well :o, seems you're totally right, I totally missed that part, my apologies

Each of the PORTD pins has a weak internal pull-up. A
single control bit, RDPU (PORTE<7>), can turn on all
the pull-ups. This is performed by setting RDPU. The
weak pull-up is automatically turned off when the port
pin is configured as a digital output or as one of the
other multiplexed peripherals. The pull-ups are
disabled on a Power-on Reset. The PORTE register is
shown in Section 10.5 “PORTE, TRISE and LATE
Registers”.

PORTE.7=1 ' this will indeed enable pull-up on PORTD

Intcon2.7=1 will disable the pull-ups as per the datasheet. (pdf page 102)

Out of curiosity, why do you say that you're unable to disable the pull-ups? If you read some voltage from them, maybe you read some "parasitic voltage", and If I remember correctly, some of these I/O on PORTB are also set as analog at POR. See ADCON0 (p262)

ADCON0=%00001111 ' turn of all ADCs

You can also trick PORTB adc with the config fuses.

Bonxy
- 14th April 2009, 19:37
Hi Steve,

I always try the datasheets before I post a help request, the only problem with the datasheets is that they are quite technical and confusing to a dabbler like me who only program for fun.

Anyway, I think i got the active low switch working now, the switch is connected to ground and port pin and it works,

BUT, How do I get a switch to work active high now ?,

I connect the switch to +5v and port pin (it trigger the switch once but do not go back low)

how can i get this to work ? any ideas :-)

Tom@Nottingham
- 14th April 2009, 21:46
Thanks for your/and others invaluable help in guiding me along.

The faulty analog inputs an8, an9 and an12 when connected to a pot 0-5v would, when the applied voltage was reduced, indicate the correct voltage until the voltage went down to 1.5v. I then connected a milliamp meter in circuit with the analog input and measured a current of 1.6 ma. After reading the sbc44 manual I now believe these inputs cannot be used as analog inputs but can be used as digital i/o? I do however have 10 analog inputs that work correctly, as I shall be using lm35/ad22100 to measure temperatures, hopefully.

PS I have now succeeded in getting pc vb2005 to usb pic4550 and believe I now understand how it works. Does upgrading to vb2008 express give any problems?

Tom

mister_e
- 14th April 2009, 21:59
Tom , VB2008 work as VB2005, but it has few less bugs and few new improvements.

Assuming you might use EasyHid DLL, I can't tell how good, bad it will be for Vista or VB2008 as I no longer use that DLL.

Check your ADCON0 setting, I already use all Analog channel on that one, and never got issues.

Bonxy

BUT, How do I get a switch to work active high now ?,
Same thing, but you need a pull-down resistor instead of a pull-up.

Bonxy
- 15th April 2009, 11:40
Hi all

Does anyone know how to read a switch connected to a port pin on 18f4550 (active high).

eg: switch is connected between port pin and +5v

without using an external pull-down resistor

Melanie
- 15th April 2009, 13:44
Not recommended. A pin will 'float'... sometimes it might acquire a charge from internal capacitances and over a period of time you will read a High when earlier it was a Low.

Use internal Pull-Up's where available and pull down with a switch externally for minimum component count. Try not to wire +5v to things like Switches and Sensors... especially if that same +5v supplies your PIC or other Logic... all you're doing is asking for noise to be induced into your Power Supply circuits which could then cause you grief elsewhere.

Bonxy
- 15th April 2009, 14:55
pull down with a switch externally for minimum component count.

Try not to wire +5v to things like Switches and Sensors.

Hi Melanie

Thanks for your reply, could you please elaborate on a couple of things ?, I'm not sure what you mean about pulling down externaly with a switch ?,

What im trying to do is have a switch with just 2 wires connected that can work active high or active low. (without resistors)

This project is a kind-of one chip does everything scenario, and so I cant use resistors, will it damage my pic if i put +5 to a pin ?.

Thanks

Melanie
- 15th April 2009, 19:47
Somehow I get the feeling you could do with some basics...

DIGITAL only has two states, On or Off, High or Low, 1 or 0. That's why we call it Binary.

A PIC pin when used for DIGITAL can only have two states... High (or 1) or Low (0). 1 or Zero that's all you got. There's no 'in-between', no half-way or part way. Your choice is 1 or Zero. That's it - no other choices. This is also why everybody does DIGITAL and very few people do ANALOG. Because with DIGITAL life is easy. You learn 1 and you learn Zero and that's it - you're a computer expert because there's nothing else to learn.

This means one of two things...

Scenario A. You preset the PIC's pin with a HIGH (ie set it to a Logic 1) and you do this by pulling it UP to +5v via a Resistor (say 10K for arguments sake). This pin is normally now sitting at +5v (Logic 1 or High). You connect a pushbutton or switch between the PIC's pin and Ground (0v). When you push the button, you short that pin down to 0v, forcing it LOW. You need a Resistor, because otherwise you'll be shorting the +5v Power Supply out! Lots of PICs have pull-up Resistors inside them on many of their pins which can be switched-in to do the job and save you from providing one externally. So here, with the switch being OPEN-circuit, the PIC sees a HIGH (Logic 1) on it's pin, and when you press the Button the PIC sees a LOW (0) on it's pin.

Scenario B. You preset the PIC's pin with a LOW (ie set it to a Logic 0) and you do this by pulling it DOWN to 0v via a Resistor (say 10K for arguments sake). This pin is normally now sitting at 0v (Logic 0 or Low). You connect a pushbutton or switch between the PIC's pin and Supply (+5v). When you push the button, you connect that pin up to +5v, forcing it HIGH. You need a Resistor, because otherwise you'll be shorting the +5v Power Supply out! PICs don't carry internal pull-down Resistors inside, so you need to provide one externally. So here, with the switch being OPEN-circuit, the PIC sees a LOW (Logic 0) on it's pin, and when you press the Button the PIC sees a HIGH (1) on it's pin.

You CANNOT leave a PIC pin 'floating' unconnected. This is because the pin can acquire a charge (or discharge) and set the pin HIGH or LOW or even flicker between the two - which is kinda defeating what you want the pin to do if you can't even predict what state it is going to be in at any point in time. You pull it LOW with a switch and it might stay there when the switch is released, then some time later it might float High. You pull it High with a switch, then it might stay there forever after you release the switch - again not what you want it to do.

And in answer to your question - No, you won't damage a PIC's pin (when it's set for INPUT - TRISx=1) by connecting it directly to +5v or to 0v.

Bonxy
- 16th April 2009, 00:24
Hi Melanie

Its not realy the basics i'm after, Im looking for what seems to be an advanced answer.

I am simply asking if it is possible to get an active high input on a pin ? using any method whatsoever without the need for an external pull-down resistor?.

If the answer is no then thats fine, but all I seem to be getting is ambiguous replies or lectures that dont answer my question.

I had one person that told me to look at the 18f4550 datasheet (which I already had done), he didnt even look himself before making a reply :-(.

I've thought of a simple workaround to the problem myself (although not ideal), have a changeover switch that has the common as the pic pin and the changeover contacts as 0v and +v.

I dunno Melanie I love pic's etc and just do it for fun, but It feels a bit like a bit of a club on this website, and asking for help on hear is hard work, I feel like a noob again. :-(

Melanie
- 16th April 2009, 07:22
I've thought of a simple workaround to the problem myself (although not ideal), have a changeover switch that has the common as the pic pin and the changeover contacts as 0v and +v.


But then that is THREE wires and you specified two a couple of posts ago. But yes, that'll work providing your switch is the break-before-make type otherwise you'll be shorting out your +5v line.



I am simply asking if it is possible to get an active high input on a pin ? using any method whatsoever without the need for an external pull-down resistor?.


Without external components, your simple answer is NO.

Bonxy
- 16th April 2009, 09:51
Thanks Melanie

Like I said the change over switch idea is not ideal, but I cant think of anything else just off hand.
If there is no way to do it by programing the pic then that only leave's phisical methods, hmm, gonna have to give this project some more thought before deciding if it is viable.
Thanks very much for taking the time to reply :-).

Dave
- 16th April 2009, 11:41
Bonxy, The change over switch as you call it is nothing more than a single pole/double throw. As far as shorting out the +5 volts to ground if it is a make before break, just tie the +5 volt side through a 4.7K resistor. The resistor will allow a small current to flow through it but not short the supply.

Dave Purola,
N8NTA

Melanie
- 16th April 2009, 11:50
This is the whole issue here Dave, if only Bonxy would use a Resistor all his problems would go away - but he won't.

Bonxy
- 16th April 2009, 11:50
Hi Dave

thanks for that :-), I have been trying that with a standard 3 pin changeover 'microswitch', BUT, while I have been experimenting with it I have 'somehow' managed to get a switch working either as active low or as active high without any resistors and with only 2 wires, despite what I have been told it seems to be working ?????, I am not holding my breath though because the person that told me this cannot be done is prety expert on this stuff.
Im thinking that there may be something I've overlooked on my dev board (EasyPic3), Ive removed all the pull-up/pull-down jumpers to be sure and it seems to be working ?.
This is strange, lol :-), its doing exactly what i want it to, that worries me.

Dave
- 16th April 2009, 12:00
Bonxy, There may be parasitic resistance from solder flux or something on the board you are using for prototyping the circuit on. I personally would NEVER use a digital input from a processor without some kind of active state. The best you could do is what I suggested in my last email if you dont have any room on the prototype board you are using.. The resistor can be located at the switch or the point you pick up the +5 volts.. The problem with letting the unknown resistance control the state of the input is you cant say for sure the state will be stable when you put the circuit into the REAL WORLD... It is nothing more than an antenna in this state and anything can influence its state... Highly unstable...

Dave Purola,
N8NTA