cancel
Showing results for 
Search instead for 
Did you mean: 

ADC measurement toggles between correct value and (2^n - 1) every couple readings

Rafael Bachmann
Associate II

I am taking measurements with the ADC1 in an STM32f042C6T6. I poll the temperature channel for examples here, but this problem appears in every channel and regardless of sample time, polling/IT/DMA mode, and clock frequency (AFAICT).

Setting up the ADC in CubeMX: 12Bit resolution, 239.5 cycles, other settings depending on whether I use DMA or not (but make no difference).

In polling mode, I read the ADC as follows:

HAL_ADC_Start(&hadc);
HAL_ADC_PollForConversion(&hadc, HAL_MAX_DELAY);
uint32_t temp = HAL_ADC_GetValue(&hadc);
HAL_ADC_Stop(&hadc);

Or use the conversion complete interrupt to read the value, or read the value from an array shared with the DMA.

The measurement is periodically correct, and then for approx. the same amount of time it is the value 4095 (2^12 - 1). If I reduce the ADC resolution, the measurement periodically is 2^n - 1 (i.e., at 6 bit it will be 63). After a dozen measurements or so, the value will be correct again, and then become incorrect again.

What could be causing this? I don't remember this happening earlier. Did I fry something?

Thank you for your help.

UPDATE: I had an external signal connected to TIM2 in input comparison mode. This signal influenced the ADC. I am not sure how this can happen, but the problem disappears when I remove the signal.

1 REPLY 1

Read out and check content of ADC registers.

JW