Internal Temperature Sensor for megaf4 ADC [database function operation]

Source: Internet
Author: User

Measure the ambient temperature around the chip. The output voltage of the temperature sensor is proportional to the temperature. The obtained temperature is measured by ADC.

Inside the chip, the temperature sensor is connected to the ch16 of adc1. If you do not use a sensor, you can set it to the powerdown mode to save power.

Main features:

Temperature measurement range:-45 ~ + 125 degrees Celsius

Temperature Measurement Accuracy: ± 1. 5 degrees Celsius

Procedure:

1. Select adc1 ch16 as the input of the ADC.

2. Set the sampling time

3. Set the tsvrefe bit of adc1 register adc_cr to wake up the temperature sensor from the powerdown mode.

4. Start ADC Conversion

5. Read the conversion value and convert it to the voltage vsense, vsense = Value × 3300/4096 (MV)

6. Calculate the temperature.

Temperature Calculation formula: temp = (vsense-V25)/avg_slope) + 25

V25 is the value of vsense at 25 degrees, and avg_slope is the temperature conversion rate. The two values can be found in Datasheet.

V25 = 0.76 v avg_slope = 2.5 mV/°C

Temp = (vsense-760)/2500 + 25;

【CodeImplementation]

First, wake up the temperature sensor:

Adc_tempsensorvrefintcmd (enable );

Move the previousProgramTo 16 channels:

Adc_regularchannelconfig (adc1, adc_channel_16, 4, adc_sampletime_144cycles );

Read the converted value and use the above formula to calculate it:

AA = adcvalue [I]-760;
Printf ("Current temperature: % F degree Celsius \ r \ n", (aa)/2.5 + 25 );
Printf ("% d \ r \ n", adcvalue [I]);

Pay attention to the data type here. adcvalue defines uint16_t and is the unsigned number.

 

The temperature can be read here, but there is still a problem: the temperature is not accurate. The temperature I read at night is 68 degrees. I don't know if the internal temperature is high after the film has been working for a long time or my calculation is wrong.

However, the temperature does change with the temperature. When the board is powered off, the temperature will decrease, but it is still inaccurate.

 

Technorati flag: 440f4, ADC, Temperature Sensor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.