ADC reading issue
Posted: 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:
I read the data with this code:
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!
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);
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
Thanks!