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

Post History

60%
+1 −0
Q&A How to change the polarity of an input using a single switch?

The difference between your two options is which polarity the input floats to when left open, and whether there is an overall inversion. Adding the inversion in the firmware would require one more...

posted 11mo ago by Olin Lathrop‭

Answer
#1: Initial revision by user avatar Olin Lathrop‭ · 2023-06-16T18:01:19Z (11 months ago)
The difference between your two options is which polarity the input floats to when left open, and whether there is an overall inversion.

<blockquote>Adding the inversion in the firmware would require one more pin from the chip.</blockquote>

Not necessarily.  I was envisioning inversion or not would be specified by configuration data stored in non-volatile memory.  This is how PLCs do it.  Physical switches are rather klunky.

Assuming you really want to do it the klunky way, I'd separate how the line floats from adding the inversion.

The inversion part is simple.  You already have a digital signal at the collector of the transistor.  Running that thru a XOR gate before presenting it to the micro allows for optional inversion.

Adding an optional pullup to the input changes the voltage at which the line floats.  100 k&Omega; to 24 V at IN is enough to easily turn on the transistor.

Now the question is how to add the pullup and change the level of the second XOR gate input with a single jumper or switch.  Have the switch either connect a node to 24 V or not.  That works directly for the pullup.  A resistor divider from there to the XOR gate can change the 0-24 V into 0-3.3 V.  For example, 100 k&Omega; pullup with 16 k&Omega; to ground would work.

One last issue is that you don't want high voltage on the input back-driving the pullup node and changing the polarity of the XOR input.  The solution is to isolate each with a diode:


<img src="https://electrical.codidact.com/uploads/40vtjb92zzjgb3evfbux1qq7q0z5">