cancel
Showing results for 
Search instead for 
Did you mean: 

stm32u575 adc differential mode

Ephraimoved
Associate III

Dear Sir.

I need the output of the ADC to be signed .

the adc is configured .

 /** Common adc1 configuration */

 hadc->Init.ClockPrescaler      = ADC_CLOCK_ASYNC_DIV1;

 hadc->Init.Resolution        = ADC_RESOLUTION_14B;

 hadc->Init.DataAlign        = ADC_DATAALIGN_RIGHT;

 hadc->Init.ScanConvMode       = ADC_SCAN_ENABLE;

 hadc->Init.EOCSelection       = ADC_EOC_SINGLE_CONV;

 hadc->Init.ExternalTrigConv     = ADC_EXTERNALTRIG_LPTIM2_CH1;

 hadc->Init.ExternalTrigConvEdge   = ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING;

 hadc->Init.TriggerFrequencyMode   = ADC_TRIGGER_FREQ_HIGH;

 hadc->Init.Overrun         = ADC_OVR_DATA_OVERWRITTEN;

 hadc->Init.LeftBitShift       = ADC_LEFTBITSHIFT_NONE;

 hadc->Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_CIRCULAR;

 hadc->Init.LowPowerAutoWait     = DISABLE;

 hadc->Init.ContinuousConvMode    = DISABLE;

 hadc->Init.DMAContinuousRequests  = ENABLE;

 hadc->Init.OversamplingMode     = DISABLE;

 hadc->Init.DiscontinuousConvMode  = DISABLE;

 hadc->Init.NbrOfConversion     = ADC_CHANNELS;

 hadc->Init.GainCompensation     = 0;

 if (HAL_ADC_Init(hadc) != HAL_OK)

 {

Error_Handler();

 }

 sConfig.Channel   = ADC_CHANNEL_15;

 sConfig.Rank     = ADC_REGULAR_RANK_1;

 sConfig.SamplingTime = ADC_SAMPLETIME_391CYCLES_5;

 sConfig.SingleDiff  = ADC_DIFFERENTIAL_ENDED;

 sConfig.OffsetNumber = ADC_OFFSET_NONE;

 sConfig.Offset = 8192;

 sConfig.OffsetSign  = ADC_OFFSET_SIGN_NEGATIVE;

 if (HAL_ADC_ConfigChannel(hadc, &sConfig) != HAL_OK)

 {

Error_Handler();

 }

the adc output register is drfined as

__IO  int  aADCxConvertedData[ADC_CONVERTED_DATA_BUFFER_SIZE * ADC_CHANNELS];

Any idea why I don get the aADCxConvertedData negative ?

Please Advise.

1 REPLY 1
CMYL
ST Employee

Hi @Community member​,

ADC_OUTPUT = Full_scale x Vinput/VREF+

Vinput that is the channel input is always between Vref+ and Vref- (for Nucleo-U5 Vref+=VDD and Verf-=VSS). As Vinput is always positive, the ADC_OUTPUT (converted data) is always positive.

Real value should be got according to your sensor documentation, which is function of Vinput or ADC_OUTPUT values. This real value can be negative or positive.

BR,

Younes