Interfacing an MCP9700 analog temp sensor...???

User avatar
RBSe
Posts: 33
Joined: Wed Mar 06, 2013 7:42 pm
Location: Eureka, California
Contact:

Interfacing an MCP9700 analog temp sensor...???

Unread post by RBSe »

Hi,

In trying to fill the box of my Digi-Key order I ran across the MCP9700 (pdf) analog temp sensor for $0.30 and i thought it might work well on the EZSBC1 analog inputs.
The I.C. is a TO-92 case and has a range of -40c to +125c, 10mv/degree C output with a 500mv + offset .
How would I get a Farenheit output with 1 decimal in control basic code...???
Thanks for your help.

Robert
.
Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom.

Clifford Stoll
Daniel
Posts: 133
Joined: Tue Nov 13, 2012 2:10 pm

Re: Interfacing an MCP9700 analog temp sensor...???

Unread post by Daniel »

Hi Robert

There are many ways including just measuring the voltage, subtracting 500mV and then converting Celsius to Fahrenheit by multiplying by 9/5 and adding 32. There is a more direct way.
The sensor is specified from -40C to 125C and it is linear. With a bit of arithmetic it is easy to find that at -40 the readout measurement on the 10-bit ADC with a 3300mV reference will be 31 and 125 it will be (ideally) 542.5. Since the ADC does not measure fractions of a bit lets round that to 543. At -40C the temperature is also -40F and at 125C the temperature is 257 Fahrenheit.
Now we have the four points needed to use the MAP function described in the user manual on p37.

Code: Select all

'MCP9700 in Fahrenheit
'MCP0700 connected to pin 10 of the EzSBC1
PINMODE 10,ADC  'Use pin 10 as ADC input
tempX= INADC( 10 )
TempF = MAP( tempX, 31, 543, -40, 257)

'Multiply by ten, truncate the decimals and divide by 10 to get one decimal
TempF = ( INT (TempF*10) )/10.0  
PRINT TempF
END


Daniel
Andries Pretorius
Posts: 37
Joined: Thu Nov 01, 2012 10:57 am
Location: Johannesburg, South Africa

Re: Interfacing an MCP9700 analog temp sensor...???

Unread post by Andries Pretorius »

Nice efficient coding Daniel!!

Thank you

Andries
User avatar
RBSe
Posts: 33
Joined: Wed Mar 06, 2013 7:42 pm
Location: Eureka, California
Contact:

Re: Interfacing an MCP9700 analog temp sensor...???

Unread post by RBSe »

Fantastic Daniel!

I knew it would be a good example on how to use the MAP command.
But, i did not expect it to be so efficient and concise
Now i understand the power of the MAP command much better.
Thanks Daniel,

Robert
.
Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom.

Clifford Stoll
Post Reply