AnsweredAssumed Answered

Problem with ADC values

Question asked by BEN OTHMEN BADR on Feb 9, 2017
Latest reply on Apr 13, 2017 by kaltofen.jupp

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

Attachments

Outcomes