2020-10-09 06:06 AM
Dear members,
I am using the NUCLEO-F303RE and X-NUCLEO-IHM08M1 boards. I have created a position control project which seems to work fine. At this stage I would like to introduce an ADC conversion, however I am able to request an ADC conversion but this never completes.
Below is the code I have. Did anyone have a similar issue?
RegConv_t PotentiometerConv;
uint8_t PotentiometerHandle;
void PotentiometerInitialise (void)
{
PotentiometerConv.regADC = ADC1;
PotentiometerConv.channel = ADC_CHANNEL_9;
PotentiometerConv.samplingTime = ADC_SAMPLETIME_61CYCLES_5;
PotentiometerHandle = RCM_RegisterRegConv(&PotentiometerConv);
}
if(RCM_GetUserConvState() == RCM_USERCONV_IDLE) /*if Idle, then program a new conversion request*/
RCM_RequestUserConv(PotentiometerHandle);
if (RCM_GetUserConvState() == RCM_USERCONV_EOC) //if conversion is ready to be read
{
pot = RCM_GetUserConv(); //this returns the ADC value (the returned value is between [0 and 65535] where the max value equivals to 3,3V)
if ((pot>=low_ref) && (pot<=high_ref)) //this means 1.65V +- tollerance
MC_ProgramPositionCommandMotor1(0,0);
//stop_motor();
else if (pot>high_ref) //values above 1.67V
rotate_clockwise();
else if (pot<low_ref) //values below 1.646V
rotate_anticlock();
else
MC_StopMotor1();
}
Solved! Go to Solution.
2020-10-21 08:19 AM
@msingh i am able to read the ADC values using the APIs
If you have initialised the ADC properly it should work ,
/* init of ADC3 used */
static void MX_ADC3_Init(void)
{
/* USER CODE BEGIN ADC3_Init 0 */
/* USER CODE END ADC3_Init 0 */
ADC_MultiModeTypeDef multimode = {0};
ADC_ChannelConfTypeDef sConfig = {0};
/* USER CODE BEGIN ADC3_Init 1 */
/* USER CODE END ADC3_Init 1 */
/** Common config
*/
hadc3.Instance = ADC3;
hadc3.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV1;
hadc3.Init.Resolution = ADC_RESOLUTION_12B;
hadc3.Init.ScanConvMode = ADC_SCAN_ENABLE;
hadc3.Init.ContinuousConvMode = DISABLE;
hadc3.Init.DiscontinuousConvMode = DISABLE;
hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START;
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_OVERWRITTEN;
if (HAL_ADC_Init(&hadc3) != HAL_OK)
{
Error_Handler();
}
/** Configure the ADC multi-mode
*/
multimode.Mode = ADC_MODE_INDEPENDENT;
if (HAL_ADCEx_MultiModeConfigChannel(&hadc3, &multimode) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_12;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
{
Error_Handler();
}
}
/* Reading Values */
if (RCM_GetUserConvState() == RCM_USERCONV_IDLE)
{
/* if Idle, then program a new conversion request */
RCM_RequestUserConv(calcAdcSpeed );
}
else if (RCM_GetUserConvState() == RCM_USERCONV_EOC)
{
/* if Done, then read the captured value */
adcCapture = RCM_ExecRegularConv(calcAdcSpeed);
}
2020-10-16 01:14 AM
Dear @msingh
Could you give more details to the STM32 Community about the material you use (HW and SW, CPU(s), tools and versions, board(s), motor(s) and so on)?
And more especially did you use MC tools (such as MC_suite, MC-Motor Profile, MC-SDK, MC-workbench, and so on)?
Best regards
Laurent Ca...
2020-10-16 02:47 AM
I was using Atolic TrueStudio and for some reasons it didn't work on that. I have now installed the STM32CubeIDE 1.4.0 and it works fine with that. @Laurent Ca... which documentation explains best the position control method? I have used the AN5464 application note to achieve a working project, however at this stage I would like to vary the position using ADC. ADC conversion returns a sensible value and when I try to use this value to calculate new position the motor stops rotating and starts making noice. Looks like it varies the currents instead of varying the position, since I use the same function I cannot understand why this is happenning. If there is any other documentation you could suggest that'll be useful or if you know how to solve this it would be even better.
To generate the initial project I have used the MC-workbench 5.4.4 then used STM32CUBEMX 5.5.0 to add PC3 as analogue input. The ADC conversion works, BUT when I try using this variable holding ADC value in the "MC_ProgramPositionCommandMotor1" function it simply doesn't work and the motor keeps making noise.
2020-10-21 08:19 AM
@msingh i am able to read the ADC values using the APIs
If you have initialised the ADC properly it should work ,
/* init of ADC3 used */
static void MX_ADC3_Init(void)
{
/* USER CODE BEGIN ADC3_Init 0 */
/* USER CODE END ADC3_Init 0 */
ADC_MultiModeTypeDef multimode = {0};
ADC_ChannelConfTypeDef sConfig = {0};
/* USER CODE BEGIN ADC3_Init 1 */
/* USER CODE END ADC3_Init 1 */
/** Common config
*/
hadc3.Instance = ADC3;
hadc3.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV1;
hadc3.Init.Resolution = ADC_RESOLUTION_12B;
hadc3.Init.ScanConvMode = ADC_SCAN_ENABLE;
hadc3.Init.ContinuousConvMode = DISABLE;
hadc3.Init.DiscontinuousConvMode = DISABLE;
hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START;
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_OVERWRITTEN;
if (HAL_ADC_Init(&hadc3) != HAL_OK)
{
Error_Handler();
}
/** Configure the ADC multi-mode
*/
multimode.Mode = ADC_MODE_INDEPENDENT;
if (HAL_ADCEx_MultiModeConfigChannel(&hadc3, &multimode) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_12;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
{
Error_Handler();
}
}
/* Reading Values */
if (RCM_GetUserConvState() == RCM_USERCONV_IDLE)
{
/* if Idle, then program a new conversion request */
RCM_RequestUserConv(calcAdcSpeed );
}
else if (RCM_GetUserConvState() == RCM_USERCONV_EOC)
{
/* if Done, then read the captured value */
adcCapture = RCM_ExecRegularConv(calcAdcSpeed);
}
2020-10-21 09:09 AM
It actually started working on its own, I simply changed from Atolic IDE to STM32CUBE IDE and it worked. However I have another bigger problem now. The motor stopped working completely. I had made some changed and the motor stopped working. I then went back to the previous version of the code but still doesn't work and I can't understand why?! I have confirmed the hardware works by doing a motor profile using motor profiler 5.4.4 and the motor rotates fine and creates a profile of the motor. How ever the project I had doesn't work any more, neither work if I create a new project from scratch I just don't understand what is going on. Is there anything you can suggest? I was so simply creating a project using AN5464 however now I'm having so much trouble.
Kind Regards
Manpreet Singh
2020-10-21 09:15 AM
@msingh " STM32 Motor Control " it is strange , but try to clean the project and rebuild it. Have you selected the correct binary to flash ?
Have you changed any optimization settings or compiler flags ?
Are you trying using the atollic ide or STM32CUDE IDE now ?
2020-10-21 10:24 AM
Dear @msingh, dear @KKuma.3
According to the rules of the forum for the tag "STM32 Motor Control", please for a new question, use a new thread.
Best regards
Laurent Ca...
2020-10-22 01:15 AM
tried to clean the project and rebuilt it as well didn't help I am using STM32CUBE IDE (also tried with atolice IDE but didn't work). What do you mean with selected correct binary flash? or optimization settings or complier flags? I had changed something in the debugger but placed it back to how it was previously (I think). Anyways let's continue this conversation to the other thread I have so we follow the rules.