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

Timer is not stable(phase/duty change all the time).

Dears, I am working for an application on [email protected] including PWM, Timer and a few peripheral functions. I was trying to create a timer on timer1 in us tick. The timer was created, but not stable. I implemented a pin toggle in timer even handler to check the timer stability. The only way to get a stable output pin toggle signal is that set the timer priority to 1(original is 3), but it will cause the system crash. Is there any mistake I implemented the timer for us application?


void sTimerInit(void) { uint32_t time_us = 20; //Time(in micro-seconds) between consecutive compare events. uint32_t time_ticks; uint32_t err_code = NRF_SUCCESS;

//Configure TIMER_LED for generating simple light effect - leds on board will invert his state one after the other.
nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
err_code = nrf_drv_timer_init(&TIMER_COUNTER_IR, &timer_cfg, timer_led_event_handler);
APP_ERROR_CHECK(err_code);

time_ticks = nrf_drv_timer_us_to_ticks(&TIMER_COUNTER_IR, time_us);

nrf_drv_timer_extended_compare(
     &TIMER_COUNTER_IR, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);

nrf_drv_timer_enable(&TIMER_COUNTER_IR);

}

Parents
  • FormerMember
    0 FormerMember

    Could you share more of your code so that it is easier to get an overview?

    It is most likely not related, but what is the value returned by nrf_drv_timer_us_to_ticks()? From what I can see, the arguments should be the time in microseconds and the frequency of the timer..

  • Hello Kristin, Thanks for your reply. Should I open the complete C code to you? Please let me know if any questions. I have doubt as you mentioned. But also as I mentioned, it will get stable when I changed the priority of Timer to 1.(// Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice) The value from nrf_drv_timer_us_to_ticks() is 0x140. I think it could the reason of the other timers againsting the timer1 when I set it as priority 3.

Reply
  • Hello Kristin, Thanks for your reply. Should I open the complete C code to you? Please let me know if any questions. I have doubt as you mentioned. But also as I mentioned, it will get stable when I changed the priority of Timer to 1.(// Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice) The value from nrf_drv_timer_us_to_ticks() is 0x140. I think it could the reason of the other timers againsting the timer1 when I set it as priority 3.

Children
No Data
Related