2017-02-09 03:45 AM
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 : 1697My 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
2017-02-11 11:39 AM
PA5 is dedicated to an on board function. Try using the PA4/PA3 combination.
Cheers, Hal
2017-02-14 07:13 AM
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
2017-02-14 07:28 AM
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 : 16941762 : 16961763 : 16971764 : 16961765 : 1697Do 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.
2017-02-14 08:03 AM
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 : 137You see here values is +/- 2 bits difference, max is +/-3bits
Regards.
2017-02-14 08:26 AM
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.
2017-02-14 09:36 AM
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
2017-02-14 11:08 AM
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
2017-02-14 08:06 PM
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
2017-02-15 07:22 PM
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:
has 2.1.15 Internal noise impacting the ADC accuracy which
has been corrected on more recent STM32F4 members like the
.2017-02-15 08:11 PM
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(); }