I'm currently working with a TP100 temperature sensor that's connected to JP10 pin 25, which aligns with channel 8 on the ADC channel. The primary objective of my code is to interpret the ADC value, converting it into both voltage and temperature readings.
So far, the conversion processes are functioning as anticipated. However, I'm encountering an issue where the ADC reading for channel 8 consistently registers as 0. Upon testing, channels 1-7 provide accurate readings, but channels 8-11 only return a value of 0. Also, if I print directly from the console command, it returns the correct value. The hardware connections seem to be in order, as the voltage fluctuating between 0V and 5V in response to temperature changes—increasing with heat and decreasing upon cooling.
Below is the code I'm currently working with. Could there be an initialization step I've overlooked, or is there another reason why the readings might not be coming through as expected?
Thank you.
Code: Select all
#include "KMotionDef.h"
//#include "PC-DSP.h"
//extern int ADC_BufferIn[N_ADCS];
// Function to read from ADC and convert to temperature
void readtemp() {
// Read analog value from channel 8
int adc_value = ReadADC(8);
//int adc_value=489; //debug line for conversion
// Assuming 2047 counts is the maximum for 6.144V
float voltage = (float)adc_value * (6.144 / 2047.0);
// Convert voltage reading to temperature
float temp_range = 100.0 - 0.0;
float voltage_range = 5 - 0.0;
float temp = ((voltage - 0.0) / voltage_range) * temp_range + 0.0;
// Print results
printf("The ADC reading is %d, which corresponds to a voltage of %.2f V.\n", adc_value, voltage);
printf("This voltage corresponds to a temperature of %.2f °C.\n", temp);
}
int main() {
readtemp();
return 0;
}
//conversion checked
//reading ch0-7 ok
//reading ch8-11=0
//send in console ADC 8