ADC on multiple pins with PPI - nRF52832

I was trying to build off of the example of Lesson 6, exercise 3 from the Intermediate course on DevAcademy. 

https://academy.nordicsemi.com/courses/nrf-connect-sdk-intermediate/lessons/lesson-6-analog-to-digital-converter-adc/

In this example, the AN0 is sampled the amount of times set by SAADC_BUFFER_SIZE (8000).

In my application, I am trying to sample on more than 1 pin.  Is it possible to do scan multiple pins with the PPI?

Ideally, I would like to monitor, AN2 and AN3.  In some circumstances, I want to monitor AN2, AN3, AN5, and AN6. 

I tried to modify the example as such but it reports 0bad0004

  /* STEP 4.6 - Declare the struct to hold the configuration for the SAADC channel used to sample the battery voltage */
    nrfx_saadc_channel_t channel_2 = NRFX_SAADC_DEFAULT_CHANNEL_SE(NRF_SAADC_INPUT_AIN2, 0);
    nrfx_saadc_channel_t channel_3 = NRFX_SAADC_DEFAULT_CHANNEL_SE(NRF_SAADC_INPUT_AIN3, 0);

    /* STEP 4.7 - Change gain config in default config and apply channel configuration */
    channel_2.channel_config.gain = NRF_SAADC_GAIN1_6;
    err = nrfx_saadc_channels_config(&channel_2, 0);
    if(err != NRFX_SUCCESS)
    {
        printk("nrfx_saadc_channels_config error\r\n");
        // LOG_ERR("nrfx_saadc_channels_config error: %08x", err);
        return;
    }

    channel_3.channel_config.gain = NRF_SAADC_GAIN1_6;
    err = nrfx_saadc_channels_config(&channel_3, 1);
    if(err != NRFX_SUCCESS)
    {
        printk("nrfx_saadc_channels_config error\r\n");
        // LOG_ERR("nrfx_saadc_channels_config error: %08x", err);
        return;
    }

    /* STEP 4.8 - Configure channel 0 in advanced mode with event handler (non-blocking mode) */
    nrfx_saadc_adv_config_t saadc_adv_config = NRFX_SAADC_DEFAULT_ADV_CONFIG;
    err = nrfx_saadc_advanced_mode_set(BIT(2)|BIT(3),
                                        NRF_SAADC_RESOLUTION_12BIT,
                                        &saadc_adv_config,
                                        saadc_event_handler);
    if(err != NRFX_SUCCESS)
    {
        printk("nrfx_saadc_advanced_mode_set error %08x\r\n", err);
        // LOG_ERR("nrfx_saadc_advanced_mode_set error: %08x", err);
        return;
    }

Any advice?

Parents Reply
  • I did find that if I used a value of

    #define SAADC_SAMPLE_INTERVAL_US 50

    and I tried to breakpoint and step through the code (using Ozone) that the debugger/IDE would seem to get stuck and not be able to step through the code. 

    Using a value of

    #define SAADC_SAMPLE_INTERVAL_US 500

    seemed to work much better for being able to step through the code while debugging. 

    This will definitely change how often the device processes the A to D pins but I willing to set it slower while I do my development.

    Any insight into why this would make debugging problematic?

Children
  • It sounds strange that the this change should impact debugging/stepping through the code. As far as I know, the timer is not used in SW, it only runs in HW and DPPI is used for trigging SAADC samploing. Would you be able to provide some more context regarding how you are debugging?

    jablackann said:
    the debugger/IDE would seem to get stuck and not be able to step through the code. 

    Could you please share some more details from this situation?

Related