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
raptorhal2
Lead
Posted on February 11, 2017 at 20:39

PA5 is dedicated to an on board function. Try using the PA4/PA3 combination.

Cheers, Hal

Posted on February 14, 2017 at 15:13

Hi Braid,

Yes I tried this configuration also, without any positive result, I tried also to use LQFP-48 STM32F072 chip, still fail to get real values from ADC.

Regards

Posted on February 14, 2017 at 15:28

Even with buffer, the DAC output is relatively 'weak'. Your ADC sampling time setting is not visible, but try longer one's.

Example of values :

DAC : ADC

1760 : 1693

1761 : 1694

1762 : 1696

1763 : 1697

1764 : 1696

1765 : 1697

Do you honestly expect the ADC to follow LSB steps of the DAC output ?

I think you are a quite a bit optimistic here. Try bigger steps.

Posted on February 14, 2017 at 16:03

Hi,

this phenemenon is related to STM32F303, STM32F051, STM32F072,

When I tested with STM32F407 the result is correct ! 

Values for STM32F407 :

DAC : ADC 

120 : 121

121 : 122

122 : 123

123 : 124

124 : 125

125 : 128

126 : 128

127 : 129

128 : 130

129 : 132

130 : 130

131 : 132

132 : 134

133 : 134

134 : 136

135 : 137

You see here values is +/- 2 bits difference, max is +/-3bits

Regards.

Posted on February 14, 2017 at 16:26

this phenemenon is related to STM32F303, STM32F051, STM32F072,

When I tested with STM32F407 the result is correct ! 

I don't think so.

This is much more dependent on the board and PCB design than on the different MCUs - especially F303 vs. F407.

Posted on February 14, 2017 at 17:36

I worked the first time on the F3Discovery board, then I worked on my own PCB that's have more quality than the discovery board.

Regards

Posted on February 14, 2017 at 19:08

I have same experience. I tested ADC for chip STM32F405RGT6 and F411RET6. The later has a much better ADC performance than the other one.  I mean much better. You can image the difference.

The testing system is using a function generator to output sine wave to the board and the board capture the waveform and save to the flash. Finally export the data to PC to analyze them.

The ADC data from F411RET6 is pretty smooth, but very ugly (zigzap) for F405.

I don't know what is the exact difference in chip which makes the big difference.

By the way I recommand using a function generator to test the system to figure out the absolute performance of ADC

Posted on February 15, 2017 at 04:06

hi,

Yes, by checking datasheets for various families of STM, you can see thats not the same ADC module in all chips.

I have used a DDS wave generator and I have compared the values,always the same results.

regards

Posted on February 16, 2017 at 03:22

mao wrote:

I have same experience. I tested ADC for chip STM32F405RGT6 and F411RET6. The later has a much better ADC performance than the other one.  I mean much better. You can image the difference.

The testing system is using a function generator to output sine wave to the board and the board capture the waveform and save to the flash. Finally export the data to PC to analyze them.

The ADC data from F411RET6 is pretty smooth, but very ugly (zigzap) for F405.

I don't know what is the exact difference in chip which makes the big difference.

By the way I recommand using a function generator to test the system to figure out the absolute performance of ADC

The 

STM32F405RGT6 and STM32F411RET6 are in the same series which usually means they have the same ADC.

But in this case there is a difference in the errata:

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

  has 2.1.15 Internal noise impacting the ADC accuracy which 

has been corrected on more recent STM32F4 members like the

http://www.st.com/content/ccc/resource/technical/document/errata_sheet/81/45/af/ac/2b/e1/4d/07/DM00137034.pdf/files/DM00137034.pdf/jcr:content/translations/en.DM00137034.pdf

.
Max
ST Employee
Posted on February 16, 2017 at 05:11

Hello

,

Did you try to perform an ADC calibration to see if this improve the results?

/* Run the ADC calibration in single-ended mode */ if (HAL_ADCEx_Calibration_Start(&hdac, ADC_SINGLE_ENDED) != HAL_OK) { /* Calibration Error */ Error_Handler(); }