Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using a PIC18F2550 to control a H Bridge, and I am using several input signals, such as RS-232, I2C and Analog 0-5V to make the final PWM output for the H bridge. I have a problem with PCB space, so I am joining all the input signals in 4 pins, since they will never be used together: Vcc, GND, S1 and S2. S1 will be RS-232 Tx connected to the I2C SDA, and S2 will be RS-232 Rx connected to the I2C SCL and the Analog input. This way, since the user will select which kind of control he wants before using the system, I can save some space. Just to make it clear: The user will select one kind of input (RS-232 for example), and all the other inputs connected to this PIC pin will become a disabled input pin so to not interfere with the communication.

Since I have an analog input (were if the user send 0V the PWM will be 0% and 5V it will be 100%), I wanted to add a pulldown 100K resistor to make it safer in case there is nothing connected, because this is an analog control, so in case the connection is lost, the analog pin could read some voltage and the motor could go nuts. But since I have a I2C connection in the same pin, is this possible? I think it isnt because the I2C needs a pullup, and this will make a voltage divider, right?

Does anyone have a better idea, about a way to make it read 0V in case there is nothing connected in the analog mode, and still have the option to use the pins for I2C or maybe SPI in the future too? Thanks!

share|improve this question
A diagram of your proposed circuit would help. What resistor values do you have in mind for pull-up and pull-down? – Nick Alexeev Nov 15 '12 at 3:09

You're right that a pull-up and a pull-down connected to the same line would create a voltage divider.

You could connect the pull- resistors to a digital I/O pin. If you drive this auxiliary pin high, it will be a pull-up. If you drive it low, if will be a pull-down. If you let it float, you can make an undisturbed analog measurement.

You could also use a larger PIC with more I/O, such as PIC18F4550. Then you wouldn't have to multi-purpose the pins as much.

share|improve this answer
Its a very clever answer but I dont think it will work in my case, I will let those pins available to the user "as is", so I wont be putting any pull-ups myself, I will let the user choose the pull-ups that suits them better. – mFeinstein Nov 15 '12 at 3:56
@mFeinstein Are you designing a sort of a general purpose PIC board for prototyping? – Nick Alexeev Nov 15 '12 at 4:19
No, I am designing a general purpose H Bridge controller...the user can send to the MCU a lot of different signals (RS-232, R/C, Analog in, I2C, USB) and at the end it will control the motor based on the information it received. – mFeinstein Nov 15 '12 at 4:37
@mFeinstein PWM pins aren't multiplexed with I2C on PIC18F2550, and there are other pins with analog inputs. I don't yet understand why you are so hard pressed to multi-purpose the I2C pins with H-bridge. If you want to provide much communication and much I/O, would you consider using a larger PIC, such as PIC18F4550? – Nick Alexeev Nov 15 '12 at 5:30
I am not multiplexing the PWM pins with the I2C pins. I am reading an I2C value and converting it to a PWM value...for example, if I recive 0xFF as value I will output a 100% PWM. – mFeinstein Nov 15 '12 at 5:37

You could invert the "sense" of the analog input: make 5V -> 0% and 0V -> 100%. That gives you the right behaviour while still being useful with input from a potentiometer.

share|improve this answer
The problem is that I wont have always a pull-up...I will leave the pins to the user to decide if he will be using it as an analog input or I2C...so if the user is using I2C, it's better if I dont put any pullup, since I dont know if he will be using it in 5V – mFeinstein Nov 16 '12 at 18:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.