cancel
Showing results for 
Search instead for 
Did you mean: 

Strange ADC behavior

Fx14
Associate

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

3 REPLIES 3
raptorhal2
Lead

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

Blocking functions in an interrupt/callback, probably non-optimal

Sample rates? Baud rates?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
AScha.3
Chief III

i think, you have a lot of interference on adc input, so

  1. connect a 100nF (cer. cap) direct (short connections) on adc-input to GND.
  2. show measurement  again
If you feel a post has answered your question, please click "Accept as Solution".