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

How to find out SAADC sampling time??

Hello.

I'm using nrf52833 / SDK 17.0.0

I want to find out SAADC sampling time by using logic analyzer.

However, I still  don't know what sampling time is.

In this picture, CH7 means pin(0,12) CH8 means(0,24).

With zooming CH7.

Below is my code.

But I don't know how to configure Sampling time

When I choose acqtime = 10us.

Is it right that Sampling time must be smaller then acqtime + convtime(about 12us)??

void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
{
    if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
    {
        ret_code_t err_code;
        uint16_t adc_value;
        uint8_t value[SAADC_SAMPLES_IN_BUFFER*2];
        uint16_t bytes_to_send;
				nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(0,24));
				nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(0,12));			

        // set buffers
        err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAADC_SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);
						
        // print samples on hardware UART and parse data for BLE transmission
        printf("ADC event number: %d\r\n",(int)m_adc_evt_counter);
 
				for (int i = 0; i < SAADC_SAMPLES_IN_BUFFER; i++)
        {
						printf("ADC RESULT : %d\r\n", p_event->data.done.p_buffer[i]);

						adc_value = p_event->data.done.p_buffer[i];
            value[i*2] = adc_value>>8;
            value[(i*2)+1] = adc_value;
						nrf_gpio_pin_toggle(NRF_GPIO_PIN_MAP(0,12));

        }
				nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(0,24));


         // Send data over BLE via NUS service. Create string from samples and send string with correct length.
				bytes_to_send = (uint16_t) SAADC_SAMPLES_IN_BUFFER*2;
				
        err_code = ble_nus_data_send(&m_nus, value, &bytes_to_send, m_conn_handle);
        if ((err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_NOT_FOUND))
        {
            APP_ERROR_CHECK(err_code);
        }
				
	
        m_adc_evt_counter++;
    }
}

cF)  SAADC_SAMPLE_IN_BUFFER = 100

Thank you

Parents
  • Is it right that Sampling time must be smaller then acqtime + convtime(about 12us)??

     No, it's the other way around, your sampling time needs to be longer than acquisition time + conversion time. 

    Also, you're putting a lot application code in your SAADC callback and it's running in interrupt context, you should consider running the uart printing and BLE transfers in mains context. 

Reply
  • Is it right that Sampling time must be smaller then acqtime + convtime(about 12us)??

     No, it's the other way around, your sampling time needs to be longer than acquisition time + conversion time. 

    Also, you're putting a lot application code in your SAADC callback and it's running in interrupt context, you should consider running the uart printing and BLE transfers in mains context. 

Children
Related