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

Timer not correct?

Now,I use a 1s timer to calculate the clock. At first,I use the telephone to adjust the time to fit the telephone time. but finally(after a night ) the result runs fastly compared with the telephone. For example,the telephone time is 8:40,but the devices are 8:42 or 8:46. The code is:

#define APP_TIMER_PRESCALER    0
#define CLOCK_MEAS_INTERVAL    APP_TIMER_TICKS(1000,APP_TIMER_PRESCALER)

static void ble_stack_init(void)
{
  SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM,NULL);
}
create the timer:
app_timer_create(&m_clock_timer_id,APP_TIMER_MODE_REPEATED,clock_meas_timeout_handler);
start the timer:
app_timer_start(m_clock_timer_id,CLOCK_MEAS_INTERVALL,NULL);


static void clock_meas_timeout_handler(void *p_context)
{
 UNUSED_PARAMETER(p_context);
 clock_process();//calculate the time
}

The function of clock_process() is dealling with the clock time,but the result as describe above.

Parents
  • I understand that you can't just run the clock timer in a project, I only try to figure out why it does not work.

    It may be best if you let me see the code so I can see what is going on and try to reproduce it here. If you don't want to share it on Devzone you can open a case on mypage.

    You can use PPI to generate the clock timer, but in combination with the app_timer this will be hard.

  • I have created other timers.

    void timers_init()
    {
     APP_TIMER_INIT(APP_TIMER_PRESCALER,APP_TIMER_MAX_TIMERS,APP_TIMER_OP_QUEUE_SIZE,false);
    err_code = app_timer_create(&m_sec_req_timer_id,APP_TIMER_MODE_SINGLE_SHOT,sec_req_timeout_handler);//for ancs
    
    err_code = app_timer_create(&m_clock_timer_id,APP_TIMER_MODE_REPEATED,clock_meas_timeout_handler);//for clock timer ------1s
    
    
    app_timer_create(&m_acc_timer_id,APP_TIMER_MODE_REPEATED,acc_meas_timeout_handler);//for acc timer------20ms
    
    app_timer_create(&m_pulse_timer_id,APP_TIMER_MODE_REPEATED,pulse_meas_timeout_handler);//for acc timer------25ms
    
    app_timer_create(&m_sec_timer_id,APP_TIMER_MODE_REPEATED,sec_meas_timeout_handler);//for some timer things-----1s
    
    app_timer_create(&m_button_timer_id,APP_TIMER_MODE_REPEATED,button_meas_timeout_handler);//for button events----100ms
    }
    
Reply
  • I have created other timers.

    void timers_init()
    {
     APP_TIMER_INIT(APP_TIMER_PRESCALER,APP_TIMER_MAX_TIMERS,APP_TIMER_OP_QUEUE_SIZE,false);
    err_code = app_timer_create(&m_sec_req_timer_id,APP_TIMER_MODE_SINGLE_SHOT,sec_req_timeout_handler);//for ancs
    
    err_code = app_timer_create(&m_clock_timer_id,APP_TIMER_MODE_REPEATED,clock_meas_timeout_handler);//for clock timer ------1s
    
    
    app_timer_create(&m_acc_timer_id,APP_TIMER_MODE_REPEATED,acc_meas_timeout_handler);//for acc timer------20ms
    
    app_timer_create(&m_pulse_timer_id,APP_TIMER_MODE_REPEATED,pulse_meas_timeout_handler);//for acc timer------25ms
    
    app_timer_create(&m_sec_timer_id,APP_TIMER_MODE_REPEATED,sec_meas_timeout_handler);//for some timer things-----1s
    
    app_timer_create(&m_button_timer_id,APP_TIMER_MODE_REPEATED,button_meas_timeout_handler);//for button events----100ms
    }
    
Children
No Data
Related