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

Can we implment PWM Analyzer on SDK 11?

I need to implement a PWM analyzer. I looked at the example in SDK 6 and it's fairly easy to follow. When I tried it, it doesn't look like GPIOTE handler gets called frequently enough. Is there a better recommendation to calculate duty cycle other than using GPIOTE that will do a good job sensing the rise and drop?

Parents
  • The peripherals use a 16 MHz clock, which is a limiting factor when measurements are performed using PPI. Using GPIOTE and a timer connected via PPI as the pwm_analyzer example in SDK 6 is a sensible way of doing the measurements. You can also use a comparator instead of GPIOTE.

    If the frequency of the PWM signal you are analyzing is too high compared to what you are measuring with, you could consider low pass filtering the PWM signal and using the ADC. This will have a few disadvantages, though. It will require an external RC filter and will have lower accuracy.

    A few questions:

    • What is the maximum frequency of the PWM signal you need to analyze?
    • Are you using nRF52 or nRF51?
  • You should have no problem measuring frequencies of up to 25 kHz using a timer together with a comparator or gpiote using PPI. This way, connecting the peripherals with PPI, the actual measurement will be done in hardware, and you only need software to configure and process the measurements.

    One thing I can think of that can give problems is that the way it is implemented in the example in SDK 6, you need to sample two consecutive low-to-high (or opposite) transitions in order to determine the duty cycle. While you should have more than enough time, this may not be the case if there is something else happening, such as higher priority interrupts of SoftDevice activity. One way around this is to ensure that the GPIOTE_IRQHandler() has the highest application interrupt priority. If you are using the SoftDevice you should make sure it will not interrupt either, which you can do using for example the timeslot API.

Reply
  • You should have no problem measuring frequencies of up to 25 kHz using a timer together with a comparator or gpiote using PPI. This way, connecting the peripherals with PPI, the actual measurement will be done in hardware, and you only need software to configure and process the measurements.

    One thing I can think of that can give problems is that the way it is implemented in the example in SDK 6, you need to sample two consecutive low-to-high (or opposite) transitions in order to determine the duty cycle. While you should have more than enough time, this may not be the case if there is something else happening, such as higher priority interrupts of SoftDevice activity. One way around this is to ensure that the GPIOTE_IRQHandler() has the highest application interrupt priority. If you are using the SoftDevice you should make sure it will not interrupt either, which you can do using for example the timeslot API.

Children
No Data
Related