Understanding default Timer Configurations

[NRF52840] [NRFconnect v2.0.0]

Hi,

I'm attempting to use the Timer peripherals in counter mode to keep track of pulses on a certain pin. I was able to get this working well with Timer2 (which I picked arbitrarily). When I tried to use Timer1, it appears to be being used by something else. The count that I see in the CC register is no longer changing based on the pulses received, but is counting something else (not sure what it's counting).

My question is what other peripheral may be using Timer1 under the hood? I saw in the Nrf52840 data sheet that Timer0 is being used for bluetooth/radio so I understand why I couldn't use it. I also saw in my compiled DTS that the "sw_pwm: sw-pwm" node uses "<&timer2>" as its generator. (For my application this node is disabled, which is why I guess I can effectively use Timer2).

Is there anywhere that I can look to understand for sure which Timer instances I can use based on which other peripherals I have active for my application. Ultimately , I need to count pulses on a few different pins so will need multiple timer instances in the final application.

As a follow-up question I would like to make sure there isn't a more pragmatic way to configure the timer instances to count gpio interrupts. I'm not using an api like I do for most things which leaves me open to over-riding memory addresses that are being used by other peripherals if I'm not careful.

NRF_P0->PIN_CNF[FLOW_COUNT_PIN] = GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos |
                                   GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos |
                                   GPIO_PIN_CNF_SENSE_High << GPIO_PIN_CNF_SENSE_Pos;

    NRF_PPI->CHEN |= 1 << FLOW_PPI_CHANNEL;
    NRF_PPI->CH[FLOW_PPI_CHANNEL].EEP = (uint32_t)&NRF_GPIOTE->EVENTS_IN[FLOW_PPI_CHANNEL];
    NRF_PPI->CH[FLOW_PPI_CHANNEL].TEP = (uint32_t)&NRF_TIMER1->TASKS_COUNT;

    NRF_GPIOTE->CONFIG[FLOW_PPI_CHANNEL] = GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos |
                                      FLOW_COUNT_PIN << GPIOTE_CONFIG_PSEL_Pos |
                                      GPIOTE_CONFIG_POLARITY_LoToHi << GPIOTE_CONFIG_POLARITY_Pos;

    NRF_TIMER1->TASKS_STOP = 1;
    NRF_TIMER1->TASKS_CLEAR = 1;
    NRF_TIMER1->MODE = TIMER_MODE_MODE_LowPowerCounter << TIMER_MODE_MODE_Pos;
    NRF_TIMER1->BITMODE = TIMER_BITMODE_BITMODE_32Bit << TIMER_BITMODE_BITMODE_Pos;
    NRF_TIMER1->TASKS_START = 1;

Thanks!

Related