0
\$\begingroup\$

This question already has an answer here:

I am using an ST STM8AF5288 microcontroller powered by 5V in one of my projects (STM8AF5288 home, datasheet). Is it possible to directly sense a +12V signal input by port pins?

I am using a current limit resistor in the input. All the port pins in the ST STM8AF5288 microcontroller have clamping diodes. Will I able to sense a +12V signal input? Below is the circuit used in my project:

components between +12V signal input and MCU input

\$\endgroup\$

marked as duplicate by Rev1.0, Harry Svensson, winny, Sparky256, Dave Tweed Sep 9 '18 at 16:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ Here we directly sense +12v.No divider used here. \$\endgroup\$ – Raja Sep 4 '18 at 9:01
  • \$\begingroup\$ Is your MCU always powered or should it be able to cope with that 12V signal when off? \$\endgroup\$ – Dmitry Grigoryev Sep 4 '18 at 11:02
  • 1
    \$\begingroup\$ My MCU always powered. \$\endgroup\$ – Raja Sep 4 '18 at 11:08
2
\$\begingroup\$

Move your R1 resistor and place it in parallel with the C1 capacitor so that you get a voltage divider effect from the 12V signal down to the acceptable input voltage of the MCU. You may have to adjust the resistor values to get the correct divider ratio.

Do not rely on the input voltage clamps on the MCU to limit the input high voltage level. Clamps are put on the chip to protect the inputs for extreme conditions and are never meant to be used in normal usage application.

\$\endgroup\$
  • \$\begingroup\$ Is it possible to use by limit the injection current? \$\endgroup\$ – Raja Sep 4 '18 at 10:18
  • 1
    \$\begingroup\$ @Raja - Some people think that it is OK to use the clamp diodes by limiting the injection current. Experienced engineers that I know would never intentionally use the clamping diodes like that. \$\endgroup\$ – Michael Karas Sep 4 '18 at 15:52
1
\$\begingroup\$

To quote the spec:

STM8A I/Os are designed to withstand current injection. For a negative injection current of 4 mA, the resulting leakage current in the adjacent input does not exceed 1 μA.

So yes, you can rely on clamping diodes to some extent and your circuit would work as is. However, for a 12V input constructing a voltage divider is trivial, and should be preferred as a safer, more scalable and universal solution.

\$\endgroup\$
1
\$\begingroup\$

The circuit you show may work in some conditions but is bad in general.

By depending on the internal protection network to clamp the voltages you can get unwanted and larger than anticipated leakage currents out of adjacent (on the die) pins. This can cause problems with high impedance digital or moderate impedance analog inputs (think about how many uA would cause 1 LSB error on an ADC). The long term reliability can also be questioned.

A Schottky clamp to Vdd is an easy way to deal with that (make sure that there is enough current draw Vdd that the current of all 12V inputs high does not raise Vdd out of regulation- note that this is also true when you use your circuit- there's a hidden path inside the chip to Vdd.

A suitable part number is BAT54A (you get two diodes per SOT-23).

\$\endgroup\$
0
\$\begingroup\$

As you don't share the ST part number I will gess that it is supplied from 1.8 to 3.3V. So you can't connect directly to the microcontroller input, it will be out of the specs. My recommendation will be to use a voltage divider to transform the 12V to a voltage inside the range of your microcontroller input.

EDITED

As you can see from datasheet maximum ratings, the maximum voltage allowed will be vdd +0.3, in your case 5.3V. Any value above may/will harm the device.

STM8AF526x/8x/Ax Absolute maximum ratings

\$\endgroup\$
  • \$\begingroup\$ Am using STM8AF5288 and the supply voltage is 5V. \$\endgroup\$ – Raja Sep 4 '18 at 7:28
  • \$\begingroup\$ Hi Marcos...The input voltage range is ok but the injection current is 4mA for pin mentioned in the datasheet. \$\endgroup\$ – Raja Sep 4 '18 at 9:37
  • 1
    \$\begingroup\$ Guess I should have asked this first. What do you want to do with the 12V? Reading the voltage with the ADC? Using it as a digital signal (1 or 0)? or ...? \$\endgroup\$ – Marcos Sep 4 '18 at 10:21
  • \$\begingroup\$ sensing digital voltage level..High or low. \$\endgroup\$ – Raja Sep 4 '18 at 10:57
  • \$\begingroup\$ Then don't worry. As you configure the pin as input it won't drain current from your source. When microcontroller pins are configured as input they have a very high input impedance so the current drained by the micro is very low. In page 106 of the reference manual: st.com/content/ccc/resource/technical/document/reference_manual/… You can see that when it is configured as input it goes through a schmidt trigger (High impedance imput circuit) thus very little current is drain. \$\endgroup\$ – Marcos Sep 5 '18 at 11:32

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