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

how can i make system tick funtion?

I know that nrf51822 is not supported system tick handler ? I need system tick function. How can i make system tick function for nrf51822?

Parents
  • If you need exactly 1 ms ticks, you will have to use the 16 MHz timers, since the low-frequency clock is 32.768 kHz (32768 Hz), giving ticks with a frequency of 32768/(32+1) = 992.96... Hz.

    The 16 MHz timers does not have a TICK interrupt, so to use them for such purpose, I'd recommend to set the PRESCALER register to something appropriate, set one of the CC values correctly and enable the COMPAREX_CLEAR shortcut, so that the timer restarts on each compare. After this, you can enable the COMPAREX interrupt in INTEN and the TIMERX interrupt in the NVIC, and then just start the TIMER and let it run.

    For completeness, making a tick is easier with the RTC; you just set the PRESCALER correctly, enable the TICK interrupt in INTEN and the RTC interrupt in the NVIC and then start the RTC. Remember to start the LFCLK before starting the RTC.

  • @Ole I'm sorry for making a confusion to you. I made code like to below for using 16Mhz system clock.

    /* Start 16 MHz crystal oscillator */ NRF_CLOCK->EVENTS_HFCLKSTARTED = 0; NRF_CLOCK->TASKS_HFCLKSTART = 1;

    /* Wait for the external oscillator to start up */
    while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)		
    {
    }
    NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;		
    

    after this routine, I would like to configure 1ms tick timer. I think that the 1ms tick timer seem to be made using timer interrupt(timerX_IRQn). So, Can I make the tick timer using 32.768Hz with system clock 16MHz? If this is possible, How can I make code?

    I look forward to wait for your detailed guide.

Reply
  • @Ole I'm sorry for making a confusion to you. I made code like to below for using 16Mhz system clock.

    /* Start 16 MHz crystal oscillator */ NRF_CLOCK->EVENTS_HFCLKSTARTED = 0; NRF_CLOCK->TASKS_HFCLKSTART = 1;

    /* Wait for the external oscillator to start up */
    while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)		
    {
    }
    NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;		
    

    after this routine, I would like to configure 1ms tick timer. I think that the 1ms tick timer seem to be made using timer interrupt(timerX_IRQn). So, Can I make the tick timer using 32.768Hz with system clock 16MHz? If this is possible, How can I make code?

    I look forward to wait for your detailed guide.

Children
No Data
Related