Electronics question on smoothing out the input for a TMP36 sensor

I have a TMP36 that I am using with a Spark Core. I have gotten it working and (what I believe to be) accurate.

I still have so much to learn as far as electronics but I wanted to ask the experts here regarding the particular setup.

The Spark Core has the 3v3’ going to the TMP36 and I have it going to ground. I have the Vout going to A7. I also have a 103 ceramic cap shunting the Vout to GND.

I was looking at this post from Simon Monk where he pulled up the datasheet for the TMP36 and suggested using a 20k or 47k Ohm resistor across Vout to GND. I have a 0.01uF in place of that.

So, my question here is would it be acceptable and equatable to handle that on the software side by doing this:

pinMode(A7, INPUT_PULLDOWN);

I have that in place and I am getting extremely steady values but I don’t know if it is the cap or the internal pull-down resistor or a combination of both.

analogRead() uses a special input mode (AN_INPUT) which does not allow internal pull-resistors, so you need to add an external.
In fact for analogRead() you should not even set a pinMode() in code at all - read function handles that internally.

1 Like

@ScruffR I did not know that. I’m so used to doing pinMode() assignments with Arduinos.

What would happen if I added a 47k ohm resistor across the 0.01uF cap?

That’s perfectly fine.
The resistor does the DC pulling while the cap shorts out high frequency noise and as side effect adds a minimal voltage/power “buffer” for the internal ADC S&H caps.

BTW, I’d prefer the term “parallel to” over “across:wink:

I’m not sure, but the pinMode() thing might also apply to Arduino - worth a try?

1 Like

Awesome. I’m going to give it a shot and see.

IIRC, a capacitor and a resistor in parallel can create oscillations, right? I may be getting some things confused here, it’s been a few years for me.

1 Like

That's for a capacitor and inductor, the resistor would influence the charge/discharge time of the setup.

2 Likes

@eavery, a capacitor in parallel with a resistor forms a simple RC filter with a time constant calculates as t = RC. In the case of the TMP36, this circuit can serve to filter out the high frequency sampling noise that is inherent with an ADC. However, it will also present an impedance to the ADC input which may not be suitable. This is why an op-amp “follower” or unity-gain amplifier is used. It’s input is very high impedance while it output is the opposite. Arduino’s ATMega328 used on the UNO uses an op-amp input for its ADC. The impedance game is one of the reasons there are so many digital sensors available, including OneWire sensors like the DS18b20 which use 3 (or 2) wires (V+, GND, DATA), can accomodate multiple sensors on the same bus and can be located quite far from the processor. :smile:

3 Likes

I think someone mentioned that D0 is a steadier power supply. Instead of 3V3, try using that pin in a HIGH state.

@cwingrav Do you know if that is true for Spark Cores or with Photons?

Most of my background with this kind of stuff is with Arduinos and I recall from years back that it isn’t a good idea to source from a GPIO. Rather, using a transistor and run the base to the GPIO and the collector/emitter along the positive line to the component to control power.

I don’t rightly recall the reasoning behind that (low current, maybe?) but I would imagine that it would remain true with the Cores.

Is there any documentation that could demonstrate higher stability in voltage sourced from a digital I/O pin rather than the conditioned 3v3’ pin?

NB: I noticed that Photon does not have a conditioned 3v3 (displayed as 3v3’) like the Cores do. With that in mind, is the voltage sourced from a GPIO more stable than the 3v3? How about the 3v3’?

@eavery, using a digital pin as a power source does not provide “cleaner” power and is limited to providing 25ma at most. The Core used and LDO or linear regulator whereas the Photon uses a buck mode switching regulator. The linear regulator is low noise but not as efficient. However, the switching regulator does produce high frequency ripple noise on the 3V3 supply. The Core had an LC circuit to filter the 3V3 output and provided it on a seperate 3V3* pin. The Photon does not have this circuit. For this reason, filtering high frequency noise on the analog inputs becomes important.

2 Likes

Do you know what the optimal values for the resistor and capacitor are to filter out the Photon's voltage regulator noise? I'm reading a Velostat based pressure plate, and seeing a lot of variation in values; I don't know if this is the fault of the pressure plate itself, or something to do with the ADC.

@Ric I don’t have the datasheet up for the Velostat pressure plate but I have an analog sensor that I am sourcing from my 3v3* line with an RC filter that is attached between Vout and the my analog I/O.

The cap value is 0.01 uF (103 is written on ceramic caps) and I have a 47k ohm resistor in parallel (as a pulldown so readings won’t float).

Run one leg of the cap from Vout to ground as close as you can to the sensor. Then put the appropriately sized resistor in parallel with the cap. That should shunt unwanted frequencies to ground.

@peekay123 please let me know if this sounds correct to you.

Cheers!