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

Why does toggling a GPIO pin happen in constant time, but not set and clear for GPIO?

In testing the timers on the dongle, I have made a GPIO pin be controlled by the timer triggering.

So the following has a constant time between edges:

    case NRF_TIMER_EVENT_COMPARE1:
        nrf_gpio_pin_toggle(DBG_TIMING_PIN_1); // This happens with a constant spacing between signal edges
        break;

While this does not:

    case NRF_TIMER_EVENT_COMPARE1:
        // This creates a small impulse, but the timing between these impulses vary
        nrf_gpio_pin_set(DBG_TIMING_PIN_1);
        nrf_gpio_pin_clear(DBG_TIMING_PIN_1);
        break;

Am I understanding the GPIO library incorrectly? The first piece of code generates a 50ms pulse between edges, while the second one produces a varying width pulse between each impulse.

Parents
  • Hi,

    So the following has a constant time between edges:

    The first piece of code will invert (toggle) the GPIO on every time the NRF_TIMER_EVENT_COMPARE1 occurs. 

    While this does not:

     This second piece of code will set and clear within the NRF_TIMER_EVENT_COMPARE1 interrupt, and you'll see a short pulse every 50 ms (that seems to be your CC value)

     

    It'll look like this if you scope and compare the two:

     

    Kind regards,

    Håkon

  • Hi, perhaps my question would be more clear if I asked to compare it set then clear with toggling twice:

    double_toggle:

        case NRF_TIMER_EVENT_COMPARE1:
            nrf_gpio_pin_toggle(DBG_TIMING_PIN_1);
            nrf_gpio_pin_toggle(DBG_TIMING_PIN_1);

    which produces the following waveform that I expect

    compared to set_then_clear:

        case NRF_TIMER_EVENT_COMPARE1:
            // This creates a small impulse, but the timing between these impulses vary
            nrf_gpio_pin_set(DBG_TIMING_PIN_1);
            nrf_gpio_pin_clear(DBG_TIMING_PIN_1);
            break;

    which produces pulses at random times and sometimes according to the timer.

    I am looking at the time between of the pulses and not the width of the pulse high-level.

    Both tests were done on the same piece of code without changing any other lines. Is this a bug in the SDK?

Reply
  • Hi, perhaps my question would be more clear if I asked to compare it set then clear with toggling twice:

    double_toggle:

        case NRF_TIMER_EVENT_COMPARE1:
            nrf_gpio_pin_toggle(DBG_TIMING_PIN_1);
            nrf_gpio_pin_toggle(DBG_TIMING_PIN_1);

    which produces the following waveform that I expect

    compared to set_then_clear:

        case NRF_TIMER_EVENT_COMPARE1:
            // This creates a small impulse, but the timing between these impulses vary
            nrf_gpio_pin_set(DBG_TIMING_PIN_1);
            nrf_gpio_pin_clear(DBG_TIMING_PIN_1);
            break;

    which produces pulses at random times and sometimes according to the timer.

    I am looking at the time between of the pulses and not the width of the pulse high-level.

    Both tests were done on the same piece of code without changing any other lines. Is this a bug in the SDK?

Children
Related