2024-09-10 05:37 AM
Hi,
i have a custom design with a STSPIN32G4 SoC. However, I think my question does refer to the internal microcontroller (STM32G431VBTx) and not the motor controller.
Do you have any ideas what can cause this issue?
I initialize the OPV with CubeMX generated Code:
hopamp3.Instance = OPAMP3;
hopamp3.Init.PowerMode = OPAMP_POWERMODE_NORMALSPEED;
hopamp3.Init.Mode = OPAMP_PGA_MODE;
hopamp3.Init.NonInvertingInput = OPAMP_NONINVERTINGINPUT_IO0;
hopamp3.Init.InternalOutput = ENABLE;
hopamp3.Init.TimerControlledMuxmode = OPAMP_TIMERCONTROLLEDMUXMODE_DISABLE;
hopamp3.Init.PgaConnect = OPAMP_PGA_CONNECT_INVERTINGINPUT_NO;
hopamp3.Init.PgaGain = OPAMP_PGA_GAIN_32_OR_MINUS_31;
hopamp3.Init.UserTrimming = OPAMP_TRIMMING_FACTORY;
if (HAL_OPAMP_Init(&hopamp3) != HAL_OK)
{
Error_Handler();
}
hadc2.Instance = ADC2;
hadc2.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
hadc2.Init.Resolution = ADC_RESOLUTION_12B;
hadc2.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc2.Init.GainCompensation = 0;
hadc2.Init.ScanConvMode = ADC_SCAN_ENABLE;
hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc2.Init.LowPowerAutoWait = DISABLE;
hadc2.Init.ContinuousConvMode = ENABLE;
hadc2.Init.NbrOfConversion = 4;
hadc2.Init.DiscontinuousConvMode = DISABLE;
hadc2.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc2.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc2.Init.DMAContinuousRequests = DISABLE;
hadc2.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc2.Init.OversamplingMode = DISABLE;
if (HAL_ADC_Init(&hadc2) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_3;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_640CYCLES_5;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_4;
sConfig.Rank = ADC_REGULAR_RANK_2;
if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_8;
sConfig.Rank = ADC_REGULAR_RANK_3;
if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
{
Error_Handler();
}
HAL_OPAMP_SelfCalibrate(&hopamp3);
HAL_OPAMP_Start(&hopamp3);
HAL_ADCEx_Calibration_Start(&hadc2, ADC_SINGLE_ENDED);
// Retriggered in TIM3 Callback
HAL_ADC_Start_DMA(&hadc2, (uint32_t*)&adc_buffer, 4);
2024-09-10 06:10 AM
"The adc reads a voltage of 450 mV."
Is input+ connected to anything?
You can configure external GPIO pin as OPA output (connected to both, GPIO and internal ADC) and verify voltage with voltmeter if there 450mV
2024-09-10 06:34 AM
Thank you for your fast response. OPAMP3_INP is my input signal, which is 0 Volt (measured). Unfortunately my design has no connection to the output pin of OPAMP3. However, I was able to contact the pin directly with a needle. I measured a voltage of 3.6 mV at the output pin of OPAMP3, which is within the range of what is possible.
So the error must be from a wrong configuration of the adc.? What can be the reason?
Best regards.
2024-09-10 07:02 AM
I don't see this part in code:
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_VOPAMP3_ADC2;
sConfig.Rank = ADC_REGULAR_RANK_4;
if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
{
Error_Handler();
}