2024-08-31 03:08 AM - last edited on 2024-09-02 02:52 AM by SofLit
Hi,The version of mcsdk I'm using is 6.3.0, I have a problem with my ADC2, enabling one injection channel as a sample of phase current, and three regular channels, one of which is used as a speedpotentiometer, and two for my own use, and currently running the code keeps waiting for the EOC flag bit at LL_ADC_IsActiveFlag_EOC in RCM_ExecRegularConv(), below is my code:
#include "mc_type.h"
#include "mc_app_hooks.h"
#include "mc_config.h"
#include "speed_potentiometer.h"
#include "regular_conversion_manager.h"
RegConv_t ADC_UserIbusConv;
RegConv_t ADC_UserThreeSpeedConv;
uint16_t Ibus = 0;
uint16_t TS = 0;
uint8_t IbusHandle = 0;
uint8_t TSHandle = 0;
__weak void MC_APP_BootHook(void)
{
(void)RCM_RegisterRegConv(&PotRegConv_M1);
SPDPOT_Init(&SpeedPotentiometer_M1);
ADC_UserIbusConv.regADC = ADC2;
ADC_UserIbusConv.channel = ADC_CHANNEL_2;
ADC_UserIbusConv.samplingTime = ADC_SAMPLETIME_19CYCLES_5;
ADC_UserIbusConv.convHandle = IbusHandle;
RCM_RegisterRegConv(&ADC_UserIbusConv);
ADC_UserThreeSpeedConv.regADC = ADC2;
ADC_UserThreeSpeedConv.channel = ADC_CHANNEL_11;
ADC_UserThreeSpeedConv.samplingTime = ADC_SAMPLETIME_19CYCLES_5;
ADC_UserThreeSpeedConv.convHandle = TSHandle;
RCM_RegisterRegConv(&ADC_UserThreeSpeedConv);
}
__weak void MC_APP_PostMediumFrequencyHook_M1(void)
{
if(RCM_GetUserConvState() == RCM_USERCONV_IDLE)
{
RCM_RequestUserConv(&ADC_UserIbusConv);
}
else if(RCM_GetUserConvState() == RCM_USERCONV_EOC)
{
Ibus = RCM_GetUserConv();
}
if(RCM_GetUserConvState() == RCM_USERCONV_IDLE)
{
RCM_RequestUserConv(&ADC_UserThreeSpeedConv);
}
else if(RCM_GetUserConvState() == RCM_USERCONV_EOC)
{
TS = RCM_GetUserConv();
}
}
static void MX_ADC2_Init(void)
{
/* USER CODE BEGIN ADC2_Init 0 */
/* USER CODE END ADC2_Init 0 */
ADC_InjectionConfTypeDef sConfigInjected = {0};
ADC_ChannelConfTypeDef sConfig = {0};
/* USER CODE BEGIN ADC2_Init 1 */
/* USER CODE END ADC2_Init 1 */
/** Common config
*/
hadc2.Instance = ADC2;
hadc2.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV1;
hadc2.Init.Resolution = ADC_RESOLUTION_12B;
hadc2.Init.ScanConvMode = ADC_SCAN_ENABLE;
hadc2.Init.ContinuousConvMode = DISABLE;
hadc2.Init.DiscontinuousConvMode = DISABLE;//DISABLE
hadc2.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc2.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc2.Init.DataAlign = ADC_DATAALIGN_LEFT;
hadc2.Init.NbrOfConversion = 3;
hadc2.Init.DMAContinuousRequests = DISABLE;
hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc2.Init.LowPowerAutoWait = DISABLE;
hadc2.Init.Overrun = ADC_OVR_DATA_PRESERVED;
if (HAL_ADC_Init(&hadc2) != HAL_OK)
{
Error_Handler();
}
/** Configure Injected Channel
*/
sConfigInjected.InjectedChannel = ADC_CHANNEL_9;
sConfigInjected.InjectedRank = ADC_INJECTED_RANK_1;
sConfigInjected.InjectedSingleDiff = ADC_SINGLE_ENDED;
sConfigInjected.InjectedNbrOfConversion = 1;
sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_19CYCLES_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(&hadc2, &sConfigInjected) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_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(&hadc2, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC2_Init 2 */
sConfig.Channel = ADC_CHANNEL_1;
sConfig.Rank = ADC_REGULAR_RANK_2;
sConfig.SamplingTime = ADC_SAMPLETIME_7CYCLES_5;
if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
{
Error_Handler();
}
sConfig.Channel = ADC_CHANNEL_11;
sConfig.Rank = ADC_REGULAR_RANK_3;
sConfig.SamplingTime = ADC_SAMPLETIME_19CYCLES_5;
if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE END ADC2_Init 2 */
}
,