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 April 13, 2017 at 22:42

i have done some experiences with the F4 Line and will write something about it, even this not matches the exact thread topic, but maybe helpful related by the discussed issue.

The ADC of the F4 line are not able to justify or calibrate to get more stable values. The source of the issue is not the MPU or the ADC who is build-in  itself as more the design of the Discovery-board and the reference voltage generation on them.

I had rewired the mpu's pins of the DAC and ADC to an external temperature compensated high-stable reference voltage circuit and checked the values and the values are quite more stable and does'nt differs more that 10 at 12bit's resolution. It's possible to use two adc's and couple them to use them as a tandem. This requires a differential signaling - thats would be helpfully if the signal source that should converted is connected by a longer line or difficult environment.

The F7 Nucleo board is more versatile and uses jumpers to disconnect the references. I will do some test soon.