Firstly, Hello to all, I am trying to design a circuit for automotive application that circuit will read positive and negative input signals in the same pin via selecting the type of input in the software. I designed a prototype circuit to do it.You can see it in this picture.

Software Configuable Input Read Circuit

I refered a digikey article. Link of the article is here Protecting Inputs in Digital Electronics. When I want to read positive signal (9 V - 32 V). I will set internal pull-down resistor and input will be active high. When I want to read negative signal (0 V) I will set internal pull-up resistor and input will be active low. Internal pull-up and pull-down resistor value of the STM32F042C6 vary between 25k to 55k but typical value is 40k. Do you have any recommendation to improve design of the circuit ?

Edited: If I don't use pull down resistor.While reading positive signal.The capacitor(C1) will not be discharged after I switch(SW1) from positive signal to floating(not connected) and I will still read it as a high input.In this pictureProblem to discharge capacitor you can see that the input of the mcu is hanging arround 2.96V when the input not connected and the pull down resistor not selected.Is there any way to solve this problem without using pull down resistor?

  • 2
    \$\begingroup\$ I have studied the schematic but see no evidence of a negative voltage source. Do you mean that you want to (not "wanna") read positive and zero-volt input signals? \$\endgroup\$
    – Transistor
    Mar 17, 2020 at 20:32
  • \$\begingroup\$ I meant to read positive and zero volt input signals.@Transistor \$\endgroup\$
    – mrt
    Mar 18, 2020 at 11:57

2 Answers 2


From the schematic it appears that you want to monitor the status of a signal that switches between +9 to +32 V and GND (0 V).

Switching pull-up to pull-down is an unusual approach and not necessary.

  • With R2 = 40 kΩ you will easily detect a 'high' on the input.
  • With SW1 grounded R2, R4 and R1 form a potential divider on the input. The input voltage will be given by \$ V_i = \frac {1.01}{40 + 1.01}3.3 = 81 \ \text {mV} \$. This should be well below your logic low minimum allowable voltage.

You don't need to use pull-down.

  • \$\begingroup\$ It appears to me there is a third 'no pulling' state, given by the 3 position switch. To read 3 different position of a switch like that would need the software configuration they ask about. \$\endgroup\$ Mar 17, 2020 at 21:14
  • \$\begingroup\$ The thought had crossed my mind but it wasn't stated in the question. Let's see what the OP says. \$\endgroup\$
    – Transistor
    Mar 17, 2020 at 21:17
  • \$\begingroup\$ I used 3 position switch to demonstrate that the input pin can be in three different position.First position connected to positive signal. Second position left open.Third position connected to ground.@ambitiose_sed_ineptum \$\endgroup\$
    – mrt
    Mar 18, 2020 at 12:05

I think using "positive" and "negative" terms made the question somewhat confusing.

There are two possible scenarios. In the first case you have so called "active low" and "active high" signals, produced by push-pull sources. In this case you technically don't need either pull-up or pull-down resistors at all, incoming signal will take care of that. The distinction between active-low and active-high logic has to be made in software for this MCU. Some higher up the STM product line MCUs have much more advanced input circuitry where you can configure the polarity of a signal and even apply hardware filtering/conditioning.

Note, that you cannot use pull-up or pull-down to detect "no signal" condition (open switch in your schematics). The only thing they can help with is avoid erratic input switching when signal disconnected. Even that is probably non-issue with the capacitor on the input and Schmitt trigger circuitry inside.

You also cannot use pull-up/down to change the logic levels of the signal. Positive input is still high, and ground is still low. If you want to read inverted logic and can't do it in code or MCU hardware you would need external inverting gate and a way to bypass it.

The second case is when you want to accommodate tri-state or open-drain/collector signal sources. I doubt you can find many sources alternating between positive voltage and floating state as you describe. So, in this case you do need pull-up active. The good news is that weak pull-up is compatible with push-pull signals as well, as @Transistor pointed out. The bad news is that 40k is way too weak and prone to noise errors. Adding stronger external pull-up might help but you should be careful with calculations, as it forms voltage divider with protection resistors. Knowing source impedance is also helpful here.

Pull-down also can be useful for tri-state or for handling no signal condition. Typically, the choice is made to emulate an idle state of the incoming signal. For example pull-up for UART, pull-down for RS-232.

Finally, if you do find examples of "open-source" signals or if you want to detect disconnected state, then your schematics should be slightly more complicated. One of the possible solutions is to use input biasing and analog input mode.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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