cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with ADC values

BEN OTHMEN BADR
Associate II
Posted on February 09, 2017 at 12:45

Hi,

I have an STM32F3Discovery board, and I tried to use ADC, my problem is that the values are not correct.

the idea is to generate a ramp from the DAC and read values using ADC.

My code is generated using STM32CubeMX, file attached.

Example of values :

DAC : ADC

1760 : 1693

1761 : 1694 1762 : 1696 1763 : 1697 1764 : 1696 1765 : 1697

My main function :
int main(void)
{
 int a;
 char buff[100];
 
 HAL_Init();
 SystemClock_Config();
 MX_GPIO_Init();
 MX_DAC_Init();
 MX_USB_DEVICE_Init();
 MX_ADC2_Init();
 HAL_DAC_Start(&hdac,DAC_CHANNEL_1);
 
 while(1){
 for(int i=0;i<4095;i++){
 HAL_DAC_SetValue(&hdac,DAC_CHANNEL_1,DAC_ALIGN_12B_R,i);
 HAL_Delay(100);
 if (HAL_ADC_Start(&hadc2) != HAL_OK){Error_Handler();}
 if (HAL_ADC_PollForConversion(&hadc2, 1000) != HAL_OK){Error_Handler();}
 else{a = HAL_ADC_GetValue(&hadc2);}
 if(hUsbDeviceFS.dev_state == 3){
 sprintf(buff,'%4d : %4d\r\n',i,a);
 CDC_Transmit_FS(buff,strlen(buff));
 }
 }
 }
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Thanks for your help

30 REPLIES 30
Posted on February 16, 2017 at 23:11

Hiya Nesrine,

nice reference, but this will not eleminate the root of the problem and this is not a firmware as more a design problem of the disco boards. The ADC of the STM32 MCU's are mostly 12bit wide and resolute the reference voltage into 4096 steps. This means that 1 digit equates 0,0008 Volts. The passive regulator used on the board needs to have less ripples than 0,0008V to get a stable value - it's far away from this.  

The MCU does not contains an internal high stable reference voltage generation with temp compensation and in addition, the less stable voltage source of the mainboard is used as a reference. The DAC also uses the same unstable reference voltage and the output will also going up and down how the load of the board is changing. The the four lower digits of the ADC are unusable and the DAC is noisy. This could not compensate by a an oversampling algorythm. All of them i wrote about the reference voltage can be smooth by using an external reference voltage, but you can get maybe one or two more valid digits. 12Bit resolution at 3.3V is a very tricky job to get them acurate. I have done some experiences with the ADC of the STM32F407, STM32F103 and now the STM32F746. All the boards are cheap in their design and not further optimized using the full resolution - the purpose of teh disco and nucleo's are  just to demonstrate the functionality - not less but even not more. To evaluate the usablity of the STM32Fxxx ADC and DAC's all the board are not usable if the application needs an acuate ADC or DAC.

  

  
Posted on February 16, 2017 at 23:18

If I am not mistaken, the calibrate of the ADC is not available in the F4. It's also a good idea to take a look into the available errata of the used MCU. They are often good for surprises.

Posted on February 16, 2017 at 23:42

Wow, you gett mutch better results if you use only 16 values? I had checked them up and the solution was'nt better as without.

You can see a demo about that i mean of:

https://www.youtube.com/watch?v=lr8CVF3Hl4E

 

This Controller uses an F4Disco board and oversample 768 values to get the display usable. The board uses the DMA and collect 3 ADC channels. I had attempt to reduce the resolution to 10bit, but this does'nt help's. To get them better, a precisions reference voltage source is required to use. I need to resolve 450 angle degree in a 1 degree precision, so 10 Bits are required. I cut the first 3 digit and oversample the 9Bit to get the values near stable. 

Posted on February 17, 2017 at 04:19

Sorry

Kaltofen.Jupp

I was not clear enough,

At this point I was not talking about the F4 case described by

mao.rongwei

for which I already provided an explanation, and improvement can be obtained by following the recommendations in

mao.rongweiwww.st.com/content/ccc/resource/technical/document/application_note/a0/71/3e/e4/8f/b6/40/e6/DM000508pdf/files/DM000508pdf/jcr:content/translations/en.DM000508pdf

as explainedin the

http://www.st.com/content/ccc/resource/technical/document/errata_sheet/0a/98/58/84/86/b6/47/a2/DM000375pdf/files/DM000375pdf/jcr:content/translations/en.DM000375pdf

.

I was talking about

Ben_Othmen.Badreddin

case, the original subject of this thread, i.e. discrepancy between DAC and ADC measured on the STM32F3 discovery board.

The SAR ADC embedded in the STM32F3 series do have a calibration feature, and I think it should be used in this specific case ifa fewLSB of precision is expected.

Additionally, the STM32F3 Discovery board does implement a LC filter between VDD and VDDA/Vref, so noise on the supply should not impact the ADC tosuch an extend.

Anyway, the supply to check for noise on this board is VDDA, not VDD.

By default Vref is connected to VDDA on this board by R31 = 0R, but Vref is usually another MCU pin to check for noise.

I do believethe precision specification of the ADC and DAC from the datasheet should be achievable on this board in the condition described (i.e

PA4 and PA5 connected together, very simple code)

.

regards,

Max

Posted on February 17, 2017 at 08:17

Hi

teissier.maxime

‌,

Did the F413CGU6 chip has been corrected also ? In fact I have ordered two samples to do some tests.

Regards

Posted on February 17, 2017 at 08:19

Hi

teissier.maxime

‌,

Yes I have do calibration procedure without a positive result.

Regards.

Max
ST Employee
Posted on February 17, 2017 at 10:25

Yes, the STM32F413 line has been corrected.

This is the most recent member of the F4 series.

Posted on February 17, 2017 at 19:06

I had checked the schematic of the F3 Disco board and coul'nt find a Major differency between the F4Disco and F3 Disco board in relation of the reference voltage Generation. The L-C filter works as just an simple EMI-Filter to block RF on the power source. It does not valid to stablize the reference voltage. We talks about 0.0008Volt/step - the ripple of the MPU's power source is decates higher that this. That's the reason why the industry uses precise voltage reference sources for this kind of purpose.

If course, it's possible to smooth the samples a bit more by oversampling, but this in  not a choise in various cases. I had done this in one of my project, because it's just need 9 Bits resolution acuratcy and the variation of the digitized signal is very slow.  

It's not a surprize for me that the calibration doesn't solve the issue - it's gambling what the ADC / DAC doing without a stable reference.
Posted on February 18, 2017 at 00:58

The L-Cfilter works as just an simple EMI-Filter to block RF on the power source.. It does notvalid to stablize the reference voltage.

If you desire more precision using these COTS boards, why don't you disconnect VREF/VDDA from VDD and use some suitable stable/precise/low-noise reference of your choice?

Of course, this won't eliminate the error sources inherent in low-cost ADC-in-a-digital-process born out of tradeoffs, as the STM32's onchip ADCs are.

JW

Posted on February 18, 2017 at 07:37

If you desire more precision using these COTS  boards, why don't you disconnect VREF/VDDA from VDD and use some suitable stable/precise/low-noise reference of your choice?

That's a requirement if you wanna use a precision volatage reference. A 0Ohm (jumper) resistor is available for that.

And yes, you are right, a low-cost board could not gain all requirements of an more expensive developing board.

ST uses a bunch of hardware on various disco/nucleo boards, it's a shame they save the money and not spend the board this cheap part to let the 12Bit ADC / DAC resolution be usable. You need to degrade this to 8bit or need to waste memory and process time to oversample.