Page 1 of 1

ADC reading issue

Posted: Tue Oct 22, 2024 3:41 pm
by MattiaBerton
Hello,
I'm having some issue on ADC reading. I have a custom board, where I use both ADC1 and ADC2 with 3 channels each. On a timer interrupt, for each ADC I set the channel and start the ADC:

Code: Select all

			// Select ADC1 channel
	CLEAR_PERI_REG_MASK(SENS_SAR_MEAS1_CTRL2_REG, SENS_SAR1_EN_PAD_M); // Clear all ADC2 channel enable bits
	REG_SET_BIT(SENS_SAR_MEAS1_CTRL2_REG, (1 << (SENS_SAR1_EN_PAD_S + ADC1_channel))); 
	// start ADC1
	REG_CLR_BIT(SENS_SAR_MEAS1_CTRL2_REG, SENS_MEAS1_START_SAR);
	REG_SET_BIT(SENS_SAR_MEAS1_CTRL2_REG, SENS_MEAS1_START_SAR);

	// Select ADC2 channel
	CLEAR_PERI_REG_MASK(SENS_SAR_MEAS2_CTRL2_REG, SENS_SAR2_EN_PAD_M); // Clear all ADC2 channel enable bits
	REG_SET_BIT(SENS_SAR_MEAS2_CTRL2_REG, (1 << (SENS_SAR2_EN_PAD_S + ADC2_channel))); 
	// start ADC2
	REG_CLR_BIT(SENS_SAR_MEAS2_CTRL2_REG, SENS_MEAS2_START_SAR);
	REG_SET_BIT(SENS_SAR_MEAS2_CTRL2_REG, SENS_MEAS2_START_SAR);
I read the data with this code:

Code: Select all

	// Read the ADC1 value
	v_n[2] = REG_READ(SENS_SAR_MEAS1_CTRL2_REG) & SENS_MEAS1_DATA_SAR_V; // ADC result is 12 bits
	// Read the ADC2 value
	i_n[2] = REG_READ(SENS_SAR_MEAS2_CTRL2_REG) & SENS_MEAS2_DATA_SAR_V; // ADC result is 12 bits
Sometimes data in ADC2 (i_n[2]) is 0. I don't have Wifi, so Arbiter should not be a problem. What else could it be?
Thanks!

Re: ADC reading issue

Posted: Tue Oct 22, 2024 5:23 pm
by MicroController
How do you make sure the conversion is finished before trying to read the result?

Re: ADC reading issue

Posted: Wed Oct 23, 2024 9:06 am
by MattiaBerton
I don't check it. I wait more time than needed: I have RTCADC_SARCLK of 5 MHz, so acquisition time should be 5 uS. I wait 20 uS from start of conversion to reading result.
But you are right: each time ADC2 fails, it is because of SENS_MEAS2_DONE_SAR is not 1. But I can't understand why 20 uS are not enough to switch MUX and have a correct reading.

Re: ADC reading issue

Posted: Wed Oct 23, 2024 2:43 pm
by MattiaBerton
Increasing the delay to 35 us I got no error in ADC reading.
However, a strange behaviour appears: I need to write in flash every 20 seconds. While ADC1 in RTC mode works without any problem, ADC2 reads 0 every time I try to write in flash.
Why such a different behaviour?