This commit is contained in:
commit
f68987aaaa
1 changed files with 41 additions and 0 deletions
41
ArduinoDueInternalTemp
Normal file
41
ArduinoDueInternalTemp
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
//read the temperature of the integrated sensor on the Arduino DUE
|
||||
|
||||
float trans = 3.3/4096;
|
||||
float offset = 0.8;
|
||||
float factor = 0.00256;
|
||||
int fixtemp = 27;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
float treal = fixtemp + (( trans * temperatur() ) - offset ) / factor;
|
||||
Serial.println(treal);
|
||||
delay(10);
|
||||
}
|
||||
|
||||
uint32_t temperatur() {
|
||||
uint32_t ulValue = 0;
|
||||
uint32_t ulChannel;
|
||||
|
||||
// Enable the corresponding channel
|
||||
adc_enable_channel(ADC, ADC_TEMPERATURE_SENSOR);
|
||||
|
||||
// Enable the temperature sensor
|
||||
adc_enable_ts(ADC);
|
||||
|
||||
// Start the ADC
|
||||
adc_start(ADC);
|
||||
|
||||
// Wait for end of conversion
|
||||
while ((adc_get_status(ADC) & ADC_ISR_DRDY) != ADC_ISR_DRDY);
|
||||
|
||||
// Read the value
|
||||
ulValue = adc_get_latest_value(ADC);
|
||||
|
||||
// Disable the corresponding channel
|
||||
adc_disable_channel(ADC, ADC_TEMPERATURE_SENSOR);
|
||||
|
||||
return ulValue;
|
||||
}
|
||||
Loading…
Reference in a new issue