2022-08-28 12:28 PM
I am working in a project where I have to sample a signal with a sampling frequency of 8 kHz with the ADC. That data is send from the ADC to SRAM using DMA and then send through UART interface. I am using a "Blue pill" board (STM32F103C8T6) with a system clock of 16 MHz clock.
Initialization:
HAL_ADCEx_Calibration_Start(&hadc1);
HAL_ADC_Start_DMA(&hadc1, (uint32_t *) dma_buffer, DMA_BUF_LEN);
HAL_TIM_Base_Start(&htim3);
Sending data:
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef * hadc){
HAL_UART_Transmit(&huart1,(uint8_t *) &dma_buffer[DMA_BUF_LEN/2], DMA_BUF_LEN * sizeof(buffer_t)/2,100);
}
void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef * hadc){
HAL_UART_Transmit(&huart1,(uint8_t *) &dma_buffer[0], DMA_BUF_LEN * sizeof(buffer_t)/2,100);
}
The problem that I am facing is that the ADC read wrong values periodically as you can see in the images. I have turned off all the possible sources of noise with no success. Furthermore, the noise is not uncorrelated to the signal. If the derivative of the signal is negative the noise has one shape and if the derivative of the signal is positive, it is the opposite.
Any idea what can might be going and how to fix this issue? The ADC is reading a potentiometer of 10k so the source resistance is not high and the issue is present all the way from GND to VDD.
Thanks
2022-08-28 04:55 PM
10K resistance is high. What is the sampling time in cycles?
ST has an application note on ADC accuracy that should be consulted.
Cheers, Hal
2022-08-28 05:42 PM
Blocking functions in an interrupt/callback, probably non-optimal
Sample rates? Baud rates?
2022-08-29 12:34 AM
i think, you have a lot of interference on adc input, so