Shorting GPIO internally = reset and no problem?

Started by mik3ca 5 years ago9 replieslatest reply 5 years ago285 views

I remembered making a post here and on another forum about connecting outputs of sensors to the 8051 RXD pin via schmitt triggers and combined through a multiplexer.

Here's an update to my circuit here.


After asking the other community why the micro was able to collect data better and faster with the LED and resistor in series (see thick green wires), Many people indicated that I should lower the 1K resistor.  I tried 220 ohm and eliminating the LED and the 100 ohm resistor, and got no luck.

Now someone suggested I should just short out the 1K resistor (and just make a direct path from IC2 output to the GPIO). this micro (AT89C4051) has open collector outputs in which the output can be high-impedance or logic low.  If I go with this idea and by fat chance lower the RXD pin in software, then I have a short circuit if IC2 output goes high (which it will be 99% of the time).

What would happen to the micro in this case if my code the RXD pin is set low by software n seconds later from when the code begins executing? Would it automatically reset every n seconds? or would the micro overheat and malfunction? According to the datasheet, it features "power on reset" and "brown out detection" in which the latter means it resets itself if too little voltage is applied to it.

[ - ]
Reply by matthewbarrJanuary 28, 2019

If you have a GPIO that you are using as a digital input, you would set the the data output register to a 1 and configure the output control as open drain. Don't ever write a 0 to the related data output register when you're using the port as an input, that would be a bug.

The 8051 devices I've used come out of reset in that state, data registers set to 1 and output control configured as open drain. As long as your software leaves the data and output control in this state you can use the port as an input and there should be no problem driving the port directly from a push/pull output, no series resistor required.

With the series resistor removed, you might want to take a look at output sink current from your multiplexer wrt. current through your LED based on your supply voltage and 100 ohm resistor, make sure you're comfortably within the sink capability of the multiplexer output. You may need to increase the value of the 100 ohm resistor.

[ - ]
Reply by mik3caJanuary 28, 2019

the LED and 100 ohm were there just for testing purposes only. Since the multiplexer is 74HC based IC, if I'm not mistaken the output current maximum it can provide is 25mA?

[ - ]
Reply by matthewbarrJanuary 28, 2019

That 25 mA number is probably an absolute maximum rating, you don't want to operate there. Look at the Voh and Vol specs, they'll give you a min high and max low output voltage respectively at some test condition that will probably be in the 4 or 5 mA ballpark.

For example, you may see that your max Vol (output low voltage) is maybe 0.3V for a particular Vcc and temperature range, and the test condition might say Iol = 4ma. That means for these operating conditions (Vcc, temp) your output low voltage can be higher than 0.3V if you sink more current than the 4mA defined in the test conditions.

The test condition current values associated with the Voh/Vol specs are the numbers you need to stay within to guarantee that you get good output voltage levels. Those output levels are not guaranteed up to absolute max ratings.

[ - ]
Reply by mik3caJanuary 28, 2019

OK,I got the datasheet here and specs on page 5...


But for Voh condition, the test currents are negative values.

Based on all tests for low voltage, its telling me the max voltage output for logic low is 0.33V and high output is between 5.2 and 5.9V.

But wait, are you saying I should read the datasheet from right to left? 

And am I guessing right based on the datasheet that somewhat less than 7.8mA is the maximum current that should be fed into the logic IC output without damaging it?

Because if that's the case, then what about a simple LED and resistor circuit connected to the output of an 74HC series IC?  do those resistors have to be high?

But all in all, I want to know the lowest resistor possible to use for series resistor without damaging anything, but then again if I could get away with a short then I'm probably best doing that.

[ - ]
Reply by matthewbarrJanuary 28, 2019

They're using the sign to indicate the direction of current flow, negative when sourcing (Voh) and positive when sinking (Vol).

For a digital push/pull output, data sheets generally won't specify a number for "max sustained current for safe operation." They give you an absolute maximum rating for the output (+/- 35 mA in this case) and indicate that you shouldn't operate there.

The electrical characteristics at 4.5V VCC and worst case temperature for SN74HC151 tell you that at 6 mA sink current your Vol (output low voltage) will rise to 0.33V. If you sink more current than that, it will come up even more. You could probably safely operate at 10 mA sink, but your low level output voltage may rise to a point where, depending on the characteristics of your input device, you have no noise margin and may even be in the input threshold region where you can't operate reliably.

You should be able to eliminate the resistor between mux output and micro input. For this TI device, you might choose the LED current limiting resistor to Vcc such that you have 5 mA through the LED. The input current sunk from the micro input should be very small, much less than 1 mA, so you'll be within 6 mA total sink current.

If you do insist on using a series resistor between mux and micro, you should connect the LED to mux side of the resistor, not the micro side! This way there will be very little current flow through the series resistor and therefore very little IR drop, so you'll get very little difference in the logic low level at mux output vs. micro input. As you've drawn the schematic, all the LED current also goes through the 1k series resistor. This means 1.5 mA sink current gives you a 1.5 V IR drop through the resistor, so if you have 0.1V at the mux output you have 1.6V at the micro input. Yikes! You're at least giving up noise margin, and depending on the micro input characteristics you may well be above the voltage required for a guaranteed low level. With the LED instead connected to the mux side you could probably get away with 100 or 220 ohms between mux and micro with negligible IR drop, because only current from the micro input flows through the series resistor.

Again, I don't believe you need a series resistor between mux and micro. Just leave the micro port configured as an input and leave it alone, and use a simple wired connection.

[ - ]
Reply by matthewbarrJanuary 28, 2019

Here's a thought. Connect mux W out directly to micro RXD in. Connect the LED to mux Y out. Now the LED is on when T1 is on. (I assume that is the "detecting" state.)

[ - ]
Reply by mik3caJanuary 28, 2019

Ok, it turned out that what made things work at a good speed (after making the series resistor to 100 ohms) is to change the resistor feeding the phototransistor from 560K to 10K.

Question now is, is 10K way too low...

I want to be able to achieve decent sensitivity. (not where I have to have the IR emitter within 1 meter of the phototransistor). That's why I picked 560K in the first place but now I learn 560K is incorrect.

Is there some math I can use to calculate the proper value? My phototransistor is actually model PT334-6C

[ - ]
Reply by MichaelKellettJanuary 28, 2019

Your problem is that the photo transistor will be able to achieve a collector current proportional to the amount of light falling on it. If you need 560k to get the right sensitivity that suggests that you are getting about 4.5uA collector current. The capacitance in the collector circuit (which will come from the photo transistor and the other devices connected) and this current set the response speed of the detector. If it is too slow you will need an amplifier. You could swap the positions of the resistor and photo transistor, reduce the resistor to 10k and expect to see about 45mV across it, use a suitable single rail type comparator with 40mV bias on one input and the resistor/photo transistor junction on the other.


[ - ]
Reply by mik3caJanuary 28, 2019

This is what I notice..

I pit 560K and 10K in parallel (because 560K was already mounted on board to the connector) but I didn't swap the photodiode and resistor. After various tests, it was able to successfully detect the signal if a bright LED was used up to about 3 feet away. I tested with a cheap red lazer beam from ebay and so far, I get 5 feet so far, but I don't have long enough cable to test farther.

Could it be that the schmitt trigger that the phototransistor is feeding into expects a certain amount of current/voltage before it senses anything and that my setup with only 560K isn't sufficient?