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

the timer is 6 times faster

I updated a working project based on nRF52832_xxAA 32Mhz crystal, from nRF5 SDK 14.2.0 to nRF5 SDK 16.0.0

now the timer is 6 times faster,
the code hasn't changed
is there any setting i miss?

const nrf_drv_timer_t TIMER_SYS = NRF_DRV_TIMER_INSTANCE(1);
#define TIMER_PERIOD      10         /**< Timer period. System timer will expire every 10 ms */

void TIMER_Init(void)
{
    uint32_t time_ticks;
    uint32_t err_code = NRF_SUCCESS;

    //Configure TIMER for 10ms interval
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    err_code = nrf_drv_timer_init(&TIMER_SYS, &timer_cfg, timer_sys_event_handler);
    APP_ERROR_CHECK(err_code);
    time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_SYS, TIMER_PERIOD);
    nrf_drv_timer_extended_compare(
         &TIMER_SYS, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
	nrf_drv_timer_enable(&TIMER_SYS);
}

Parents
  • Are you sure you are seeing 6 times the speed, and not 8 or 4? The reason I ask is because it sounds like a prescaler setting. Check out the example in SDK\examples\peripheral\timer.

    My guess is that during your porting, you have missed some sdk_config.h definitions or something.

    Try to debug nrf_drv_timer_init() and see if the number of ticks set is correct, and if it is not, why it is not set correctly.

    BR,

    Edvin

  • I use default (16 MHz)

    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    err_code = nrf_drv_timer_init(&TIMER_SYS, &timer_cfg, timer_sys_event_handler);

    the strange thing is that if set TIMER_PERIOD to 1ms OK  2ms OK,  > 2ms the time is wrong

    time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_SYS, TIMER_PERIOD);
    nrf_drv_timer_extended_compare(
    &TIMER_SYS, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
    nrf_drv_timer_enable(&TIMER_SYS);

    What could it be?

    I would need it at 10ms but for this problem I set it at 2ms

Reply
  • I use default (16 MHz)

    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    err_code = nrf_drv_timer_init(&TIMER_SYS, &timer_cfg, timer_sys_event_handler);

    the strange thing is that if set TIMER_PERIOD to 1ms OK  2ms OK,  > 2ms the time is wrong

    time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_SYS, TIMER_PERIOD);
    nrf_drv_timer_extended_compare(
    &TIMER_SYS, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
    nrf_drv_timer_enable(&TIMER_SYS);

    What could it be?

    I would need it at 10ms but for this problem I set it at 2ms

Children
Related