ADC reading issue

Moderators: TomKerekes, dynomotion

Post Reply
joey16820
Posts: 1
Joined: Tue Feb 27, 2024 7:25 am

ADC reading issue

Post by joey16820 » Tue Feb 27, 2024 8:18 am

Hi,

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

User avatar
TomKerekes
Posts: 2546
Joined: Mon Dec 04, 2017 1:49 am

Re: ADC reading issue

Post by TomKerekes » Tue Feb 27, 2024 5:48 pm

Hi Joey,

To read Kogna ADCs from C access the buffer: Kogna_ADC_Buffer[n]. ReadADC is for Kanalog ADCs. I suppose we could make that support both.

There is also a Macro to convert to Voltage:

Code: Select all

float voltage = KOGNA_CONVERT_ADC_TO_VOLTS(Kogna_ADC_Buffer[0]);
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply