[ESP32S2] ADC measurements from ULP RISC-V

brett.brotherton
Posts: 1
Joined: Tue Jul 06, 2021 10:27 pm

[ESP32S2] ADC measurements from ULP RISC-V

Postby brett.brotherton » Fri Jul 09, 2021 7:45 pm

Hello,

I am trying to run ADC measurement from the ULP RISC-V coprocessor but cannot figure out how to trigger them.

According to https://docs.espressif.com/projects/esp ... isc-v.html the ULP RISC-V has access to the SAR ADC peripheral but I am unsure how to use it from the ULP-RISCV. I have tried with code as follows:

Code: Select all

void init_ulp_program(void)
{
    esp_err_t err = ulp_riscv_load_binary(ulp_main_bin_start, (ulp_main_bin_end - ulp_main_bin_start));
    ESP_ERROR_CHECK(err);

    /* The first argument is the period index, which is not used by the ULP-RISC-V timer
     * The second argument is the period in microseconds, which gives a wakeup time period of: 20ms
     */
    ulp_set_wakeup_period(0, 20000);

    // adc setup
    adc1_config_width(ADC_WIDTH_BIT_13);
    adc1_config_channel_atten(ADC_UNIT_1, ADC_ATTEN_6db);
    adc1_ulp_enable();

    /* Start the program */
    err = ulp_riscv_run();
    ESP_ERROR_CHECK(err);
}
Here is the code I tried running on the ULP RISC-V

Code: Select all

uint32_t channel_mask  = 1 << ADC_CHANNEL_8;
REG_WRITE(SENS_SAR_MEAS1_CTRL2_REG, SENS_SAR1_EN_PAD_FORCE | SENS_MEAS1_START_FORCE | SENS_MEAS1_START_SAR | (channel_mask << SENS_SAR1_EN_PAD_S));
do {
  ulp_riscv_delay_cycles(100 * ULP_RISCV_CYCLES_PER_US);
  last_reg_val = REG_READ(SENS_SAR_MEAS1_CTRL2_REG);
} while ((last_reg_val & SENS_MEAS1_DONE_SAR_M) == 0);
It appears that this is not properly tirggering an ADC read on Channel 8 as the while loop blocks forever. The ULP FSM has special instructions and registers for tirggering ADC reads from ULP but from what I can tell RISC-V has no such instruction and the standard way to trigger an ADC read does not appear to work from RISC-V.

Who is online

Users browsing this forum: No registered users and 71 guests