Analog thermostat question (Raspberry Pi)

Thread Starter

rfpd

Joined Jul 6, 2016
101
Hey there, I've been reading a book about IoT and I found something that didn't make much sense to me. The author said the thermostat worked as a variable resistor, so he calculated the charging time to get the 'thermostat resistor' value. The thing is, he said that GPIO #1 worked as an output and GPIO #4 worked as an input. So, he set #1 as HIGH, and then he measured the time until #4 was HIGH, subtracted those times and like so, got the charging time. I mean, it has it's logic, afterall, the eletrons in the capacitor will start to push back with the same force of the source when the capacitor is charged, the thing is, #4 is working as an open circuit, therefore it will always have the same value as #1, right?



i.jpg
 

BR-549

Joined Sep 22, 2013
4,938
How much electronic knowledge do you have? Are you familiar with RC time constants, and GPIO configurations? And are you familiar with how a processor measures time?
 

Thread Starter

rfpd

Joined Jul 6, 2016
101
How much electronic knowledge do you have? Are you familiar with RC time constants, and GPIO configurations? And are you familiar with how a processor measures time?
I have basic electronic knowledge that I learned on my college, GPIO is new to me (like I said in the first post), I'm familiar with RC time constants of corse. But the example I learned back then is charging the capacitor with a battery and then opening the switch. That way we would watch the discharge of the capacitor.

I mean, ignoring that there was GPIO inputs/outputs, would this still work? I understand the logic behind it, but it doesn't make much sense to me. I'm imagining #4 as an open circuit and that way it would have the same voltage as in #1. I'm new to this, that's why I'm asking, the only thing you mentioned I'm familired with is the RC time constant. I mean I even tried it in MultiSim, just to make sure, and it had the same voltage in both points all the time (without the GPIO inputs/ouputs, just a dc source pretending to be #1 and an open circuit on #4 with the resistor), even decreased the time window.

Sorry for the noob question and thanks for the answer.

The idea is sound (meaning correct). I do it all the time.

btw, the correct word is thermistor, not thermostat.
Sorry about that, I'm not english, so somethings I might say wrong or translate the wrong way.
 

BR-549

Joined Sep 22, 2013
4,938
Pretend that pin 4 is disconnected from the RC circuit. Do you understand that when the voltage is turned on at pin 3..........pin 3 voltage remains constant.........and the voltage at the junction of the thermistor and the cap............takes a certain amount of time to reach the pin 3 value? That time period depends on the resistance value of the thermistor. That value depends on the temp.

So.....if we count the time for that voltage to come up.......we can figure the temp. So.....we put a voltage on pin 3 and start a timer. We connect and set pin 4 to cause an interrupt....when the voltage comes up. That interrupt.....stops the counter and calculates the time. We can equate that amount of time to the temp.

Does that make any sense?
 

crutschow

Joined Mar 14, 2008
27,945
Here's an LTspice simulation of a simple RC circuit for two different values of Rt (100kΩ and 150kΩ)
The simulation was done with the startup option so that the initial DC bias calculation is not done and thus everything starts at 0V.
Does that help explain things?

upload_2017-6-28_20-46-35.png
 
Last edited:

Thread Starter

rfpd

Joined Jul 6, 2016
101
Pretend that pin 4 is disconnected from the RC circuit. Do you understand that when the voltage is turned on at pin 3..........pin 3 voltage remains constant.........and the voltage at the junction of the thermistor and the cap............takes a certain amount of time to reach the pin 3 value? That time period depends on the resistance value of the thermistor. That value depends on the temp.

So.....if we count the time for that voltage to come up.......we can figure the temp. So.....we put a voltage on pin 3 and start a timer. We connect and set pin 4 to cause an interrupt....when the voltage comes up. That interrupt.....stops the counter and calculates the time. We can equate that amount of time to the temp.

Does that make any sense?
I understood everything, except the part in bold. I always thought that 'delay' happened after the capacitor, not before. That's what I'm not understanding.

Here's an LTspice simulation of a simple RC circuit for two different values of Rt (100kΩ and 150kΩ)
The simulation was done with the startup option so that the initial DC bias calculation is not done and thus everything starts at 0V.
Does that help explain things?
I tried that in MultiSim and I got this:

Capturar.PNG
 

ebeowulf17

Joined Aug 12, 2014
3,282
I understood everything, except the part in bold. I always thought that 'delay' happened after the capacitor, not before. That's what I'm not understanding.



I tried that in MultiSim and I got this:

View attachment 129972
I think what you're missing is the "startup option" that crutschow mentioned. Your simulation is starting with the circuit already stabilized at 12V. If you add a switch, program a delay on your voltage source, or find the multi sim equivalent of "startup option," then you'll see the capacitor gradually charge up.

As for why pin 1 and pin 4 can have different voltages, the resistor (thermistor in your intended application) makes that possible. The fact that pin 4 is like an open circuit doesn't change the rest of the circuit.

At the start, both pins and the top side of the cap should start at 0V. When pin 1 is switched high, there's a voltage difference across the resistor between pins 1 and 4, which causes current to flow through the resistor and gradually charge the cap. When the cap is charged to the same voltage as pin 1, current stops flowing and the circuit reaches a new equilibrium. The time it takes for this to happen is a function of the resistance value of the thermistor and the capacitance of the cap.
 

crutschow

Joined Mar 14, 2008
27,945
Here's the sim using a pulse output from the source, similar to what MrChips mentioned.
With that you don't have to use the startup option.

upload_2017-6-29_0-36-32.png
 

Thread Starter

rfpd

Joined Jul 6, 2016
101
Thanks, I added a switch and it worked.
I think what you're missing is the "startup option" that crutschow mentioned. Your simulation is starting with the circuit already stabilized at 12V. If you add a switch, program a delay on your voltage source, or find the multi sim equivalent of "startup option," then you'll see the capacitor gradually charge up.

As for why pin 1 and pin 4 can have different voltages, the resistor (thermistor in your intended application) makes that possible. The fact that pin 4 is like an open circuit doesn't change the rest of the circuit.

At the start, both pins and the top side of the cap should start at 0V. When pin 1 is switched high, there's a voltage difference across the resistor between pins 1 and 4, which causes current to flow through the resistor and gradually charge the cap. When the cap is charged to the same voltage as pin 1, current stops flowing and the circuit reaches a new equilibrium. The time it takes for this to happen is a function of the resistance value of the thermistor and the capacitance of the cap.
Just to make sure I got this right, in an RC circuit, initially both plates of the capacitor are equally charged, therefore the potential difference is zero, and since it's connect to ground, we're 'forcing' the entrance of the capacitor to be zero. When we supply a dc voltage, I'm imaging it like each fraction of time eletrons arrive at the capacitor, accumulating at the first plate and making the second plate discharge eletrons to ground, therefore we are creating a potential difference and that potential difference will rise exponentially until the value of the DC source.

Since the resistor only transforms eletric energy into thermic energy, this phenomenon doesn't happen and the change of voltage is instantaneous.
 

crutschow

Joined Mar 14, 2008
27,945
it like each fraction of time eletrons arrive at the capacitor, accumulating at the first plate and making the second plate discharge eletrons to ground
That's true for a negative voltage.
If you applying a positive voltage then you are removing electrons from the top plate, causing electrons to be added to the grounded plate.
Since the resistor only transforms eletric energy into thermic energy, this phenomenon doesn't happen and the change of voltage is instantaneous.
You mean across a resistor all by itself?
 

Thread Starter

rfpd

Joined Jul 6, 2016
101
That's true for a negative voltage.
You mean across a resistor all by itself?
I mean if instead of a capacitor, in the above circuit, there was a resistor, this phenomenon would not happen, the voltage at its entrance would instantly change.
 

nsaspook

Joined Aug 27, 2009
8,782
I mean if instead of a capacitor, in the above circuit, there was a resistor, this phenomenon would not happen, the voltage at its entrance would instantly change.
It would be very quick due to wire propagation delays and the low values of reactance (5 pF Pin capacitance typical) in the circuit but not instantaneous in a real-world circuit.
 

ebeowulf17

Joined Aug 12, 2014
3,282
I have a question about this technique for the experts here who utilize it:

How do you get accurate measurements out of this method when capacitors tend to have huge tolerances (+/-20% or worse seems typical) and the high/low threshold voltage for GPIO pins is also often not well defined. Do you just build the circuit with a reasonable guess on ballpark component values and then calibrate the firmware for each build experimentally, based on empirical data?

If so, that would seem to make this a hobby-only method, not suitable for mass production.

I love the elegant simplicity of this method over methods requiring ADCs and more complicated input circuits, but when I imagine using it myself the unpredictability bothers me.
 

BR-549

Joined Sep 22, 2013
4,938
As long as we keep proper track of time........the analog properties aren't as confining.

That's the neat thing about digital circuits. It's not like analog where current is common.......it's the time and state that's common.

This allows low cost and low power precision.
 

ebeowulf17

Joined Aug 12, 2014
3,282
As long as we keep proper track of time........the analog properties aren't as confining.

That's the neat thing about digital circuits. It's not like analog where current is common.......it's the time and state that's common.

This allows low cost and low power precision.
Sure, but don't you then require manual calibration?

In the circuit that started this thread, the relationship between the thermistor's resistance and the time your microcontroller counts depends, quite heavily, on the capacitor value, right? If the cap is off by 20%, your time measurement will be off by a lot, and the calculated temperature reading will be off as well unless you apply a correction factor in the firmware.

Do you measure actual capacitance before building the circuit and calculate values for your code accordingly? Or do you build the whole thing, fire it up, and then measure a known temperature to calibrate?
 
Top