Hi,
thanks for reply. First I have to say that measured ADC (11th)channel pin is not floating and is defined using 4k7 potentiometer at about a half Vcc (1,6V) so it is well defined and steady. My code is:
int main(void)
{
MCU_init(); /* call device initialization */
for(;;) {
ADC0_SC1A=11;
while ((ADC0_SC2 & 0x80));
while (!(ADC0_SC1A & 0x80));
result=ADC0_RA;
}
return 0;
}
Init code for ADC generated by Device Initialization GUI:
/* ### Init_ADC init code */
/* SIM_SCGC6: ADC0=1 */
SIM_SCGC6 |= (uint32_t)0x08000000UL;
/* ADC0_CFG1: ADLPC=0,ADIV=3,ADLSMP=1,MODE=1,ADICLK=0 */
ADC0_CFG1 = (uint32_t)0x74UL;
/* ADC0_CFG2: ADACKEN=0,ADHSC=0,ADLSTS=0 */
ADC0_CFG2 &= (uint32_t)~0xFFFFFFEFUL;
/* ADC0_CV1: CV=0 */
ADC0_CV1 = (uint32_t)0x00UL;
/* ADC0_CV2: CV=0 */
ADC0_CV2 = (uint32_t)0x00UL;
/* ADC0_OFS: OFS=4 */
ADC0_OFS = (uint32_t)0x04UL;
/* ADC0_SC2: ADACT=0,ADTRG=0,ACFE=0,ACFGT=0,ACREN=0,DMAEN=0,REFSEL=0 */
ADC0_SC2 = (uint32_t)0x00UL;
/* ADC0_SC3: CAL=0,CALF=0,ADCO=0,AVGE=0,AVGS=0 */
ADC0_SC3 = (uint32_t)0x00UL;
/* ADC0_SC1A: COCO=0,AIEN=0,DIFF=0,ADCH=0x1F */
ADC0_SC1A = (uint32_t)0x1FUL;
/* ADC0_SC1B: COCO=0,AIEN=0,DIFF=0,ADCH=0x1F */
ADC0_SC1B = (uint32_t)0x1FUL;
1. If I am stepping cpu the first pass of infinite loop the result is 0 at next pass the result is about 1,4V at next pass the result is 1,9V,... The result is wrong by as much as 30%.
2. But if I run the cpu without stepping it, it never reaches the line"result=ADC0_RA;" if I pause the execution it stops at line "while (!(ADC0_SC1A & 0x80));" like the conversion is never finished.
It is true that I am not using ADC calibration yet but this shouldn't be the cause of described behavior.
Best regards