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

PWM analyzer / Pulse counter

Is it possible to count pulses with the 51822 from an external device in the range of 250-15.000 pulses pr. second, while the CPU is powered down (softdevice sleep)?

I've had a look at the pwm_analyzer sample, which might do the trick. But I'm not familiar with all the GPIOTE events and tasks. and I'm a little unsure that the resolution is high enough for this purpose. As far as I can tell the example measures both the low and high duty cycles, and firing an interrupt after right after it has measured the high cycle.

I'm not particular interested in generating an interrupt for this reading, as I would rather read the results while the BLE stack is executing to avoid extra wake-up cycles. But according to the example, it seems there is no specific code that restarts the events/task. So I guess it means that they will continuously provide the result to the registers.

Am I totally off here or is there an easier way to simply count the number of pulses from an external device?

Looking at the Timer description in the reference manual, it can also operate in a counter mode triggered by a COUNT task. Is it possible to setup a GPIO pin to trigger that task by a lo-hi transition? This way I can simply read the register whenever the SD is awake and do the frequency calculation based on the time elapsed since last read.

Parents
  • Ok, since the frequency is that low, then perhaps, as you have pointed out, there is not so much power to save by periodically enable the peripherals. However, if your average pulse frequency is e.g. 50 Hz, and you need to measure on average perhaps 3 times a second, then the method would pay off since you would only have the peripherals enabled 6% of the time. On the other hand, if your pulse freqency at any instance is down to 4 Hz and you are measuring 5 times a socond, it is not going to work.

    However, if the above method would work, you could use RTC timer instead of TIMER to measure the pulse, which is very low power. This should be adequate since your max frequency is only 250Hz. Current consumption is <1uA for RTC+LFCLK if you use 32kHz external crystal as the low frequency clock source. If you use the internal 32kHz RC clock source, the current consumption is ~10uA with calibration to obtain 250ppm accuracy, see this thread.

    Example code for TIMER in COUNTER mode is found on Nordic's Github

Reply
  • Ok, since the frequency is that low, then perhaps, as you have pointed out, there is not so much power to save by periodically enable the peripherals. However, if your average pulse frequency is e.g. 50 Hz, and you need to measure on average perhaps 3 times a second, then the method would pay off since you would only have the peripherals enabled 6% of the time. On the other hand, if your pulse freqency at any instance is down to 4 Hz and you are measuring 5 times a socond, it is not going to work.

    However, if the above method would work, you could use RTC timer instead of TIMER to measure the pulse, which is very low power. This should be adequate since your max frequency is only 250Hz. Current consumption is <1uA for RTC+LFCLK if you use 32kHz external crystal as the low frequency clock source. If you use the internal 32kHz RC clock source, the current consumption is ~10uA with calibration to obtain 250ppm accuracy, see this thread.

    Example code for TIMER in COUNTER mode is found on Nordic's Github

Children
Related