K60 ADC problem - Results are random

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

K60 ADC problem - Results are random

Jump to solution
7,783 Views
michalhrouda
Contributor I

Hi,

I have chosen MK60DN256ZVLL10 for my design and I have a problem with ADC (with both ADCs)

When I set input channel between 0 and 0x1C (including internal temp sensor) the result of the ADC is zero or random

(On channels 0 ~ 23 i get 0 or random values depending on MUXSEL setup and temperature sensor channel result is always random :smileyshocked: )

I get non zero (and correct) results only when i choose REFLH or Bandgap channels.

I tried Processor expert ADC component, Init_ADC component and code written by myself only (same behavior)

I tried all possible configurations of conversion modes, sampling timing, sampling time and calibrating feature.

Voltage on VREFH pin is correct (3.5 V) and voltage on pins that I would like to measure is correct and without any noise too.

List of pins that I use for measurement:

HUMIDITY      

=> PTC2/SPI0_PCS2/UART1_CTS_b/FTM0_CH1/FB_AD12/ADC0_SE4b/CMP1_IN0/TSI0_CH15 [72]

BAT_MEAS     

=> PTE0/SPI1_PCS1/UART1_TX/SDHC0_D1/I2C1_SDA/ADC1_SE4a [1]

PROX_MEAS     

=> PTB1/I2C0_SDA/FTM1_CH1/RMII0_MDC/MII0_MDC/FTM1_QD_PHB/ADC0_SE9/ADC1_SE9/TSI0_CH6 [54]

PWRSRC_MEAS   

=> PTC1/SPI0_PCS3/UART1_RTS_b/FTM0_CH0/FB_AD13/ADC0_SE15/TSI0_CH14 [71]

//enable bandgap

    PMC_REGSC |= PMC_REGSC_BGBE_MASK;

 

    //Processor Expert Init

    AD0_Init();

    AD1_Init();

    //Calibration

    ADC0_SC3 |= 0x80;

    while ((ADC0_SC1A && 0x80) == 0);

    ADC1_SC3 |= 0x80;

    while ((ADC1_SC1A && 0x80) == 0);

    for(;;)

    {

 

        ADC1_SC1A = 4;

        while ((ADC1_SC1A && 0x80) == 0);

        bat = ADC1_RA;

 

 

        ADC0_SC1A = 15;

        while ((ADC0_SC1A && 0x80) == 0);

        pwr = ADC0_RA;

 

        ADC0_SC1A = 9;

        while ((ADC0_SC1A && 0x80) == 0);

        prox = ADC0_RA;

 

        ADC0_SC1A = 4;

        while ((ADC0_SC1A && 0x80) == 0);

        hum = ADC0_RA;

 

        FRTOS1_vTaskDelay(500/portTICK_RATE_MS);

    }


Labels (1)
0 Kudos
Reply
1 Solution
4,938 Views
JimDon
Senior Contributor III

First, I hope you tried the code I posted.

This code works fine for me when things are properly inited, using a device init project:

  
unsigned long result;
....
for(;;) {  
       ADC0_SC1A=11;
       while ((ADC0_SC2 & 0x80));
       while (!(ADC0_SC1A & 0x80));
       result=ADC0_RA;
  }

If it is hanging, then something is not set up right.

I have attached the mcuinit file generated by device init I used.

Enjoy!!

View solution in original post

0 Kudos
Reply
31 Replies
1,127 Views
michalhrouda
Contributor I

I'm sure that I did not overclock or underclock ADC. Pay attention to the fact that measurements on internal bandgap, internal temperature sensor, VREFH and VREFL are correct. Could overclock or underclock affect/damage ADC channel multiplexor only?

0 Kudos
Reply
1,127 Views
adriansc
Contributor IV

Hi,

I am not really sure what is going wrong there. In the attachments you can find an ADC driver for any Kinetis Family MCU, compare this with your initialization and read codes.

Hope this helps.

0 Kudos
Reply
1,127 Views
michalhrouda
Contributor I

Thank you for your answer and example code I tried your code but i get same (wrong) results:

kinetis-adc-measurements.png

Code:

static void vAdcTestTask(void *pvParameters)

{

    //enable bandgap

    PMC_REGSC |= PMC_REGSC_BGBE_MASK;

      

    //Init

    ADC0_Init16b();

    ADC1_Init16b();

    //Calibration

    ADC0_SC3 |= 0x80;

    while ((ADC0_SC1A && 0x80) == 0);

  

    ADC1_SC3 |= 0x80;

    while ((ADC1_SC1A && 0x80) == 0);

  

    for(;;)

    {

        ADC0_Values[channel] = ADC0_Read16b(channel);

        ADC1_Values[channel] = ADC1_Read16b(channel);

                  

        channel++;

        if (channel >= 31) channel = 0;

        //10 ms delay

        FRTOS1_vTaskDelay(10/portTICK_RATE_MS);

  

    }

          

}


Here is layout of my pcb:

kinetis-adc-layout.png

0 Kudos
Reply
1,127 Views
adriansc
Contributor IV

Hi,

Did you try just one channel? I mean, just read one of the channels with problems just to dismiss that the problem can be because the time that other channels demand for conversion.

Is there a possibility to test your code in a TWR-K60?

Regards.

0 Kudos
Reply
1,127 Views
michalhrouda
Contributor I

Same code is working on TWR-K60N512 without any problems. That means, that there is a problem with hardware design :smileysad: 


I suspect that problem could be in 3.5V power supply (typical is 3.3V).

Update: Power supply voltage is not the issue = same behaviour @ 3.3V

0 Kudos
Reply
1,127 Views
adriansc
Contributor IV

As we say: Al mal paso darle prisa. This is like "Let's get it over and done with" keep us posted. I recommend you to have a look at Freescale's layout design, preferably TWR-K53 ,it has more ADC functions.

Regards.

0 Kudos
Reply
1,127 Views
michalhrouda
Contributor I

I'm just tried to resolder mcu and there was probably cold junction. Internal temperature sensor is working now. But channels that i'd like to measure (1~24) are still wrong but different. Values are not zero but random... :smileyconfused:

0 Kudos
Reply
1,127 Views
JimDon
Senior Contributor III

Since you have confirmed that the code is correct, then I suggest there is still a hardware problem. It ain't fixed until it's fixed.

Could be that the VREF connections are bad or any number of interconnect issues. You are in for a tough day, because you need to crawl through the hardware and figure out what's ups. Perhaps the chip has gone bad due to a short??. If there was a bad solder joint then most likely there are more. Only you can figure this out, as asking about symptoms is really tough for anyone else to answer when it is a hardware problem.

0 Kudos
Reply
1,127 Views
michalhrouda
Contributor I

Do you think that problem is in layout/hardware design or in soldering quality?

0 Kudos
Reply
1,127 Views
michalhrouda
Contributor I

Yes, I did. I get zero all the time on all channels that I would like to measure (I was measuring on one channel and putting values into buffer)

Most confusing to me is the fact that the value measured on internal bandgap channel is always correct (19101/65535 * 3,5V = 1V) and value measured on internal temperature sensor is always zero

I'm going to try my code on TWR-K60 today

0 Kudos
Reply
1,127 Views
JimDon
Senior Contributor III

Adrian,

I think what you are really questioning is if your sample code correctly waits for a conversion to complete.

Only the channel number you write to the register will be converted.

0 Kudos
Reply