2025-10-13 8:00 AM - last edited on 2025-10-13 8:30 AM by mƎALLEm
Post edited by ST moderator to be inline with the community rules especially with the code sharing. In next time please use </> button to paste your code. Please read this post: How to insert source code
In STM32C092 board, when I configured in ioc file for ADC, with scan conversion mode and:
- enable analog channel 0 only, it is able to measure the analog channel 0 correctly.
- enable analog channel 1 only, it is unable to measure the analog channel 1 correctly.
- enable analog channels 0 & 1, it is able to measure the analog channel 0 correctly but channel 1 is mirroring the value of channel 0, instead of giving an independent value on changing voltages.
I tried:
- ranking ADC sequence manually, since in ioc file, it doesn't give options for ranking.
- verified the GPIO settings for analog function.
- increased sampling time for channel 1.
- gave sampling time for channel0 as 1.5 cycles and for channel1 as 160.5 cycles.
Am I doing something wrong here?
The IOC default code generation is as below:
static void MX_ADC1_Init(void)
{
ADC_ChannelConfTypeDef sConfig = {0};
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
hadc1.Init.Resolution = ADC_RESOLUTION_10B;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.ScanConvMode = ADC_SCAN_SEQ_FIXED;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc1.Init.LowPowerAutoWait = DISABLE;
hadc1.Init.LowPowerAutoPowerOff = DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc1.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_1CYCLE_5;
hadc1.Init.OversamplingMode = DISABLE;
hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
sConfig.Channel = ADC_CHANNEL_0;
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
sConfig.Channel = ADC_CHANNEL_1;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
}
In this code I changed the number of conversions to 2 manually (since in ioc, provision wasn't there)
and also tried making different functions to set rank and start reading adc each time.
2025-10-13 8:32 AM
> enable analog channel 1 only, it is unable to measure the analog channel 1 correctly.
How "unable"?
What are the signal sources? Isn't channel 1 source's impedance too high?
> hadc1.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_1CYCLE_5;
Try increasing substantially.
JW