2023-11-27 08:43 AM
I have programmed STMG030k8T6 MCU in a prototype
Channels used ADC_IN_0 as T_sense ADC_IN_15 AS BattMon
if I am calling any one of the function I am getting exact values what i measure in hardware
But if i called them both only reading values from CH 0 please help me to sort it out stuck for a long in this
Note:When i used conversion with DMA ,also getting the same issues
Reading channel_0
reading channel_15
but when read both
Already I have tried maximum of suggestions by the people but still struggling to get the solution
void Get_Tsense(void)
{
ADC_ChannelConfTypeDef sConfig = {0};
sConfig.Channel = ADC_CHANNEL_0;
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_1;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1, 1000);
Tsense_raw=HAL_ADC_GetValue(&hadc1);
Tsense=(Tsense_raw*3.3)/4095;
HAL_ADC_Stop(&hadc1);
HAL_Delay(100);
}
void Get_Batmon(void)
{
ADC_ChannelConfTypeDef sConfig = {0};
sConfig.Channel = ADC_CHANNEL_15;
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_1;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1, 1000);
Batmon_raw=HAL_ADC_GetValue(&hadc1);
Batmon=(Batmon_raw*3.3)/4095;
HAL_ADC_Stop(&hadc1);
HAL_Delay(100);
}
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_ADC1_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
Get_Tsense();
Get_Batmon();
}
/* USER CODE END 3 */
}
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV2;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.ScanConvMode = ADC_SCAN_SEQ_FIXED;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc1.Init.LowPowerAutoWait = DISABLE;
hadc1.Init.LowPowerAutoPowerOff = DISABLE;
hadc1.Init.ContinuousConvMode = ENABLE;
hadc1.Init.NbrOfConversion = 2;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
hadc1.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_160CYCLES_5;
hadc1.Init.OversamplingMode = DISABLE;
hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_0;
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_15;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
}
/**
.Please
Solved! Go to Solution.
2023-11-28 07:06 PM
When you configure the second ADC channel, the settings from the first channel are already in there.
In the previous thread, I suggested checking the ADC_CHSELR. Did you do so? What is the value of this register in each of the three cases? Use that info to guide the solution.
If that doesn't solve it, print out the ADC register values in all three cases just prior to the HAL_ADC_Start call and someone will surely spot the issue.
Three cases are:
2023-11-28 07:06 PM
When you configure the second ADC channel, the settings from the first channel are already in there.
In the previous thread, I suggested checking the ADC_CHSELR. Did you do so? What is the value of this register in each of the three cases? Use that info to guide the solution.
If that doesn't solve it, print out the ADC register values in all three cases just prior to the HAL_ADC_Start call and someone will surely spot the issue.
Three cases are:
2023-11-29 01:17 AM
I solved by setting ADC_CHSELR Thank you so much for the help.