Hi Myke --
Well, I hope that BOARD_InitBootPeripherals() is setting the ADCs correctly, but the lack of any meaningful changes in the output, even when the input changes from ground to 3.3V might mean something rather basic is wrong. Since my last message, I have changed the resolution to 8 bits, and dropped all the hardware averaging, and multiple sampling. It didn't make any difference. I don't have this chip on a Tower or Freedom board, but I do have a K64 on both Tower and Freedom boards. I will give that a try.
"Bandgap" is channel 27 on each ADC. There was a reading for the second test, but I ignored it because it was the same as the first. I shouldn't have been so lazy. The actual output looks like this:
ADC0 pin 53 = 252 ADC0 bandgap = 6 ADC1 pin 26 = 6 ADC1 bandgap = 6
ADC0 pin 53 = 252 ADC0 bandgap = 6 ADC1 pin 26 = 6 ADC1 bandgap = 6
ADC0 pin 53 = 252 ADC0 bandgap = 6 ADC1 pin 26 = 6 ADC1 bandgap = 6
ADC0 pin 53 = 252 ADC0 bandgap = 6 ADC1 pin 26 = 6 ADC1 bandgap = 6
ADC0 pin 53 = 251 ADC0 bandgap = 6 ADC1 pin 26 = 6 ADC1 bandgap = 6
In the above sample, ADC1 (pin26) measures 1.677V, and ADC0 (pin 53) measures 0.754V. I didn't do anything to get the summary value, this is just the decimal value returned by ADC16_GetChannelConversionValue().
My setup is that I have two, AA batteries in series, with a 10K, ten turn pot across the terminals, with the wiper of the pot going to the processor's pin 26 (should be ADC1, SE18, and two more AA batteries tied to a different 10K, ten turn pot tied to the processor's pin 53, which should be ADC0, SE8. The negative side of the "lower" battery in each of the pairs is tied to system ground. Board power is from yet another pair of AA batteries.
Here are the contents of board.c:
/***********************************************************************************************************************
* BOARD_InitPeripherals functional group
**********************************************************************************************************************/
/***********************************************************************************************************************
* ADC0 initialization code
**********************************************************************************************************************/
/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
instance:
- name: 'ADC0'
- type: 'adc16'
- mode: 'ADC'
- custom_name_enabled: 'false'
- type_id: 'adc16_7d827be2dc433dc756d94a7ce88cbcc5'
- functional_group: 'BOARD_InitPeripherals'
- peripheral: 'ADC0'
- config_sets:
- fsl_adc16:
- adc16_config:
- referenceVoltageSource: 'kADC16_ReferenceVoltageSourceVref'
- clockSource: 'kADC16_ClockSourceAsynchronousClock'
- enableAsynchronousClock: 'true'
- clockDivider: 'kADC16_ClockDivider8'
- resolution: 'kADC16_ResolutionSE8Bit'
- longSampleMode: 'kADC16_LongSampleDisabled'
- enableHighSpeed: 'false'
- enableLowPower: 'false'
- enableContinuousConversion: 'false'
- adc16_channel_mux_mode: 'kADC16_ChannelMuxA'
- adc16_hardware_compare_config:
- hardwareCompareModeEnable: 'false'
- doAutoCalibration: 'false'
- offset: '0'
- trigger: 'false'
- hardwareAverageConfiguration: 'kADC16_HardwareAverageDisabled'
- adc16_pga_config:
- adc16PgaEnable: 'false'
- enable_dma: 'false'
- enable_irq: 'false'
- adc_interrupt:
- IRQn: 'ADC0_IRQn'
- enable_priority: 'false'
- priority: '0'
- enable_custom_name: 'false'
- adc16_channels_config:
- 0:
- enableDifferentialConversion: 'false'
- channelNumber: 'SE.1'
- enableInterruptOnConversionCompleted: 'false'
- channelGroup: '0'
- initializeChannel: 'false'
- 1:
- enableDifferentialConversion: 'false'
- channelNumber: 'SE.27'
- enableInterruptOnConversionCompleted: 'false'
- channelGroup: '0'
- initializeChannel: 'false'
* BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */
adc16_channel_config_t ADC0_channelsConfig[2] = {
{
.channelNumber = 1U,
.enableDifferentialConversion = false,
.enableInterruptOnConversionCompleted = false,
},
{
.channelNumber = 27U,
.enableDifferentialConversion = false,
.enableInterruptOnConversionCompleted = false,
}
};
const adc16_config_t ADC0_config = {
.referenceVoltageSource = kADC16_ReferenceVoltageSourceVref,
.clockSource = kADC16_ClockSourceAsynchronousClock,
.enableAsynchronousClock = true,
.clockDivider = kADC16_ClockDivider8,
.resolution = kADC16_ResolutionSE8Bit,
.longSampleMode = kADC16_LongSampleDisabled,
.enableHighSpeed = false,
.enableLowPower = false,
.enableContinuousConversion = false
};
const adc16_channel_mux_mode_t ADC0_muxMode = kADC16_ChannelMuxA;
const adc16_hardware_average_mode_t ADC0_hardwareAverageMode = kADC16_HardwareAverageDisabled;
void ADC0_init(void) {
/* Initialize ADC16 converter */
ADC16_Init(ADC0_PERIPHERAL, &ADC0_config);
/* Make sure, that software trigger is used */
ADC16_EnableHardwareTrigger(ADC0_PERIPHERAL, false);
/* Configure hardware average mode */
ADC16_SetHardwareAverage(ADC0_PERIPHERAL, ADC0_hardwareAverageMode);
/* Configure channel multiplexing mode */
ADC16_SetChannelMuxMode(ADC0_PERIPHERAL, ADC0_muxMode);
}
/***********************************************************************************************************************
* ADC1 initialization code
**********************************************************************************************************************/
/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
instance:
- name: 'ADC1'
- type: 'adc16'
- mode: 'ADC'
- custom_name_enabled: 'false'
- type_id: 'adc16_7d827be2dc433dc756d94a7ce88cbcc5'
- functional_group: 'BOARD_InitPeripherals'
- peripheral: 'ADC1'
- config_sets:
- fsl_adc16:
- adc16_config:
- referenceVoltageSource: 'kADC16_ReferenceVoltageSourceVref'
- clockSource: 'kADC16_ClockSourceAlt1'
- enableAsynchronousClock: 'true'
- clockDivider: 'kADC16_ClockDivider8'
- resolution: 'kADC16_ResolutionSE8Bit'
- longSampleMode: 'kADC16_LongSampleDisabled'
- enableHighSpeed: 'false'
- enableLowPower: 'false'
- enableContinuousConversion: 'false'
- adc16_channel_mux_mode: 'kADC16_ChannelMuxA'
- adc16_hardware_compare_config:
- hardwareCompareModeEnable: 'false'
- doAutoCalibration: 'false'
- offset: '0'
- trigger: 'false'
- hardwareAverageConfiguration: 'kADC16_HardwareAverageDisabled'
- adc16_pga_config:
- adc16PgaEnable: 'false'
- enable_dma: 'false'
- enable_irq: 'false'
- adc_interrupt:
- IRQn: 'ADC1_IRQn'
- enable_priority: 'false'
- priority: '0'
- enable_custom_name: 'false'
- adc16_channels_config:
- 0:
- enableDifferentialConversion: 'false'
- channelNumber: 'SE.4a'
- enableInterruptOnConversionCompleted: 'false'
- channelGroup: '0'
- initializeChannel: 'false'
- 1:
- enableDifferentialConversion: 'false'
- channelNumber: 'SE.27'
- enableInterruptOnConversionCompleted: 'false'
- channelGroup: '0'
- initializeChannel: 'false'
* BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */
adc16_channel_config_t ADC1_channelsConfig[2] = {
{
.channelNumber = 4U,
.enableDifferentialConversion = false,
.enableInterruptOnConversionCompleted = false,
},
{
.channelNumber = 27U,
.enableDifferentialConversion = false,
.enableInterruptOnConversionCompleted = false,
}
};
const adc16_config_t ADC1_config = {
.referenceVoltageSource = kADC16_ReferenceVoltageSourceVref,
.clockSource = kADC16_ClockSourceAlt1,
.enableAsynchronousClock = true,
.clockDivider = kADC16_ClockDivider8,
.resolution = kADC16_ResolutionSE8Bit,
.longSampleMode = kADC16_LongSampleDisabled,
.enableHighSpeed = false,
.enableLowPower = false,
.enableContinuousConversion = false
};
const adc16_channel_mux_mode_t ADC1_muxMode = kADC16_ChannelMuxA;
const adc16_hardware_average_mode_t ADC1_hardwareAverageMode = kADC16_HardwareAverageDisabled;
void ADC1_init(void) {
/* Initialize ADC16 converter */
ADC16_Init(ADC1_PERIPHERAL, &ADC1_config);
/* Make sure, that software trigger is used */
ADC16_EnableHardwareTrigger(ADC1_PERIPHERAL, false);
/* Configure hardware average mode */
ADC16_SetHardwareAverage(ADC1_PERIPHERAL, ADC1_hardwareAverageMode);
/* Configure channel multiplexing mode */
ADC16_SetChannelMuxMode(ADC1_PERIPHERAL, ADC1_muxMode);
}
/***********************************************************************************************************************
* Initialization functions
**********************************************************************************************************************/
void BOARD_InitPeripherals(void)
{
/* Initialize components */
ADC0_init();
ADC1_init();
}
/***********************************************************************************************************************
* BOARD_InitBootPeripherals function
**********************************************************************************************************************/
void BOARD_InitBootPeripherals(void)
{
BOARD_InitPeripherals();
}
And for good measure, pin_mux.c
void BOARD_InitBootPins(void)
{
BOARD_InitPins();
}
/* clang-format off */
/*
* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
BOARD_InitPins:
- options: {callFromInitBoot: 'true', coreID: core0, enableClock: 'true'}
- pin_list:
- {pin_num: '26', peripheral: ADC1, signal: 'SE, 18', pin_signal: VREF_OUT/CMP1_IN5/CMP0_IN5/ADC1_SE18}
- {pin_num: '53', peripheral: ADC0, signal: 'SE, 8', pin_signal: ADC0_SE8/ADC1_SE8/TSI0_CH0/PTB0/LLWU_P5/I2C0_SCL/FTM1_CH0/RMII0_MDIO/MII0_MDIO/FTM1_QD_PHA}
- {pin_num: '100', peripheral: GPIOD, signal: 'GPIO, 7', pin_signal: PTD7/CMT_IRO/UART0_TX/FTM0_CH7/FTM0_FLT1}
* BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS ***********
*/
/* clang-format on */
/* FUNCTION ************************************************************************************************************
*
* Function Name : BOARD_InitPins
* Description : Configures pin routing and optionally pin electrical features.
*
* END ****************************************************************************************************************/
void BOARD_InitPins(void)
{
/* Port B Clock Gate Control: Clock enabled */
CLOCK_EnableClock(kCLOCK_PortB);
/* Port D Clock Gate Control: Clock enabled */
CLOCK_EnableClock(kCLOCK_PortD);
/* PORTB0 (pin 53) is configured as ADC0_SE8 */
PORT_SetPinMux(PORTB, 0U, kPORT_PinDisabledOrAnalog);
/* PORTD7 (pin 100) is configured as PTD7 */
PORT_SetPinMux(PORTD, 7U, kPORT_MuxAsGpio);
}