cancel
Showing results for 
Search instead for 
Did you mean: 

ADC just giving raw value of 4095 on all channels

harshpanchal_6
Associate III

Hello Community,

I’m working on a custom board using the STM32G474VET3 MCU and encountering an issue with the ADC readings. I’m consistently getting a raw value of 4095 on all the ADC channels I’m using. It seems like something might be misconfigured, but I haven’t been able to pinpoint the cause.

Any insights or suggestions would be greatly appreciated.

Thank you!

25 REPLIES 25
Ozone
Principal

On a related note, I remember a similiar issue with the PCF8591 IC, an (older) I2C extender IC with ADC channels.
When the input voltage at one single ADC pin on this IC exceeded Vref, all the ADC channels returned max. value.

Not sure if this applies to this case, but analog MCU inputs are not 5V tolerant. And discharge currents through protective diodes on such inputs definitely affect ADC operation.

ADC3_1.PNG

ADC3_2.PNG

ADC3_3.PNG

ADC_sch.PNG

  

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_DIV2;
  hadc3.Init.Resolution = ADC_RESOLUTION_12B;
  hadc3.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc3.Init.GainCompensation = 0;
  hadc3.Init.ScanConvMode = ADC_SCAN_ENABLE;
  hadc3.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  hadc3.Init.LowPowerAutoWait = DISABLE;
  hadc3.Init.ContinuousConvMode = DISABLE;
  hadc3.Init.NbrOfConversion = 1;
  hadc3.Init.DiscontinuousConvMode = DISABLE;
  hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  hadc3.Init.DMAContinuousRequests = DISABLE;
  hadc3.Init.Overrun = ADC_OVR_DATA_PRESERVED;
  hadc3.Init.OversamplingMode = DISABLE;
  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_10;
  sConfig.Rank = ADC_REGULAR_RANK_1;
  sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
  sConfig.SingleDiff = ADC_SINGLE_ENDED;
  sConfig.OffsetNumber = ADC_OFFSET_NONE;
  sConfig.Offset = 0;
  if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN ADC3_Init 2 */

  /* USER CODE END ADC3_Init 2 */

}

It may cause because of ADC line length on board ?

You still haven't shown a schematic with the stm32 !

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

ADC_sch.PNG

 

  

uint16_t Read_ADC_Raw_Debug()
{
    uint16_t val = 0;

    HAL_ADC_Start(&hadc3);

    if (HAL_ADC_PollForConversion(&hadc3, HAL_MAX_DELAY) == HAL_OK)
    {
        val = HAL_ADC_GetValue(&hadc3);
    }

    HAL_ADC_Stop(&hadc3);

    // Optional: print value over UART/RS485
    char debug_msg[50];
    sprintf(debug_msg, "Raw ADC Value: %u\r\n", val);
    RS485_Transmit((uint8_t*)debug_msg, strlen(debug_msg));

    return val;
}

I still think this is an input voltage problem.

The maximal ADC value corresponds to the ADC reference voltage Vref, and you need to check the datasheet / reference manual to see how your specific MCU handles this. Some variants have separate Vref pins, but usually it is tied to Vdda by default.


@Ozone wrote:

I still think this is an input voltage problem.


+1

@harshpanchal_6 and you still haven't said what voltages you measure at the STM32 ADC input pins.

 

As @Ozone said earlier, you need to get rid of all the other stuff and just concentrate on getting the ADC working.

The easiest way to do that would be on a Nucleo board.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

I have check the input voltage also which is perfect 

 

So is  on PD13 pin 2.8 V? And is on VDD, VDDA and VREF+ pin 3.3V?

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.