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
  • Hi jablackann,

    One thing I have spotted so far is that you should probably put it like this instead: 

    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, 1);

    Each channel shoud have a unique index number.

    Just letting you know we have started working on this. I will get back to you when I have had a closer look.

Reply
  • Hi jablackann,

    One thing I have spotted so far is that you should probably put it like this instead: 

    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, 1);

    Each channel shoud have a unique index number.

    Just letting you know we have started working on this. I will get back to you when I have had a closer look.

Children
No Data
Related