Hi Albert
I just checked operation on SE6b on a KL27 with following code:
ADC_SETUP adc_setup;
adc_setup.int_type = ADC_INTERRUPT;
adc_setup.pga_gain = PGA_GAIN_OFF;
adc_setup.int_priority = PRIORITY_ADC;
adc_setup.int_adc_controller = 0;
adc_setup.int_handler = adc_conversion_complete;
adc_setup.int_adc_int_type = (ADC_SINGLE_SHOT_TRIGGER_INT);
adc_setup.int_adc_bit = ADC_SE6_SINGLE;
adc_setup.int_adc_mode = (ADC_CALIBRATE | ADC_SELECT_INPUTS_B | ADC_CLOCK_BUS_DIV_2 | ADC_CLOCK_DIVIDE_8 | ADC_SAMPLE_ACTIVATE_LONG | ADC_CONFIGURE_ADC | ADC_REFERENCE_VREF | ADC_CONFIGURE_CHANNEL | ADC_SINGLE_ENDED_INPUT | ADC_SINGLE_SHOT_MODE | ADC_12_BIT_MODE | ADC_SW_TRIGGERED);
adc_setup.int_adc_sample = (ADC_SAMPLE_LONG_PLUS_12 | ADC_SAMPLE_AVERAGING_32);
fnConfigureInterrupt((void *)&adc_setup);
It uses an interrupt and when the conversion is complete I checked the value with a debug message to verify the operation was correct across the voltage range (12 bit mode)
ADC triggered: 0x0fff
ADC triggered: 0x0d54
ADC triggered: 0x0b30
ADC triggered: 0x0932
ADC triggered: 0x0724
ADC triggered: 0x0509
ADC triggered: 0x0307
ADC triggered: 0x0153
ADC triggered: 0x0000
So that you can check the ADC interaction, this is the low level code that this controls:
KINETIS_ADC_REGS *ptrADC = (KINETIS_ADC_REGS *)ADC0_BLOCK;
POWER_UP_ATOMIC(6, ADC0);
ptrADC->ADC_CFG1 = (ADC_CLOCK_DIVIDE_8 | ADC_SAMPLE_ACTIVATE_LONG | ADC_12_BIT_MODE | ADC_CLOCK_BUS_DIV_2);
ptrADC->ADC_CFG2 = (ADC_CFG2_MUXSEL_B | ADC_SAMPLE_LONG_PLUS_12);
_CONFIG_PERIPHERAL(D, 5, PD_5_ADC0_SE6b);
ptrADC->ADC_SC2 = ADC_REFERENCE_VREF;
ptrADC->ADC_SC3 = ADC_SAMPLE_AVERAGING_32;
ptrADC->ADC_SC1A = (ADC_SC1A_AIEN | ADC_SC1A_ADCH_6);
result = ptrADC->ADC_RA;
I have shown the HEX values written to the registers and note the following:
1) You should preform ADC calibration before first use
2) Although the pin PTD5 default to its ADC0_SE6b function it is good practice to ensure that it is correct - and power up the PTD port.
3) Although I don't see all your ADC initialisation details setting BIT4 of ADC0_CFG2 is what selects the b input, so that looks correct.
4) As a test, I selected a input on SE6a - and the result was then always 0x0fff (presumably the unavailable SE6 a input is connected internally to VDD).
With these details you may be able to identify your issue.
Regards
Mark
You can also download the uTasker project from its open source reference on GitHub for check the coding details from above and simulate the KL27 in Visual Studio.
Short video attached of testing/verifying the ADC input.