CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

designed pcb assuming pullups on port c... any solutions?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
blak3r



Joined: 11 Jan 2004
Posts: 45

View user's profile Send private message Visit poster's website

designed pcb assuming pullups on port c... any solutions?
PostPosted: Thu Jan 22, 2004 4:32 pm     Reply with quote

I'm using a PIC16F677 which is a 14 pin pic with an ADC. Basically, the lowest end pic available with an ADC.

I've read somewhere about detecting a high impedence state. In other words can i check to see if an input pin is low or high impedence? Because without pullup resistors i'm left with high impedence and gnd states.

I was throwing together a circuit as a delayed shutdown controller for his radio in his car and i was using the extra port c pins connected to dip switches to allow him to change the time on them.

I assumed that portc would have pullups since there is no portb on this pic.
_________________
"Everything should be made as simple as possible, but not one bit simpler" -- Albert Einstein

http://www.blakerobertson.com
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 22, 2004 5:13 pm     Reply with quote

Quote:
I'm using a PIC16F677 which is a 14 pin pic with an ADC. Basically, the lowest end pic available with an ADC.

I could not find this PIC on Microchip's website, so I'll assume
you mean the 16F676.

Quote:
I assumed that portc would have pullups since there is no portb on this pic.

The data sheet shows pullups are available on Port A only.


Quote:
I've read somewhere about detecting a high impedence state. In other words can i check to see if an input pin is low or high impedence? Because without pullup resistors i'm left with high impedence and gnd states.

I was throwing together a circuit as a delayed shutdown controller for his radio in his car and i was using the extra port c pins connected to dip switches to allow him to change the time on them.


I suggest that you add external pull-up resistors on the pins that
are used for the DIP switches. A value of 10K will work fine.
Then when you read the Port C pins, if the switch is open, you
will read a Logic High level and if the switch is closed, you will
read a Logic Low level. (This assumes that you have tied all
the pins on one side of the DIP switch to ground).
blak3r



Joined: 11 Jan 2004
Posts: 45

View user's profile Send private message Visit poster's website

PostPosted: Thu Jan 22, 2004 7:15 pm     Reply with quote

Thanks for your response!

oops sorry yes you are correct it's a 16F676.

What happens when you try to read an input that isn't tied to ground or Vdd?

It's an indeterminate state correct? It wouldn't always think it was high or always low... right?
_________________
"Everything should be made as simple as possible, but not one bit simpler" -- Albert Einstein

http://www.blakerobertson.com
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 22, 2004 11:28 pm     Reply with quote

A high-impedance input pin which is not connected to any other
circuit has a few pico-farads of input capacitance ( < 8 pf).
So it will hold, temporarily, the last state that it was driven to,
before the connection to the external circuit was removed.
But you can't depend upon it to hold that state forever.
So you shouldn't regard a floating input pin as something
that you can read, reliably.

It's standard practice to use pull-up resistors on PIC input pins
which are connected to switches. If the switch is closed, the PIC
will read a low level, since the other side of the switch is connected
to ground. If the switch is open, the pull-up resistor will cause
the PIC to read a high level.

Quite often, in order to save adding resistors, Port B is used
for switches or jumpers in PIC designs. That's because
Port B has programmable pull-up resistors on it.
(Also, the upper 4 bits of Port B have an "interrupt on change"
feature which can be useful with switches).
In the case of the PIC you're using, these pull-ups are on
Port A. So, to be economical, you could put the DIP switches
on that port and enable the pull-ups.
blak3r



Joined: 11 Jan 2004
Posts: 45

View user's profile Send private message Visit poster's website

PostPosted: Fri Jan 23, 2004 1:38 am     Reply with quote

Thanks for your detailed response.

I was aware of the practice of using pullup resistors. I was just desperately hoping that there would of been some solution which wouldn't have required me to make a new board.

Luckily, i made the board using a CNC milling machine so it wasn't a big investment. I was helping out a friend so i wasn't trying to spend too much time on the project but my haste got me in the end as it usually does.

Thanks again
_________________
"Everything should be made as simple as possible, but not one bit simpler" -- Albert Einstein

http://www.blakerobertson.com
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 23, 2004 1:04 pm     Reply with quote

If you just need a way to temporarily fix the problem, here is a way:

It's assumed that the DIP switch is grounded on one side,
and the other side goes to the PIC pin. (This example is
just for one pin).

If the DIP switch is closed, the PIC will read a logic 0, with
no problem, because the pin is connected to ground.
The question is, how to read a high level, when you have no pull-up ?

The solution is to take advantage of the small amount of capacitance
on the PIC pin. In the example below, a high level pulse is put out
on pin C0 for 10 us. (You could probably pulse it for less than that).
This high level pulse charges up the small capacitance on the PIC pin.
Then we read the pin. Because pin C0 has a high input impedance,
the pin's capacitance will hold the charge for a while, allowing us
enough time to read a high level.

Of course, if the DIP switch is closed, the PIC pin will be connected to
ground. When we pulse the pin for 10 us, we'll be driving a dead short
to ground. We don't normally want to design a circuit that does this,
because it could damage the output driver, but it should be OK for a
short period of time.

I wouldn't put this circuit into production if I could help it, but it is a way
to give your friend a working board, while you're making the real one.


The following circuit was tested with a C&K push-button switch on
pin C0. Normally, it displays "1 1 1 1", etc., on the terminal window.
When you push the button, it will display "0 0 0", for as long as the
switch is held down.

Note that this program uses Standard i/o. The compiler automatically
takes care of setting the TRIS registers to the proper value when the
output_high() and input() functions are used. The TRIS for pin C0
stays in the last state that it was set in by those functions.
If you're using fast i/o, you must explicitly set the TRIS to output
before setting the pin to a high level, and then you must set it back
to an input before you read it.

The enabling and disabling of interrupts is not needed in this demo
program, but it would be needed if you use interrupts in your program.
I put it in there just as an example, for that reason.

This code also doesn't do any debouncing. If you're using DIP switches,
you could use this method to read the switch, and if it reads the same
for two successive calls, with say, a 10 ms interval between them, then
consider it to be debounced.


Code:
#include "16F877.h"
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud = 9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)   

char read_switch_with_no_pullup(void);

//==========================================
main()
{
char switch_value;

while(1)
  {
   switch_value = read_switch_with_no_pullup();
   
   printf("%d ", switch_value);
   delay_ms(500);
  }

}
//=========================================
// This function reads a switch which is connected
// to Pin C0.   The PIC pin does not have a pull-up
// on it.  (Due to an oversight in making the PCB board).

char read_switch_with_no_pullup(void)
{
char retval;

disable_interrupts(GLOBAL);

// Put out a high level pulse for a short time.
// This will charge up the small inherent capacitance
// (less than 8 pf) on the PIC pin.
output_high(PIN_C0);
delay_us(10);

// Now read the pin.   Since we are using Standard i/o
// with the CCS compiler, the input() function will
// also set the TRIS for pin C0 so it becomes an input pin.
// It will remain in that state after we leave this function.
retval = input(PIN_C0);
   
enable_interrupts(GLOBAL);

return(retval);
blak3r



Joined: 11 Jan 2004
Posts: 45

View user's profile Send private message Visit poster's website

perfect!
PostPosted: Fri Jan 23, 2004 7:10 pm     Reply with quote

I'm making a delayed shutdown controller for my friend.

The dip switches just set the delay time.

So, this will work perfectly! I only read the input pins once at the very beginning of the program. Which would only happen the first time the circuit is even connected to his car. Or if he changed the input pins he will just press the reset button. (They don't change once the pic has been powered up)

Thanks a million! You saved me a bunch of time. Good thinking!
_________________
"Everything should be made as simple as possible, but not one bit simpler" -- Albert Einstein

http://www.blakerobertson.com
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group