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);
}
Solved! Go to Solution.
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!!
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?
Thank you for your answer and example code I tried your code but i get same (wrong) results:
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:
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.
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
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.
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:
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.
Do you think that problem is in layout/hardware design or in soldering quality?
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
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.