cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G431 (STSPIN32G4), OPV High Offset Voltage

oeser
Associate

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.

  • Timer TIM3 does trigger an interrupt every 10 ms.
  • The Interrupt starts a conversion of ADC2, which reads the channels IN3 (single ended), IN4 (signle ended), IN8 (single ended), and VOPAMP3 channel
  • A single conversation should take about 60 µs (ADC_CLK = 170 MHz / 4; 640.5 Cycles per Channel; 4 * 640.5 / 42.5 MHz = 60 µs)
  • VOPAMP3 is configured as PGA Internally Connected with a gain factor of 32.
  • The measured voltages of IN3, IN4, and IN8 are ok.
  • The output voltage of VOPAMP3 is different than expected.
  • According to the datasheet of the microcontroller (5.3.22 Operational amplifiers characteristics) the OPV has
    • an input common mode range from 0 to VDDA
    • a maximum offset Voltage of 3 mV over the entire temperature range
    • the low saturation voltage is at 100 mV
  •  
  • I would expect the maximum measured output voltage to be somewhere around 3 mV * 32 (PGA gain) = 96 mV
  • The adc reads a voltage of 450 mV.

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();
  }

 

 

 

I initialize the ADC with CubeMX generated Code:

 

 

 

  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();
  }

 

 

 

These are the functions I use to read out the adc. Before I do anything with the peripherals I give the MCU 100 ms to settle.

 

 

 

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); ​

 

 

 

Best regards.
3 REPLIES 3
MasterT
Lead

"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

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.

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();
}