Possibility to read the current timer value

Hi

Is there any way to read the current value of the nPM1300 timer?

This would allow to keep track of time while the CPU is not running or rebooting (in the absence of an external RTC)

Thanks

Parents
  • Edit: Sorry, no, this is not possible :) See comment from Dan.
    Yes, you can read the current value of the nPM1300 timer by accessing the TIMERHIBYTE, TIMERMIDBYTE, and TIMERLOBYTE registers. These registers represent the most significant byte, middle byte, and least significant byte of the timer respectively.

    TIMERHIBYTE: Address offset 0x8
    TIMERMIDBYTE: Address offset 0x9
    TIMERLOBYTE: Address offset 0xA

    You will find more details on TIMER in the nPM1300 documentation:
    https://docs.nordicsemi.com/bundle/ps_npm1300/page/chapters/core_components/timer/doc/frontpage.html

  • Hi, I've already tried to read that register.

    The value does not change while the timer is running (at least in General Purpose mode) :

    npmx_timer_t *timer = npmx_timer_get(&m_npmx, 0);
    const npmx_timer_config_t timer_cfg = {
        .prescaler = NPMX_TIMER_PRESCALER_SLOW,
        .mode = NPMX_TIMER_MODE_GENERAL_PURPOSE,
        .compare_value = 0xFFFFFF,
    };
    npmx_timer_config_set(timer, &timer_cfg);
    npmx_timer_task_trigger(timer, NPMX_TIMER_TASK_ENABLE);
    
    nrf_delay_ms(100);
    
    uint8_t timer_buffer[3] = {0};
    npmx_backend_register_read(m_npmx.p_backend, NPMX_REG_TO_ADDR(NPM_TIMER->TIMERHIBYTE), timer_buffer, 3);
    
    uint32_t timer_value = (
        (timer_buffer[0] << 16) |
        (timer_buffer[1] <<  8) |
        (timer_buffer[2] <<  0)
    );
    NRF_LOG_INFO("Timer value: 0x%x", timer_value);

    Output is: Timer value: 0xFFFFFF

Reply
  • Hi, I've already tried to read that register.

    The value does not change while the timer is running (at least in General Purpose mode) :

    npmx_timer_t *timer = npmx_timer_get(&m_npmx, 0);
    const npmx_timer_config_t timer_cfg = {
        .prescaler = NPMX_TIMER_PRESCALER_SLOW,
        .mode = NPMX_TIMER_MODE_GENERAL_PURPOSE,
        .compare_value = 0xFFFFFF,
    };
    npmx_timer_config_set(timer, &timer_cfg);
    npmx_timer_task_trigger(timer, NPMX_TIMER_TASK_ENABLE);
    
    nrf_delay_ms(100);
    
    uint8_t timer_buffer[3] = {0};
    npmx_backend_register_read(m_npmx.p_backend, NPMX_REG_TO_ADDR(NPM_TIMER->TIMERHIBYTE), timer_buffer, 3);
    
    uint32_t timer_value = (
        (timer_buffer[0] << 16) |
        (timer_buffer[1] <<  8) |
        (timer_buffer[2] <<  0)
    );
    NRF_LOG_INFO("Timer value: 0x%x", timer_value);

    Output is: Timer value: 0xFFFFFF

Children
No Data
Related