How to retrigger one shot timer in SAMD20

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

I'm using SAMD20 on a custom board using Atmel Studio and Start project.

 

I have setup a one shot timer that fires as expected. After some time I want to start the one shot timer again but I'm unable to get it to work.

 

Here is how I setup the timers the first time.

void si_timer_init(void)
{
    timer_task_1.interval = 1500;
    timer_task_1.cb       = timer_cb_fast_blink;
    timer_task_1.mode     = TIMER_TASK_REPEAT;

    timer_task_2.interval = 6000;
    timer_task_2.cb       = timer_cb_slow_blink;
    timer_task_2.mode     = TIMER_TASK_REPEAT;

    timer_task_3.interval = 75000;
    timer_task_3.cb       = timer_cb_check_temp;
    timer_task_3.mode     = TIMER_TASK_ONE_SHOT;

    timer_add_task(&TIMER_0, &timer_task_1);
    timer_add_task(&TIMER_0, &timer_task_2);
    timer_add_task(&TIMER_0, &timer_task_3);
    timer_start(&TIMER_0);
}

 

And this is how I try to restart the one shot timer:

 

void restart_oneshot_timer()
{
    timer_stop(&TIMER_0);

    timer_task_3.interval = 75000;
    timer_task_3.cb       = timer_cb_check_temp;
    timer_task_3.mode     = TIMER_TASK_ONE_SHOT;
    timer_add_task(&TIMER_0, &timer_task_3);
    
    timer_start(&TIMER_0);
}

When I run the above code, all timers stop working. I've also tried adding the task without using timer_stop(), timer_start() but that made no difference. Any clues on how I can get the one shot timer to fire again?

 

TIA

Yogi

This topic has a solution.
Last Edited: Sun. Sep 24, 2017 - 04:52 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Got it! All we have to do is timer_add_task(...) without stopping or starting the timer and it works :-)