ADC reading issue

MattiaBerton
Posts: 33
Joined: Thu Aug 30, 2018 8:16 am

ADC reading issue

Postby MattiaBerton » Tue Oct 22, 2024 3:41 pm

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!

MicroController
Posts: 1652
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: ADC reading issue

Postby MicroController » Tue Oct 22, 2024 5:23 pm

How do you make sure the conversion is finished before trying to read the result?

Who is online

Users browsing this forum: No registered users and 85 guests