Interfacing a PNP sensor's output to an 8051 MCU

Thread Starter

cmartinez

Joined Jan 17, 2007
8,220
The AT89S8052's pins are configured as bi-directional input-outputs. The way I understand that they work is by weakly pulling up an internal drain terminal. They're capable of delivering very little current, they were designed to drain current instead. The datasheet does not say what resistor value is internally being used to pull the pin up.

Anyway, I need to detect a signal level change on those bi-directional pins arriving from a sensor that has a PNP output (its high output level is 5V, so we're safe as far as voltage is concerned). My plan is to pull the MCU's pins down with a resistor, so that when the sensor is activated it will bring the voltage back up.

I've tried to represent what I think is happening inside the MCU, and what I plan to do to interface it to the PNP sensor. I hope my depiction is more or less accurate.

Capture.JPG


My question is, what's the maximum value allowed for those pull down resistors so that the MCU will detect a low signal at its pin? I'm under the impression that the higher, the better, so as to draw as little current as possible from the PNP sensor when it goes high.

@Papabravo I have a hunch that you might be able to help me out with this one.
 

Papabravo

Joined Feb 24, 2006
21,159
The weak pullup is on the order of 40K Ohms, but this parameter is not specified. As I understand a PNP sensor it wants to have an active pullup to VCC and a passive pull down to ground. If we start with a nominal weak pullup of 40 KOhms and a desire to have the passive level at less than 0.1Vcc something like 2.2K might do the trick.

2.2K / (40K + 2.2K) ≈ 0.052

With a Vcc of 5V that will put the input low level at about 0.26V.

Check the datasheet to see if this is still a guaranteed low. At 5V the 2.2K resistor will sink abut 2 mA which is not an excessive amount.

Since the 40K value is not speced and is more likely to be higher than lower (from my experience) you should be good to go.

To quote my favorite Republican, Ronald Reagan "Trust, but verify".
Words to live and engineer by.
 

Thread Starter

cmartinez

Joined Jan 17, 2007
8,220
Thanks GopherT for taking the time to respond. I think Papabravo might be right on target. Although the Atmel's MCU datasheet does not specify the internal resistor value, the 8051 architecture is quite old and is supposed to be more or less standardized between brands.
I'm so glad you answered my post stating a recommended 2.2k value. I'll be installing those resistors and testing the circuit tomorrow, and they're SMT. I was planning on using 10K resistors, and being forced to dismount them after going through a headache trying to figure things out would've been a pain in the backside.

You've saved the day (again). Thank you very much.
 

Papabravo

Joined Feb 24, 2006
21,159
You realize that I'm going to feel really really bad if you have to swap them for a different value. I guess I wish you hadn't told me that, but I'll cross everything that can be crossed and hope for a positive outcome. CVS (Chuckling Very Softly).
 

GopherT

Joined Nov 23, 2012
8,009
Thanks GopherT for taking the time to respond. I think Papabravo might be right on target. Although the Atmel's MCU datasheet does not specify the internal resistor value, the 8051 architecture is quite old and is supposed to be more or less standardized between brands.
I'm so glad you answered my post stating a recommended 2.2k value. I'll be installing those resistors and testing the circuit tomorrow, and they're SMT. I was planning on using 10K resistors, and being forced to dismount them after going through a headache trying to figure things out would've been a pain in the backside.

You've saved the day (again). Thank you very much.
Just clip/crush the smd resistors in half and remove half at a time. Then put the new one in place.
 

Thread Starter

cmartinez

Joined Jan 17, 2007
8,220
You realize that I'm going to feel really really bad if you have to swap them for a different value. I guess I wish you hadn't told me that, but I'll cross everything that can be crossed and hope for a positive outcome. CVS (Chuckling Very Softly).
Boy, am I glad this is not a parachuting forum... :eek::)
 

Thread Starter

cmartinez

Joined Jan 17, 2007
8,220
What if you put a DMM in series to measure the current while pulling the node down?
Yeah, I can do that. But better yet, tomorrow I'll connect a 50k pot configured as a rheostat to one of the mcu's pins and make a tiny program instructing another pin to go low (monitoring it with a dmm, of course) when a low signal is detected in the first pin.

That way I'll know exactly what resistance is needed to pull the pin down. And then I'll use half that value as a safety measure.
 

Picbuster

Joined Dec 2, 2013
1,047
The question is simple: max output sensor =5V as stated.
forget about the week pull-up to high to disturb the lot.
from mpu data sheet you know when a signal is declared high. assume 1Volt
voltage dividers @ 5V 4:1 40K/10K if however the input should not go above the 3v3 then use a clamp diode to the 3v3 from mpu vdd.
if the output of pnp sensor is current then follow procedure below to find value(s).
Take a 27K in serie with this pnp sensor connect the lot to 5V activate sensor and read voltage over resistor.
this will give you an indication for the divider.
assume < threshold calculate the wanted value
Assume 2.5V ready
But try to use always a clamp to protect input when a mishap with sensor or wire happens.
 

Thread Starter

cmartinez

Joined Jan 17, 2007
8,220
You realize that I'm going to feel really really bad if you have to swap them for a different value. I guess I wish you hadn't told me that, but I'll cross everything that can be crossed and hope for a positive outcome. CVS (Chuckling Very Softly).
Just thought I'd drop by and let you know that I finally built the thing and tested it.... and it worked perfectly!

You can stop chuckling now, and start smiling :)

Thanks again!
 
Top