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

nRF52 timer has no modulus?

I'm learning about the nRF52 series and so far love everything I see, especially the SDK. But I just got to the point where I'd like to generate precisely timed output, and there is something I don't understand: the nRF52832 timer seems to have no modulus (wraparound) setting. From what I understand, you can set the prescaler and the bit width, but the timer will still run over the full range of values allowed by the bit width.

This seems to imply that you can't produce arbitrary PWM output, only a specific set of PWM periods is supported.

Am I missing something?

  • Hi Jan

    What you are probably missing is the SHORTS register, which allows you to enable a shortcut between any of the compare events and the clear task. With this enabled you can assign one of the CC registers to act as a reload register, and have the timer reset every time the value in the CC register is reached.

    Codewise it would look something like this:

    NRF_TIMER0->CC[3] = 1000;   
    NRF_TIMER0->SHORTS = TIMER_SHORTS_COMPARE3_CLEAR_Msk;   
    NRF_TIMER0->TASKS_START = 1;
    

    As a side note, if what you need is PWM I would recommend using the dedicated PWM modules. They can also be configured with an arbitrary reload value, in the range 2-(2^15), and allow you to update the duty cycle directly from a RAM buffer without requiring MCU interaction.

    Best regards
    Torbjørn

  • Yes! Thank you — this seems to be what I was missing. While reading the specs I thought to myself: there is no way they could have designed an otherwise great chip with such a limitation.

    I will have to figure out how exactly this clearing works out cycle-wise, but I'm very glad it's there. And yes, for PWM I will definitely use the PWM modules, I just used it as an example. At the moment I actually need specific timer periods.

Related