Error on the ADC Values of a Multichannel ADC
Hi All,
I am presently measuring the two signals below through a multichannel adc that is triggered by the rising edge of a PWM signal on TIM1 CH4.
a. Inverter return line current on channel 3
b. Speed reference value from a potentiometer.
I am quite sure, I am reading the right adc channel, but the problem is that the adc value for the current seems to be corrupted and it jitters too much from the correct value.
Below is the configuration code for the ADC
static void MX_ADC_Init(void)
{
/* USER CODE BEGIN ADC_Init 0 */
/* USER CODE END ADC_Init 0 */
ADC_ChannelConfTypeDef sConfig = {0};
/* USER CODE BEGIN ADC_Init 1 */
/* USER CODE END ADC_Init 1 */
/** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
*/
hadc.Instance = ADC1;
hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
hadc.Init.Resolution = ADC_RESOLUTION_12B;
hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc.Init.LowPowerAutoWait = DISABLE;
hadc.Init.LowPowerAutoPowerOff = DISABLE;
hadc.Init.ContinuousConvMode = DISABLE;
hadc.Init.DiscontinuousConvMode = DISABLE;
hadc.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_TRGO;
hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
hadc.Init.DMAContinuousRequests = DISABLE;
hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED;
if (HAL_ADC_Init(&hadc) != HAL_OK)
{
Error_Handler();
}
/** Configure for the selected ADC regular channel to be converted.
*/
sConfig.Channel = ADC_CHANNEL_5;
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
sConfig.SamplingTime = ADC_SAMPLETIME_13CYCLES_5;
if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
{
Error_Handler();
}
/** Configure for the selected ADC regular channel to be converted.
*/
sConfig.Channel = ADC_CHANNEL_3;
if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
{
Error_Handler();
}
// /** Configure for the selected ADC regular channel to be converted.
// */
// sConfig.Channel = ADC_CHANNEL_8;
// if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
// {
// Error_Handler();
// }
// /** Configure for the selected ADC regular channel to be converted.
// */
// sConfig.Channel = ADC_CHANNEL_9;
// if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
// {
// Error_Handler();
// }
// /** Configure for the selected ADC regular channel to be converted.
// */
// sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;
// if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
// {
// Error_Handler();
// }
// /** Configure for the selected ADC regular channel to be converted.
// */
// sConfig.Channel = ADC_CHANNEL_VREFINT;
// if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
// {
// Error_Handler();
// }
/* USER CODE BEGIN ADC_Init 2 */
/* USER CODE END ADC_Init 2 */
}Also, since the application -- a bldc trapezoidal current and speed control -- I am running is kinda complex. The ADC is calibrated and started at other parts of the code.
But the main problem i think is the fact that the adc values get corrupted. I wrote another code the see the right ADC value that matches the inverter DC line current and it was totally different from what I get when I run my bldc control application.
What could possible be wrong?