2
\$\begingroup\$

I was working with a Nucleo f411re (STM32 MCU) in order to read several analog sensors.
I started testing a single temperature sensor (LM35) and all was fine. When I added a linear potentiometer for reading its extension, a strange fact happened: the temperature read increased proportionally to the extension of the potentiometer. Here's the circuit:

schematic

simulate this circuit – Schematic created using CircuitLab

PA0 and PA1 are analog pins, connected to stm32 ADC. Here you can find the ADC datasheet.

So I measured the output voltage from LM35 with multimeter and it was stable even when I was extending the potentiometer; while, if read from Nucleo, the temperature was "following" the potentiometer read.

I solved this problem adding a 1 µF capacitor between ground and the V_out of LM35. But I'm not satisfied, because I would like to know the reason of the strange temperature read behavior. Any Idea?

EDIT: I have found something that could explain this problem at section 3.4.1 of the ADC datasheet. It seems a known issue, due to the sampling switch in the internal sampling circuit of the ADC. Can you confirm this?

\$\endgroup\$
  • 1
    \$\begingroup\$ We need a schematic diagram. There's an button on the editor toolbar. Click it! "When I added a linear potentiometer ..." How can we possibly guess where you added it? \$\endgroup\$ – Transistor Sep 16 '16 at 18:07
  • \$\begingroup\$ Please post your code also. \$\endgroup\$ – Bence Kaulics Sep 16 '16 at 18:08
  • 1
    \$\begingroup\$ Probably your sample time was too short for the impedance of the sensor, and you read it immediately after the pot (I'm assuming it's got a single ADC multiplexed to pins) \$\endgroup\$ – pjc50 Sep 16 '16 at 18:20
  • \$\begingroup\$ @pjc50, I think is somewhat in ADC the problem. Can you explain me your hypothesis? \$\endgroup\$ – Bernheart Sep 16 '16 at 18:44
  • 1
    \$\begingroup\$ Well, with a datasheet and a circuit diagram, this is now a good and upvotey question. \$\endgroup\$ – pipe Sep 16 '16 at 19:06
4
\$\begingroup\$

There are a lot of things that could be causing this problem. see here. However, what appears to be the most obvious is a problem with sampling time.

If you check out page 35, it mentions that the ADC is a sample and hold converter: it has a capacitor that charges (or discharges) until it has the same voltage as the source, then it reads that value. The time for this is set by the time that SW1 is on: the "sampling time". If there isn't enough time for the capacitor to discharge/charge to the correct voltage before turning off the switch and reading the value (depending on the resistance of the source), then you won't get the right value.

schematic

simulate this circuit – Schematic created using CircuitLab

This is in the section on problems with reading high impedance sources. The LM35 has a low impedance output if it is sourcing current, it can only sink 1µA of current though, which makes it a very high impedance current sink.

If you are setting a higher voltage with the pot than you are reading from the LM35, then the current from the capacitor needs to flow out of C_sh through the LM35: this is very slow (because of that 1µA current sink capability), and thus your sampling time is too short.

A capacitor helps to smooth this out, but also slows down the response time of the LM35.

A quick fix is to put a >1kΩ resistor in parallel with the LM35. This sinks current when you need it to, and gives a current path to ground for the current from C_sh.

\$\endgroup\$
  • \$\begingroup\$ Thank you! But I haven't understood how a capacitor can help to resolve this problem: in fact how can an external capacitor reduce the discharging time of C_sh? \$\endgroup\$ – Bernheart Sep 16 '16 at 20:10
  • 1
    \$\begingroup\$ A few explanations: 1) when the switch is initially attached, the external capacitor looks like a short to the fast transient of the higher voltage of C_sh, so a lot of the current will flow out rapidly that way. The lower frequency components of the transient are smaller and can flow out via the LM35. 2) you have a larger capacitor than C_sh on the output. When the two are put in parallel, all the charge is evenly distributed between them. Since the output capacitor is larger, it soaks up the extra charge from the internal capacitor and barely changes its voltage. \$\endgroup\$ – Andrew Spott Sep 16 '16 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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