This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

sampling two analog

Hello

I want to sampling two analog.. with different configuration and handler.

so I set two channels like this.

    nrf_saadc_channel_config_t cds_channel_config =
    NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN1);

    err_code = nrf_drv_saadc_init(&cds_saadc_config, cds_saadc_callback);
    if(err_code != NRF_SUCCESS) return 1;

    err_code = nrf_drv_saadc_channel_init(0, &cds_channel_config);
    if(err_code != NRF_SUCCESS) return 1;
    
    ///////////////////////////////// (different function)
    
    nrf_saadc_channel_config_t co_channel_config =
    NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN6);

    err_code = nrf_drv_saadc_init(&co_saadc_config, co_saadc_callback);
    if(err_code != NRF_SUCCESS) return 1;

    err_code = nrf_drv_saadc_channel_init(1, &co_channel_config);
    if(err_code != NRF_SUCCESS) return 1;

and then I call only one sample function like this.

void saadc_process()
{
    //..

    nrf_drv_saadc_sample();
}

Then error occurs. How can I change code?

and is there good example I can refer?

BR,

lyrics

Parents Reply Children
  • But do they require a different configuration of the SAADC peripheral? If yes, exactly what needs to be different? 

    Because I set different resolution value. cds is 8Bit , and co is 10Bit.  Also, I tried to handle each value

    with a handler. (cds_handler and co_handler)

    I don't know the ads functions well, so I just divided them into two.

    Is there a way to separate two channels in one handler? 

  • Hi,

     

    lyrics said:

    Because I set different resolution value. cds is 8Bit , and co is 10Bit.  Also, I tried to handle each value

     Then you need to:

    1. Initialize the SAADC with 8 bit resolution.
    2. Sample 
    3. Un initialize the SAADC
    4. Initialize the SAADC with 10 bit resolution
    5. Sample

    Maybe it would be better to just use 10 bits in both cases, that way you wouldn't need to reinitialize the SAADC peripheral between each sample. You can truncate the 10 bit result to 8 bit in your application instead. 

     

    lyrics said:
    Is there a way to separate two channels in one handler? 

    The samples are taken sequential starting from the lowest channel number. You can print the number of the sample to keep track of which channel it comes from. For example, if you're using two channels then you know that odd numbered samples are from the first channel, and even numbered samples are from the second channel.

    regards

    Jared 

  • Hi,

    Maybe it would be better to just use 10 bits in both cases,

    First of all, I just added a channel and ran the program..

    But error occurs second channel init function.. (nrf_drv_saadc_channel_init)

     I hope there is reference code (example)!

        ret_code_t err_code;
        nrf_drv_saadc_config_t cds_saadc_config;
    
        cds_saadc_config.low_power_mode = false;                                  //Enable low power mode.
        cds_saadc_config.resolution = NRF_SAADC_RESOLUTION_8BIT;                  //Set SAADC resolution to 12-bit. This will make the SAADC output values from 0 (when input voltage is 0V) to 2^12=4096 (when input voltage is 3.6V for channel gain setting of 1/6).
        cds_saadc_config.oversample = NRF_SAADC_OVERSAMPLE_DISABLED;              //Set oversample to 4x. This will make the SAADC output a single averaged value when the SAMPLE task is triggered 4 times.
        cds_saadc_config.interrupt_priority = APP_IRQ_PRIORITY_LOW;               //Set SAADC interrupt to low priority.
    
        nrf_saadc_channel_config_t cds_channel_config =
        NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN1);
    
        err_code = nrf_drv_saadc_init(&cds_saadc_config, cds_saadc_callback);
        if(err_code != NRF_SUCCESS) return 1;
    
        err_code = nrf_drv_saadc_channel_init(0, &cds_channel_config);
        if(err_code != NRF_SUCCESS) return 1;
    
        err_code = nrf_drv_saadc_buffer_convert(m_cds_buffer_pool[0], 1);
        APP_ERROR_CHECK(err_code);
        
        err_code = nrf_drv_saadc_buffer_convert(m_cds_buffer_pool[1], 1);
        APP_ERROR_CHECK(err_code);
        
        nrf_saadc_channel_config_t co_channel_config =
        NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN6);
    
        err_code = nrf_drv_saadc_channel_init(1, &co_channel_config );
        APP_ERROR_CHECK(err_code);
        
        err_code = nrf_drv_saadc_buffer_convert(m_co_buffer_pool[0], 1);
        APP_ERROR_CHECK(err_code);
        
        err_code = nrf_drv_saadc_buffer_convert(m_co_buffer_pool[1], 1);
        APP_ERROR_CHECK(err_code);
        
        //CDS_F=1;
        return 0;
    

  • lyrics said:

    But error occurs second channel init function.. (nrf_drv_saadc_channel_init)

     OK, but this is a different function than earlier. What error code is returned?

    regards

    Jared 

  • Hi,

    OK, but this is a different function than earlier. What error code is returned?

    In that case, the err_code is 0x11 (17).

    However, if I move on to the next function with the break point, the error below occurs.

Related