Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Comments on Sensing 3 states in a single mcu pin using firmware

Parent

Sensing 3 states in a single mcu pin using firmware

+1
−0

I want to sense 3 different states in the same mcu pin (GND, Hi-Z and PWR).

PWR is typical +24V but I would like to have a wide margin from +17V to +40V just to be safe. The values can change but the typical will still be +24V

I need 32 different (physical) inputs.

I designed the following circuit after some brainstorming from my previous post and I'd like some review on it.

schematic

The input (IN) at the left is where the wire is connected.
The out (OUT) at the right goes to an MCU pin with enabled pull-up resistor.
D1 and D3 are zener diodes.
D2 and D4 are schottky diodes.
Zener diodes value can be as lower as 4.7V

PULLUP is a firmware controlled output. It can be the output of a power switch that gives 3.3V or a P-Channel mosfet working as a simple switch. It's not showing on the scematic because it will be common for all inputs. The circuit I represent will be multiplied 32 times. One for each input. 32 inputs total. All anodes of D4 will be connected together to the output of a power switch. That output will be firmware controlled using an mcu pin.

How it works.
When a voltage is applied (+24V typ) D1 conducts and Q1 starts conducting.
D3 is used to protect gate-source maximum voltage. R3 is a pulldown.
R1 limits the current through D1 and D3.

When the IN is grounded D2 connects the gate to ground. It also cancels out R1 and D1 and the voltage divider that would be formed (R2 - R1). And brings gate source to ground.

Firmware checks for Hi-Z.
If we enable PULLUP, and the wire is floating. The state will change from Q1 not conducting to Q1 starts conducting. If the wire is connected to any other rails there will be no change. So, if a change occurs during the time the PULLUP is enabled the mcu translates that as "cable is floating".
One mcu pin enables all PULLUP pins at the same time.
This must be done multiple times per second but for my application that the frequency response is barely a 100Hz will do the job.

The question:
I don't like the D1 and D2 diodes. The reason I placed D1 is to avoid triggering the mosfet with very low voltage like 2V to 4V.
Is D2 really necessary?

What can I improve?

EDIT:
I drew an alternative circuit using BJT.
bjt_circuit

In the second circuit. PULLUP pin must be +24V

In the second circuit, can the zener diode (D2) pull down the base of the transistor and turn it off?

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

Post
+3
−0

Starting with your first circuit:

It seems a little klunky, but should work.

I don't like the D1 and D2 diodes. The reason I placed D1 is to avoid triggering the mosfet with very low voltage like 2V to 4V. Is D2 really necessary?

The input voltage threshold for sensing high is the 8.2 V drop across D1, times 1.1 (the reciprocal of the R1-R3 divider ratio), plus whatever gate voltage is required to turn on Q1 sufficiently to pull OUT low. If the gate threshold is 2 V for example (you didn't link to a datasheet so I didn't look it up), then that comes out to 11 V. That's a reasonable threshold when the nominal input values are 0 V and 24 V.

One problem with this is that the gate voltage to pull OUT low is usually poorly specified. Using D1 instead of having the R1-R3 voltage divider attenuate more is one way to get more consistency. Only you can say whether that's needed in your case.

D2 should not be necessary as long as the minimum gate voltage to turn on Q1 is well above one silicon junction drop. It probably is. Check the datasheet. Note that D1 performs the same function by acting as an ordinary diode when the input is low. You could lose D2, but inject the pullup current immediately after D1.

As for your second circuit:

I would move R2 to the other side of R3. That way, R3-R2 form a voltage divider. With the input grounded, the forward drop on D2 will be about the same as what it takes to turn on the transistor. The voltage to the right of D2 needs to be attenuated to guarantee the transistor is off when IN is at ground.

You could remove D2 completely, move R2 to the right side of R3, and adjust the input voltage with the R3-R2 divider:

There will be some slop in the input threshold voltage due to the uncertainty of the exact base voltage that Q1 will turn on at. There will also be some temperature dependence. However, if you are trying to sense "near 0 V" versus "near 24 V", this should do well enough.

If this were an industrial situation, I would put a reverse diode across R2. That would protect Q1 from large negative input voltages.

If you really want to make this robust, make sure it can tolerate 250 VAC at IN. That means R1 needs to be ½ W at least. 1 W would give good margin. I would also put a 400 V diode in series with R3. That prevents a large positive input from back-driving the 24 V supply, and reduces the power requirement to withstand 250 VAC. With the diode, I'd also make R3 a 1 W resistor.

Here is the final industrial-strength version:

This will detect 0 V versus 24 V in, but can withstand 250 VAC accidentally connected to IN.

One issue with this circuit is that it has no hysteresis. Perhaps that's not important in your application.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

2 comment threads

Zener vs voltage divider? (1 comment)
Thanks, Olin. I concluded you like more the NPN version versus the MOSFET version. Regarding ... (1 comment)
Zener vs voltage divider?
DeadMouse‭ wrote over 1 year ago

Why do you prefer a voltage divider over a zener diode?