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

Configuring ADC sampling rate and simultaneous reading from multiple channels.

Hi, guys! I'm using the nRF52 SDK 15.3 BLE_APP_UART peripheral example.

I wish to add 3 ADC channels (12-bit) to read 3 potentiometers at a sampling frequency of 6kHz.

When I tried the timer interrupt, I think I can generate a timer interrupt which is millisecond range.

Can I ask these;

0. Can I set a timer to sample analog value at 6kHz? Or due to the spec (SoftDevice, BLE, etc), is this not possible?

1. I'm using 3 channels (A0, A1, A2). Is there a way to read all 3 simultaneously? I don't want to read A0 -> A1 -> A2.

2. After reading it, I wish to send these values using NUS (Nordic UART service) to the central.

I think the TX buffer will not be empty if I send these after each ADC readings.

In the past, I used the TX complete BLE event to send multiple data. From SDK 15, how can I send these chunk of data?

3. Do you think using a different BLE service would be better instead of using NUS?

THanks for the help

Parents
  • Hi,

    0. You can set a timer to sample analog values up to the maximum sample rate of the SAADC (200 ksps). The SAADC peripheral support EasyDMA, which allows you to sample directly to RAM without CPU being involved. You will have to make sure that you have enough CPU availability to process the samples and setup new buffers.

    1. You can not read all 3 simultaneously, the nRF52 series ICs only have a single SAADC, with 8 muxed inputs. You can setup multiple channels that is sampled sequentially, by a single trigger of the SAMPLE task. This is called SCAN mode, and will sample the lowest channel first, then second lowest, and so on.

    2. Depending on the configuration of the BLE link and how often you send data, you might face issues sending the data over BLE. You will not be able to send the samples at each sample interval, but if you send larger buffers, you could be able to send all samples. With 6 kHz sample rate and 3 channels, you will need a throughput of 6000 samples * 3 channels * 16 bits = 288 kbit/s. See the softdevice specifications for more details on throughput.

    3. NUS will give you the same throughput as any other GATT service, it is just sending bytes using notifications. Just make sure that you send the samples as binary data and not convert it to strings.

    If you have not already seen it, I would recommend having a look at this examples, that basically does what you are looking for. There is also a branch for SDK 15.2.0 support, but this have not yet been fully tested.

    Best regards,
    Jørgen

  • 0. Yes, that is correct. However, note that it will sample channel0 - channel1 - channel2 - channel3 regardless of which analog input the channel is configured to sample, for instance you could configure channel0 with input AIN7 and it would still be sampled first.

    1. It will sample next channel as soon as the first channel is done. The sample time will depend on the configured acquisition time.

    2. You only have to change SAADC_SAMPLE_RATE (and change nrf_drv_timer_ms_to_ticks() to nrf_drv_timer_us_to_ticks()), but increasing the timer frequency could be good to get better accuracy in the timer compare register.

    3. The SAADC peripheral support double buffering, allowing you to sample to one buffer while processing the previously filled buffer. You could just as well have used two separate variables.

    4. The SAADC always use EasyDMA to store samples directly in the buffer in RAM.

    5. The NUS example is limited by the BLE configuration. If you increase MTU size and enable DLE, NUS can support more than 20 bytes. Please have a look at this blog post to understand the different parameters.

Reply
  • 0. Yes, that is correct. However, note that it will sample channel0 - channel1 - channel2 - channel3 regardless of which analog input the channel is configured to sample, for instance you could configure channel0 with input AIN7 and it would still be sampled first.

    1. It will sample next channel as soon as the first channel is done. The sample time will depend on the configured acquisition time.

    2. You only have to change SAADC_SAMPLE_RATE (and change nrf_drv_timer_ms_to_ticks() to nrf_drv_timer_us_to_ticks()), but increasing the timer frequency could be good to get better accuracy in the timer compare register.

    3. The SAADC peripheral support double buffering, allowing you to sample to one buffer while processing the previously filled buffer. You could just as well have used two separate variables.

    4. The SAADC always use EasyDMA to store samples directly in the buffer in RAM.

    5. The NUS example is limited by the BLE configuration. If you increase MTU size and enable DLE, NUS can support more than 20 bytes. Please have a look at this blog post to understand the different parameters.

Children
No Data
Related