2020-04-07 04:42 AM
HI I USED STM32F303RC ADC1 ADC2 ADC3 ADC4 ONLY PROBLEM ADC 3 USED ADC3_CH1 FOR REQULAR AND CH3 FOR INJECT BOU INJECT READ IS WRONG
FOR TEST CHANGE REQULAR TO CH5 AND INJECT TO CH5 AGAIN REGULAR READ CORECT BOUT INJECT READ WRONG
THIS MY CONFIG ADC
__weak void MX_ADC3_Init(void)
{
ADC_HandleTypeDef hadc3 = {0};
/* USER CODE BEGIN ADC3_Init 0 */
__HAL_RCC_ADC34_CLK_ENABLE();
ADC3_io_config();
/* USER CODE END ADC3_Init 0 */
ADC_MultiModeTypeDef multimode = {0};
ADC_InjectionConfTypeDef sConfigInjected = {0};
ADC_ChannelConfTypeDef sConfig = {0};
/** Common config **/
hadc3.Instance = ADC3;
hadc3.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
hadc3.Init.Resolution = ADC_RESOLUTION_12B;
hadc3.Init.ScanConvMode = ADC_SCAN_ENABLE;
hadc3.Init.ContinuousConvMode = DISABLE;
hadc3.Init.DiscontinuousConvMode = DISABLE;
hadc3.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc3.Init.NbrOfConversion = 1;
hadc3.Init.DMAContinuousRequests = DISABLE;
hadc3.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc3.Init.LowPowerAutoWait = DISABLE;
hadc3.Init.Overrun = ADC_OVR_DATA_PRESERVED;
if (HAL_ADC_Init(&hadc3) != HAL_OK)
{
Error_Handler();
}
/* CALIBRATION ADC1 */
if (HAL_ADCEx_Calibration_Start(&hadc3, ADC_SINGLE_ENDED) != HAL_OK)
{
Error_Handler();
}
/** Configure the ADC multi-mode **/
multimode.Mode = ADC_MODE_INDEPENDENT;
if (HAL_ADCEx_MultiModeConfigChannel(&hadc3, &multimode) != HAL_OK)
{
Error_Handler();
}
sConfig.Channel = ADC_CHANNEL_5; // CHANEL ADC POT MUST SET WITH HAND CHANEL 1
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.SamplingTime = ADC_SAMPLETIME_19CYCLES_5;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
{
Error_Handler();
}
/** Configure Injected Channel **/
sConfigInjected.InjectedChannel = ADC_CHANNEL_5; // CHANEL COS ENCODER INPUT MUST SET WITH HAND
sConfigInjected.InjectedRank = ADC_INJECTED_RANK_1;
sConfigInjected.InjectedSingleDiff = ADC_SINGLE_ENDED;
sConfigInjected.InjectedNbrOfConversion = 1;
sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_7CYCLES_5;
sConfigInjected.ExternalTrigInjecConvEdge = ADC_EXTERNALTRIGINJECCONV_EDGE_RISING;
sConfigInjected.ExternalTrigInjecConv = ADC_EXTERNALTRIGINJECCONV_T1_TRGO;
sConfigInjected.AutoInjectedConv = DISABLE;
sConfigInjected.InjectedDiscontinuousConvMode = DISABLE;
sConfigInjected.QueueInjectedContext = DISABLE;
sConfigInjected.InjectedOffset = 0;
sConfigInjected.InjectedOffsetNumber = ADC_OFFSET_NONE;
if (HAL_ADCEx_InjectedConfigChannel(&hadc3, &sConfigInjected) != HAL_OK)
{
Error_Handler();
}
}
I USED TO OTHER ADC WORK WITHOUT PROBLEM
2020-04-07 04:43 AM
SORRY I MISTAKE WRITE CH3 I USED INJECT ON CH5