1
\$\begingroup\$

Hi I am using an analog input pin on an STM8 microcontroller, I want to measure a potentiometer that I expect to change voltage slowly (<1 V/s) I also expect there to be some noise at a higher frequency from a nearby motor.

I was planning on using a large (1 µF) bypass capacitor and some series resistance (1 Ω) to filter out the noise and allow measuring the voltage. But having read the documentation for the MCU I'm now not sure this is ok.

Specifically the analog input section on page 11 here: https://www.st.com/resource/en/application_note/an2752-getting-started-with-stm8s-and-stm8af-microcontrollers--stmicroelectronics.pdf

They give this schematic including the external components I was planning on placing:

analog input schematic from link

But they also give this equation without much context, which imples that I can't add the values of resistor/ capacitor I was planning to add:

equation from link

I can't see electrically why adding a bigger external capacitor would stop Csamp charging in time (because it would just charge from the external capacitor), but that seems to be the implication here? RM0016 doesn't seem to have any more information on the topic.

\$\endgroup\$
6
  • \$\begingroup\$ 1 ohm would be quite useless, compared to the potentiometer. You need to know what's a good range for the maximum source impedance, so your potentiometer which value is unknown can be selected properly. And the response time of RC filter, if you need it. Rext is both your pot source impedance and RC filter resistance. \$\endgroup\$ Commented Jan 13 at 9:22
  • \$\begingroup\$ Do you have any more information on how to select the input inpedance? it's a 5Kohm pot, 3.3v supply \$\endgroup\$ Commented Jan 13 at 10:25
  • \$\begingroup\$ Basically the formula says it already, but from a slightly different perspective. If Rext (which includes pot and your RC series resistor), it limits the bandwidth but even without external cap, series resistance will affect if the internal sampling cap will charge in time. For example for AVRs, the suggested source impedance is max 10k. If you have a 5 kohm pot, max source impedance is 1.25 kohms. \$\endgroup\$ Commented Jan 13 at 10:44
  • 1
    \$\begingroup\$ @mond It's not sampled at 2 MHz. The system clock for the ADC in the MCU is 2 MHz. It would be able to convert every 7 us or at 143 kHz if put into continuous mode, but of course you can tell the ADC to sample once per second or once per day. \$\endgroup\$ Commented Jan 13 at 22:38
  • 1
    \$\begingroup\$ @Mike Just so you know, their internal values of 30 kOhm and 3 pF provide a tau of 90 ns. It takes about 588 ns for the input to completely settle to 1.5 parts in 1024, 624 ns to settle to 1 part in 1024, and 686 ns to settle to 0.5 parts in 1024. Independent of external details. Keep in mind. \$\endgroup\$ Commented Jan 14 at 8:17

1 Answer 1

1
\$\begingroup\$

The datasheet gives out specs for the ADC when source impedance (Rain) is up to 10 kohms.

And with a 5 kohm pot, the maximum output impedance is reached at midpoint when there is 2.5k to supply and 2.5k to ground, meaning the source impedance is 1.25 kohms. It may not even need any extra capacitor for filtering.

If you want to put an extra capacitor for filtering, the value is only relevant to noise frequencies, or what RC lowpass cut-off frequency you want.

As the maximum output impedance of pot is 1.25 kohms, with 1 uF capacitor, the RC cutoff freqency is as low as 127 Hz.

As the ADC has a dynamic range of 10 bits or 60dB, and RC filter has slope of attenuating 20dB per decade, 1270 Hz noise is down by 20dB, 12700 Hz noise is down by 40dB, and 127000 Hz noise is down by 60dB, or beyond level of ADC converter dynamic range.

So technically, even a 100nF cap would do well, and would be needed in any case when source impedance is above 10kohms. For example sensing a battery voltage by dividing it down to half with 1 megaohm resistors cannot be sampled because the internal sampling capacitor cannot charge through the 500 kohm source impedance, so that's why the voltage is kept stable within 0.5LSB of ADC conversion result by the external cap, and as long as the conversion is not done too often, the external capacitor will get charged via the large source impedance between ADC conversions.

\$\endgroup\$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.