2023-12-20 08:17 PM
My attempt to get the ADC value (also not sure if I should be calling to handle &hadc3, but result is the same with no ADC value)
[code]
HAL_Delay(1);
HAL_ADC_Start(&hadc1);
// Poll ADC1 Perihperal & TimeOut = 1mSec
HAL_ADC_PollForConversion(&hadc1, 10);
// Read The ADC Conversion Result & Map It To PWM DutyCycle
AD_RES = HAL_ADC_GetValue(&hadc1);
HAL_ADC_Stop(&hadc1);
[/code]
2023-12-21 09:24 AM
Hello @brian-o,
Thanks for your question !
Here some remark and guidance :
1/ Configure the ADC parameters (resolution, data alignment, ...) and regular group parameters (conversion trigger, sequencer, ...) using function HAL_ADC_Init().
2/ Configure the channels for regular group parameters (channel number, channel rank into sequencer, ..., into regular group) using function HAL_ADC_ConfigChannel().
3/ Also, I advise you to use HAL_ADCEx_Calibration_Start() to perform an automatic ADC calibration.Best Regards,
Pierre
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-12-21 04:29 PM
Thank you Pierre,
the ADC calibration call (when used) enters some failure leading to a WHILE(1) loop in the HAL library, so there is likely a related issue.
ADC initialization code is below from the cube generated content, &hadc1 or 3 handle is declared in my globals:
ADC_HandleTypeDef hadc1;
Initialization code:
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_10B;
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_SOFTWARE_START;
hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
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_3;
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC_Init 2 */
/* USER CODE END ADC_Init 2 */
}
2023-12-22 01:19 AM - edited 2023-12-22 01:20 AM
Hello @brian-o ,
Thank you for sharing your code ! For your information, there's a button for a better code display, don't hesitate to use it next time (you can check the picture below) :)
Regarding the issue :
Best Regards,
Pierre
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.