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

nRF52833 SAADC Transmitting full rate data over UART

Hello Nordic Team,

i've been evaluating the nRF52833 and i have been having a lot of good success.  i have been focused on the SAADC block to ensure it meets my performance needs.  i have been able to configure the block and get good data at lower rates.  I have started with the example for the DK and been able to customize it fairly easily.  

I'm not to the point where i need to achieve a faster sampling rate and observe the data.  If i'm understanding this correctly this piece of code controls the sample rate 

/* setup m_timer for compare event every 400ms */
uint32_t ticks = nrf_drv_timer_us_to_ticks(&m_timer, 500); //RPM
nrf_drv_timer_extended_compare(&m_timer,
NRF_TIMER_CC_CHANNEL0,
ticks,
NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
false);
nrf_drv_timer_enable(&m_timer);

in this case i have lowered the timer period to 500us as opposed to 400ms that is the default.  when i do this i get several dropped logs as shown in the UART.  i am running the UART at 460800 baud.  i believe i have enough bandwidth with the UART to display this data but i'm not sure how to increase the log size or improve the throughput in this case to get samples from the SAADC streamed over the UART any faster.  

do you have any guidance on where to go from there?

thanks!

  • Hi,

    The logs get dropped because the internal log buffer have been filled before your application is able to process it. There are a few different ways to work around this:

    • Disable deferred logging, by setting NRF_LOG_DEFERRED to 0 in your sdk_config.h file. Note that this will make logs being processed in-line, which may slow down your application.
    • Increase the log buffer, by setting NRF_LOG_BUFSIZE in your sdk_config.h file. I still see some logs dropped with your sample rate and buffer size set to 16384 in the SAADC example in SDK 17.0.2, but you can increase it even further if you have enough available RAM
    • Remove overhead in the logs, for instance by using NRF_LOG_RAW_INFO. This macro will only send the string you input and strip the "<info> app: " part of the log. You can also remove any additional logging that is not required, for instance the "NRF_LOG_INFO("ADC event number: %d", (int)m_adc_evt_counter);" part of the example if you still have this. Here you have a code snipper that will remove the overhead in the SAADC example:
      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;
      
              err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAMPLES_IN_BUFFER);
              APP_ERROR_CHECK(err_code);
      
              int i;
              //NRF_LOG_INFO("ADC event number: %d", (int)m_adc_evt_counter);
      
              for (i = 0; i < SAMPLES_IN_BUFFER; i++)
              {
                  NRF_LOG_RAW_INFO("%d\r\n", p_event->data.done.p_buffer[i]);
              }
              m_adc_evt_counter++;
          }
      }

    Another option is to use the UART driver directly and send large buffers of raw SAADC samples. This will take a bit more work, but you save some overhead of strings and the usage of the logger module.

    Best regards,
    Jørgen

Related