This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

High Sample Rate with ADC and SoftDevice

I am trying to sample the ADC every 2ms. I notice lots of slowness with BLE advertising and typically can't connect to device over BLE when sampling. I am using PPI, configuring, and starting before the softdevice is enabled.

  1. Should nRF51822 be capable of reading ADC every 1ms to 2ms reliably?

  2. Should I move all the PPI configuration to after the softdevice is enabled and be using the sd_ppi functions?

Thanks!

Edit: Headline, format, added tags.

  • Hi Stefan,

    This sample was very helpful to me - thanks. When you wrote about "accuracy of the ADC" are you referring to the accuracy of when the ADC samples, or the measurement error of the ADC?

    Also, why do we need to set the priority of the ADC interrupt explicitly to LOW? Is this to solve the problem Chris had where he can't connect to device over BLE when sampling the ADC?

    And one more question - I have some ADC samples that need high accuracy (so I'll use the external crystal), and some that don't (so I'll use the internal RC). Is it necessary to check if the crystal is running before stopping it, like this:

    
    		uint32_t p_is_running = 0;
    		sd_clock_hfclk_is_running((&p_is_running));
    		if (p_is_running)
    		{
    			sd_clock_hfclk_release();
    		}
    
    

    Or is it fine to just call sd_clock_hfclk_release() all the time, regardless of whether it's actually running or not?

  • Hi Stefan

    The accuracy which I am refering to is according to the ADC specfication in table 38 in the nRF51822 PS v1.3. This specification applies to accuracy of perceived ADC output when applying a known voltage source to the ADC input.

    You need to set the priority of the ADC interrupt to LOW in order to be able to call a softdevice function, starting with sd_. Otherwise you will get a hard fault.

    The example has been working fine just by calling sd_clock_hfclk_release and sd_clock_hfclk_request directly. While the softdevice is enabled it has control over the 16MHz crystal. Any sd_ function is a wrapper function implemented in the softdevice which should not allow the application to do any undesirable things to peripherals that the softdevice is in control of. So the method introduced in the example should be just fine.

  • Hi Stefan

    The accuracy which I am refering to is according to the ADC specfication in table 38 in the nRF51822 PS v1.3. This specification applies to accuracy of perceived ADC output when applying a known voltage source to the ADC input.

    You need to set the priority of the ADC interrupt to LOW in order to be able to call a softdevice function, starting with sd_. Otherwise you will get a hard fault.

    The example has been working fine just by calling sd_clock_hfclk_release and sd_clock_hfclk_request directly. While the softdevice is enabled it has control over the 16MHz crystal. Any sd_ function is a wrapper function implemented in the softdevice which should not allow the application to do any undesirable things to peripherals that the softdevice is in control of. So the method introduced in the example should be just fine.

  • Ok,

    I don't have any experience developing code for nrf51822, but I want to buy a evaluation kit and start developing. Currently I'm working with atmega328, but I want to try making my app work on a nrf51822.

    I have a pulse sensor that triggers an interrupt every 2ms reading a value on ADC, so as far as I read that can't be done on the nrf?

    Thanks!

  • Hi Vlad

    Well, as mentioned previously, this depends on the amount of data you want to send in each connection interval. If you only need to send 1 or two packets per connection interval then you should be able to read the ADC every 2 milliseconds. So if you need to send ~20 kbps or less in one direction, then you should be able to sample every 2 ms (500 Hz).

Related