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

COUNTER starts at zero (0)

Hello,

I am creating an application that counts the number of times the button is pressed (Every high to low transition).

I am using GPIOTE to sense the high-to-low events. I have used PPI to connect the GPIOTE event to trigger the COUNT and CAPTURE task of the Timer/Counter.

If Button_0 is pressed, the system increments the counter. If Button_1, it clears the timer.

However, I have the following output:

I am wondering why the counter starts counting at Zero.

Please see the attached blinky.rar

Project Path: blinky\pca10040\blank\ses\blinky_pca10040.

Thank you!

  • Hi,

    The COUNT and CAPTURE tasks do not happen sequentially when you are triggering these from the same event over PPI, this will trigger HW signals that will reach the TIMER endpoints at approximately the same time. The counter inside the TIMER will start out with a value of 0 until the COUNT task has been triggered. Since you trigger the COUNT and CAPTURE tasks at the same time, the capture will most likely happen before the counter has been incremented. Have you tried triggering the capture in the BSP event handler before reading out the CC register?

    Best regards,
    Jørgen

  • Hi Jørgen,

    Yes, I have tried that. That was actually my original approach. I only used PPI to trigger the COUNT task and do the capture on the BSP event handler. It works.

    Thanks for your response. I was actually just trying to experiment with the PPI. Now it's clear that tasks do not happen sequentially when using PPI. Thank you!

    Jade

Related