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

1kHz or more ADC sampling rate over BLE

Problem:

I am trying send samples from SAADC to the NRFconnect app at 1kHz. I have built my application on the ble_app_uart__saadc_timer_driven__scan_mode example. I have managed to achieve 420Hz but anything more than that results in a timeout error:

Error 8(0x8): GATT CONN TIMEOUT

Changes in default example:

  1. Samples in buffer increased from 4 to 24
  2. MIN_CONN_INTERVAL is 7.5ms
  3. MAX_CONN_INTERVAL is 15
  4. Bluetooth timeout and disconnect responses modified to make sure Bluetooth is visible and connectable even after a disconnect
  5. Only 1 ADC channel used instead of 4
  6. Sending data twice in one SAADC callback function, as follows

ret_code_t err_code;
uint16_t value[SAADC_SAMPLES_IN_BUFFER];
uint16_t bytes_to_send;

err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAADC_SAMPLES_IN_BUFFER);
APP_ERROR_CHECK(err_code);

for (int i = 0; i < SAADC_SAMPLES_IN_BUFFER; i++)
{
    if (p_event->data.done.p_buffer[i] <= 0)
    {
        value[i] = 0;
    }
    else
    {
        value[i] = p_event->data.done.p_buffer[i];
    }
}

uint8_t nus_string[50];

bytes_to_send = sprintf(nus_string, "%d %d %d %d %d %d %d %d %d %d", value[0], value[1], value[2], value[3], value[4], value[5], value[6], value[7], value[8], value[9]);
err_code = ble_nus_data_send(&m_nus, nus_string, &bytes_to_send, m_conn_handle);

bytes_to_send = sprintf(nus_string, "%d %d %d %d %d %d %d %d %d %d", value[10], value[11], value[12], value[13], value[14], value[15], value[16], value[17], value[18], value[19]);
err_code = ble_nus_data_send(&m_nus, nus_string, &bytes_to_send, m_conn_handle);

I cannot figure out how to increase the data rate anymore. I tried putting more values in one bytes_to_send string, but it shows the same error after 1 or 2 seconds. I tried sending more values by using the bytes_to_send block thrice instead of twice, all in no vein. I am using SoftDevice 132.

 Any help with this would be greatly appreciated. 

Thanks in advance,

Usman

Parents
  • Hi,

    Do you get any error codes from the ble_nus_data_send() function calls?

    If the problem is that you are sending too much data, it won't help to call the function twice.

    There are other methods to increase throughput (increased MTU, Data Length Extension - DLE, Connection Event Length Extension, etc.). See Bluetooth Low Energy data throughput in the softdevice specifications for maximum throughput for different configurations.

    Another thing you should consider is to send the SAADC samples as raw bytes, rather than strings. The SAADC samples are signed 16-bit integers, while the string you send can have up to 6 chars (48-bits, 5 chars for number + sign) for each sample. If you send the samples as raw bytes, you need to handle it accordingly on the receiver side; store in int16_t variable and not threat it as string.

    Best regards,
    Jørgen

  • Hi Jørgen,

    I finally managed to do it by increasing the max MTU from 240 to 265 and by sending one packet of 46 samples instead of two packets of 10 samples each. I will also explore the other two options you suggested and see if I can increase throughput even more.

    Thank you so much for your help. Smiley

    Best regards,

    Usman

Reply Children
No Data
Related