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
  • Hi

    Initial thoughts on this is that yes, you can use TIMER peripheral for this purpose and have it in COUNTER mode. Then the hardware will count the pulses and, as you say, you can make calculations to calculate the frequency based on the counter value. However, this will not be specifically low power, as TIMER peripheral constantly requires 16HMz clock to be enabled, so the operation will require ~1mA of current.

    However, if you intend only periodically to measure the frequency of the PWM signal, then it should be possible to monitor GPIO pin for signal transition, and let that signal transition start a TIMER. When the timer has been started, you configure the pin signal transition to stop the timer and trigger an interrupt so you can check the value of the timer and calculate the frequency. If you do not need to check the frequency very often, this method could be relatively low power, since you only need to enable the peripherals while you perform the measurement. Let me know if you would consider this method instead of the other one.

    What do you need to measure exactly, the duty cycle of the PWM or also the frequency?

Reply
  • Hi

    Initial thoughts on this is that yes, you can use TIMER peripheral for this purpose and have it in COUNTER mode. Then the hardware will count the pulses and, as you say, you can make calculations to calculate the frequency based on the counter value. However, this will not be specifically low power, as TIMER peripheral constantly requires 16HMz clock to be enabled, so the operation will require ~1mA of current.

    However, if you intend only periodically to measure the frequency of the PWM signal, then it should be possible to monitor GPIO pin for signal transition, and let that signal transition start a TIMER. When the timer has been started, you configure the pin signal transition to stop the timer and trigger an interrupt so you can check the value of the timer and calculate the frequency. If you do not need to check the frequency very often, this method could be relatively low power, since you only need to enable the peripherals while you perform the measurement. Let me know if you would consider this method instead of the other one.

    What do you need to measure exactly, the duty cycle of the PWM or also the frequency?

Children
No Data
Related