• Forums
• Posts
Latest Posts
Active Posts
Recently Visited
Search Results
• Page Extras
• Forum Themes
• AVR Freaks

Calculate temperature from ADC value of MCP9701A sensor

Author
litunbls
Junior Member
• Total Posts : 107
• Reward points : 0
• Joined: 2016/12/28 10:29:43
• Location: 0
• Status: offline
0

Calculate temperature from ADC value of MCP9701A sensor

Dear all , I use MCP9701A sensor to an 12 bit ADC(reads from 0 to 4095).
I want to convert this ADC value to room temperature in degree centigrade.

Can some one help me which data are necessary from the data sheet(http://ww1.microchip.com/downloads/en/DeviceDoc/20001942G.pdf)
to find the linear relationship between ADC value and temperature.

Pl specify the page no. or graph no (from the above datasheet) which i can derive the linear relationship.

KTrenholm
Super Member
• Total Posts : 709
• Reward points : 0
• Joined: 2012/08/08 14:04:23
• Location: Connecticut, USA
• Status: offline
Re: Calculate temperature from ADC value of MCP9701A sensor 2017/09/06 11:45:00 (permalink)
4 (1)
litunbls
Dear all , I use MCP9701A sensor to an 12 bit ADC(reads from 0 to 4095).
I want to convert this ADC value to room temperature in degree centigrade.

Can some one help me which data are necessary from the data sheet(http://ww1.microchip.com/downloads/en/DeviceDoc/20001942G.pdf)
to find the linear relationship between ADC value and temperature.

Pl specify the page no. or graph no (from the above datasheet) which i can derive the linear relationship.

I use this exact sensor.  The transfer function is on EQUATION 4-1 on page 8 of the spec.
I'm using a 10-bit ADC and a 9700, so the offset is 500mV and the T coefficient is 100, a 9701 would be 400mV and 195 (see the Sensor Output DC characteristics on page 2).  Just replace the macro values for a 12-bit ADC.

` #define ADC_VREF           5.0f#define ADC_V_PER_COUNT     ADC_VREF/1023.0f#define MCP9700_T_COEFF     100.0f      /*From MCP9700 Spec*/#define MCP9700_OFFSET      0.5f    /*500mV offset*/ uint16_t adc_raw;float voltage;float temperature;voltage = adc_raw * ADC_V_PER_COUNT;temperature = ((voltage - MCP9700_OFFSET)*MCP9700_T_COEFF);`

du00000001
Just Some Member
• Total Posts : 2769
• Reward points : 0
• Joined: 2016/05/03 13:52:42
• Location: Germany
• Status: offline
Re: Calculate temperature from ADC value of MCP9701A sensor 2017/09/06 11:53:33 (permalink)
3 (1)
If you need accuracy beyond the nominal values, some 2-point calibration will be required. But this is another story.

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
litunbls
Junior Member
• Total Posts : 107
• Reward points : 0
• Joined: 2016/12/28 10:29:43
• Location: 0
• Status: offline
Re: Calculate temperature from ADC value of MCP9701A sensor 2017/09/06 12:54:31 (permalink)
0
`#define MCP9700_T_COEFF 100.0f /*From MCP9700 Spec*/#define MCP9700_OFFSET 0.5f /*500mV offset*/`

Can you enplane me where(page no or graph no) can I find these two values in my datasheet(link given in the 1st post).

KTrenholm
Super Member
• Total Posts : 709
• Reward points : 0
• Joined: 2012/08/08 14:04:23
• Location: Connecticut, USA
• Status: offline
Re: Calculate temperature from ADC value of MCP9701A sensor 2017/09/06 12:56:41 (permalink)
3 (1)
litunbls
`#define MCP9700_T_COEFF 100.0f /*From MCP9700 Spec*/#define MCP9700_OFFSET 0.5f /*500mV offset*/`

Can you enplane me where(page no or graph no) can I find these two values in my datasheet(link given in the 1st post).

You can try going back and reading my earlier post again:

I'm using a 10-bit ADC and a 9700, so the offset is 500mV and the T coefficient is 100, a 9701 would be 400mV and 195 (see the Sensor Output DC characteristics on page 2).
post edited by KTrenholm - 2017/09/06 13:00:46
litunbls
Junior Member
• Total Posts : 107
• Reward points : 0
• Joined: 2016/12/28 10:29:43
• Location: 0
• Status: offline
Re: Calculate temperature from ADC value of MCP9701A sensor 2017/09/06 13:46:02 (permalink)
3 (1)

Output Voltage, (TA = 0°C)        V @0°C = 400mV     MCP9701/9701A
Temperature Coefficient,TC = 19.5 mV/°C                 MCP9701/9701A

I fouhd above from thadata sheet.

So according to the formula(I use 12 bit ADC)

Thanks :)
du00000001
Just Some Member
• Total Posts : 2769
• Reward points : 0
• Joined: 2016/05/03 13:52:42
• Location: Germany
• Status: offline
Re: Calculate temperature from ADC value of MCP9701A sensor 2017/09/06 14:01:24 (permalink)
0
As you will find out soon enough, this
will not work.

`temp = (raw - 328) / 16;`

This is not perfect but good enough to start with. temp and raw have to be signed int to make that work (the constants are signed int anyway).

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
litunbls
Junior Member
• Total Posts : 107
• Reward points : 0
• Joined: 2016/12/28 10:29:43
• Location: 0
• Status: offline
Re: Calculate temperature from ADC value of MCP9701A sensor 2017/09/06 14:03:07 (permalink)
0
but there is a small doubt.
For the same temperature chip , I found following code from microchip(official demo code)

Any comment on this?
litunbls
Junior Member
• Total Posts : 107
• Reward points : 0
• Joined: 2016/12/28 10:29:43
• Location: 0
• Status: offline
Re: Calculate temperature from ADC value of MCP9701A sensor 2017/09/06 14:08:15 (permalink)
0
du00000001
As you will find out soon enough, this
will not work.

`temp = (raw - 328) / 16;`

This is not perfect but good enough to start with. temp and raw have to be signed int to make that work (the constants are signed int anyway).

Exactly what i was expecting................... !
But why it will not work if the first reply to this query is correct?
Where do you find this magic number 328 and 16 from the datasheet?
MBedder
Circuit breaker
• Total Posts : 6767
• Reward points : 0
• Joined: 2008/05/30 11:24:01
• Status: offline
Re: Calculate temperature from ADC value of MCP9701A sensor 2017/09/06 14:19:02 (permalink)
3 (1)
"litunbls"So according to the formula(I use 12 bit ADC)

Go back to primary school.
post edited by MBedder - 2017/09/06 14:22:16
du00000001
Just Some Member
• Total Posts : 2769
• Reward points : 0
• Joined: 2016/05/03 13:52:42
• Location: Germany
• Status: offline
Re: Calculate temperature from ADC value of MCP9701A sensor 2017/09/06 15:17:51 (permalink)
0
In integer, the following applies:
400/1000 = 0
19.5/1000 might work - 19.5/1000.0 will work.
raw*5/4095 = 0 (, 1, 2, 3, 4, 5 - these are all possible results with raw = 0 .. 4095)

328 = (0.4 V / 5 V) * 4095 (calculator, rounded)
16 = (0.0195 V / 5 V) * 4095 (calculator, rounded)

Everybody can calculate in float these days, but this will be quite slow. And 368.0 has to be a typo! My calculator bets on 327.68.
Even the bracketing is not so good (although it might work): I'd cast ... (( (float)ADCvalue ... to make sure I get what I want.
post edited by du00000001 - 2017/09/06 15:20:25

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
du00000001
Just Some Member
• Total Posts : 2769
• Reward points : 0
• Joined: 2016/05/03 13:52:42
• Location: Germany
• Status: offline
Re: Calculate temperature from ADC value of MCP9701A sensor 2017/09/06 15:23:04 (permalink)
0
@ MBedder
Is integer arithmetics a subject in primary school these days? Seems I'm getting old 😏

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)