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

Advertising and Fast ADC Sampling

Hi, I am a newbie. I understand that a similar question was asked earlier, but I couldn't get an answer specific to my questions. My goal is to sample an analog signal at 40 KHz with 8 bit resolution, do some processing and advertise one integer value as manufacturer specific data. I understand from S110_SoftDevice_Specification_2.0 that the CPU halts during BLE events and there is advertising latency. Without the SoftDevice, I can do this as the ADC of nrf51822 (Rev3) can sample at 50KHz with 8 bit resolution. With the SoftDevice however, I can only sample at 1KHz. Is it possible to actually sample at 40 KHz with the SoftDevice? If not, what's the maximum sampling rate that I can get? Will the Time Slot API help? Thanks in advance!

  • FormerMember
    0 FormerMember

    With the recent S110 softdevices I think the processor load is much less intensive. I've a setup working with sampling at around 1.5 kHz while having a fast connection. I use the timer event to send a PPI task to start ADC sampling and with high priority ADC IRQ get it before the next time it samples.

    If you are looking only for advertisements I would suggest going bare metal without Softdevice as this gives you much more control.

  • How long for and how often do you need to do the sampling? The timeslot API will give you a fairly long slot if you ask for it, but you'll get it at random times, the longer the slot you want, the more random the times you'll get it.

    If all you're doing is advertising the value, you could just turn off advertising, shutdown the softdevice, do your sampling and calculation, then turn it all on again and advertise your value until the next time.

  • What you did not mention is how you are timing your ADC acquisition. Are you using a busy loop approach where you take a reading, sleep for 25uS (period of a 40KHz) and then acquire again or are you using a timer?

    If you use a busy loop, it will be much more sensitive to soft device events than a timer based approach.

    In a timer based approach, you set a timer for your sample period and use that timer to trigger the next acquisition. That way the CPU spends as much time as possible "idle" and the soft device does not have to compete with 100% processor load of a no-op busy loop.

    I can't promise 40KHz is achievable, I think it should be. But if you can only achieve 1KHz, you're probably doing it wrong.

    Hope that helps. David

  • I think the limitation of ADC sampling frequency with the S110 softdevice is described sufficiently in this blog post. With second revision nRF51 it is, 150Hz-1kHz depending on the BLE load. With 3rd revision nRF51, it is approximately 2kHz.

    If you need continuous 40kHz sampling frequency, the only option is to go for nRF52 where the SAADC uses EasyDMA. If you need to sample only periodically, then you can use RK's method.

Related