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

NRF51822 Capability

I'm trying to figure out if the NRF51822 is capable of performing the tasks I need for my project. I need to be able to do the following

4x PWM at ~2kHz

4x Analog read at ~2kHz

1x Periodic Battery Level read

2x GPIO interrupt

2x Timer (trigger battery read & flash heartbeat LED)

S110 Softdevice

Is the nrf51822 capable of doing all this? I believe it only has 4 GPIOTE channels and I'm assuming I would need to use all 4 for the PWM. Is there a way to still achieve the ADC reads at that rate?

I should note, that this development is supposed to be done on top of an existing application which is using soft device S110 v7.1

  • Hi,

    As described in the PWM library documentation, 4 PWM channels will require 4 GPIOTE channels + 12 PPI channels (2 per instance + 2 per channel, each instance providing 2 channels = 22 + 42 = 12). The S110 v7.1 softdevice is based on the S110 softdevice specifications v1.3. From the chapter about PPI resource usage, you can see that this softdevice only leaves PPI channel 0-7 to the application, the rest is used by the softdevice. If you upgrade the softdevice to S110 v8.0 (based on S110 SDS v2.0), you will get 14 available PPI channels, which should be sufficient for the PWM instances.

    The next issue is the GPIO interrupts. This will require available GPIOTE channels, which you allready used for the PWM channels. You can still use GPIOs to wake the chip from System OFF sleep mode, but I don't know what your inputs are or what your will be using these for. Another alternative might be to use the LPCOMP peripheral to detect falling/rising edge of the inputs. If you need 4 analog reads + 1 analog read for battery voltage, you still have 3 available analog inputs, and can use 2 of these to generate interrupts in place of your GPIO interrupts.

    The softdevice will block usage of TIMER0 peripheral, but you still have two more timers available. You need 1 timer for each of the PWM instances, which means you do not have any timers left for triggering ADC sampling and LED blinking. An alternative is to use RTC to trigger these tasks. The softdevice blocks use of RTC0, but RTC1 is available to the application. You can setup the application timer library to use RTC1 and generate multiple timers. The RTC runs at a frequency of 32.768 kHz, but this should be sufficient for your sample rate.

    If your application can run reliably with all these peripherals running at the same time, you will have to test yourself. Note that the softdevice will allways get highest priority for timing critical tasks, which might delay interrupts for PWM, ADC and GPIO/LPCOMP. According to this post, you should be able to achieve a sample rate of 2-8 kHz, depending on the amount of data you send via BLE. When running multiple other interrupt-intensive peripherals like PWM, you might not be able to get to this level.

    I think you will have som troubles getting all this to work on the nRF51822 chip, but if this is an existing project, it might be worth a try. I would really recommend considering moving to the nRF52 series, as this provide hardware PWM peripheral, in addition to EasyDMA which allows you to sample the ADC directly to RAM. The nRF52832 also have more TIMERs, RTCs, GPIOTE channels, and more flexible PPI channels.

    Best regards,

    Jørgen

  • One more thing, I realized that the link I posted in the above answer about sample rates in the ADC with softdevice enabled is with only 1 channel enabled. You will have to divide the expected maximum sample rate on the number of enabled channels, giving you 400 - 1600 Hz maximum sample rate.

  • Thanks for the detailed reply! I didn't realize how limited SD 7.1 is with the PPIs.

    As for the GPIO interrupts, these are very low speed and low frequency signals- would I not be able to use the GPIOTE>PORT for interrupt still even if all 4 channels are being used for the PWM?

    Also, for the ADC as far as I know the measurement takes on the order of 20us. Why would I need to divide the expected sample rate by the number of channels? If I sampled each one consecutively after a timer event triggers for example I would expect that I would be able to perform 4 measurements in a couple 100us. I thought the bigger limiting factor for this is that the SD blocks the processor every BLE interval.

  • Also you mention that I will need 1 timer for each of the PWM instances. Does that mean 4 total or 1 for all 4 instances? If the former and there are only 2 timers free it sounds like I couldn't even do the 4 PWM channels.

  • If the GPIOTE channels are used for PWM, they are not available to use with GPIO. If the usage does not overlap in time, it is possible to setup the GPIOTE channels for GPIO interrupts at one time and use for PWM at another non-overlapping time.

    Yes, the ADC have a conversion time of 20µs per channel on the lowest setting. With 5 channels enabled, the total conversion time will be 100µs, or a theoretical maximum sample frequency of 10 kHz. If you have heavy BLE activity, this will limit the time that ADC interrupts can be handled, which will reduce the max sample rate. With many interrupts happening for the PWM interfaces as well, this will further limit the time available for ADC sample interrupt handling.

    The PWM library require 1 timer for each instance of the library, where one instance can provide two PWM channels. This is why it will require 2 timers in total for 4 PWM channels.

Related