How to access APB registers for DIG SAR ADC

CafeNoir64
Posts: 3
Joined: Wed Oct 23, 2019 5:51 pm

How to access APB registers for DIG SAR ADC

Postby CafeNoir64 » Wed Oct 23, 2019 6:39 pm

My ultimate goal is to do high frequency (100-1000 kHz) ADC in the 0-1.1V range, i.e. with 0dB attenuation. Therefore, I am trying to use the DIG SAR ADC controller which can be accessed through the I2S peripheral, based of this example:https://github.com/espressif/arduino-es ... eq_ADC.ino. The example seems to be working for me, but by default it uses the maximum attenuation setting which yields a voltage range of 0-4V. And unlike the standard way of using the ADC, like this: (which gives me about 20 kHz sampling frequency; somehow even less than analogRead() does ~ 50kHz)

Code: Select all

adc1_config_width(ADC_WIDTH_12Bit);// use the max 12 bit ADC precision
adc1_config_channel_atten(ADC1_GPIO33_CHANNEL,ADC_ATTEN_0db);//strap ADC1 to GPI 33
cx_in[i] = adc1_get_raw(ADC1_GPIO33_CHANNEL);//read a sample
There is no setting as far as I can find which lets me easily adjust it, (using the adc1_config_channel_atten() command does not appear to have an affect on the DIG SAR ADC approach). This is where I started digging into the technical reference manual and stumbled upon this overview:
DIG_SAR_ADC_Control_Top.PNG
DIG_SAR_ADC_Control_Top.PNG (222.43 KiB) Viewed 3569 times
It clearly shows the pattern table which contains the attenuation for up to 16 measurement rules per controller. More detailed:
apb_registers.PNG
apb_registers.PNG (436.17 KiB) Viewed 3569 times
and description of contents per register:
APB_SARADC_SAR1_PATT_TAB1_REG.PNG
APB_SARADC_SAR1_PATT_TAB1_REG.PNG (105.72 KiB) Viewed 3569 times
So my idea was to write to this address and use a mask to set the attanuation to 0dB. However, I'm a noob and haven't approached registers on the ESP32 before so I'm quite unsure about what to do. After a lot of googling I think I have to do it like this:

Code: Select all

uint32_t mask = 0xFCFCFCFC;
  *((volatile uint32_t *) (0x0600261C)) &= mask;
However, this causes my board to crash and it ends up in a bootloop.

I was also looking around to find the header files which should contain the register addresses for APB_SARADC_SAR1_PATT_TAB1_REG etc, but I couldn't find this one exactly. I did find APB_CTRL_APB_SARADC_SAR1_PATT_TAB1_REG in <soc/apb_ctrl_reg.h> which points to a different address than the one given in the documentation.

Modifying the address from this header doesn't cause me bootloops but also doesn't seem to affect my attenuation :roll:.

Sorry about the long story, but I would really appreciate it if someone can help me find the right register and tell me how to address it properly.

Who is online

Users browsing this forum: No registered users and 74 guests