This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Need a dynamically changing time based interrupt on MSP430, use Clock or TImer in SYS/BOIS?

Using MSP430, need to have a time based interrupt generated which would not be running at the start of the program. This would be started based on external trigger and the rate at which would need to trigger is also based on external triggers, it would also need to be stopped and restarted based on external triggers. My main question is what is the ability to do this using a Timer or a Clock in SYS/BIOS, and what are the tradeoffs if both are available?

I have tried

    key = Hwi_disable();
    Timer_stop(myTimer);

    timer_set_status = Timer_setPeriodMicroSecs(myTimer, tickPeriodMicroSec);
    if (timer_set_status)
        Timer_start(myTimer);
    
    Hwi_restore(key);

Inside the SWI which got posted based on the timer trigger, but after adding that the timer would not trigger again.

I have seen API for Clock_start(), Clock_stop(): but I am unsure about the true meaning of the notes on these calls of
"Can only be called from the context of the Clock Swi"

I was thinking after the initial Clock_start(), when needing to change the trigger rate calling Clock_stop then calling Clock_setPeriod(), Clock_setTimeout(), then calling Clock_start to start triggering at the new rate, but I am not sure if that is possible given the above comment on the usage of Clock_start/Clock_stop

  • Hi George,

    For the situation you describe I think dynamically programming a Timer is the way to go.  The disadvantage is that it dedicates a timer peripheral for this purpose, but the advantages are that it is lighter weight than using Clock if there are no other timing services that are needed, and that there are less constraints on when the timer can be reprogrammed.  (I’ll work separately with you on the issue of using Timer for this.)  

    Using Clock has the advantage that it will share an underlying timer peripheral for other timed events, but the disadvantage is that when changes can be made are more constrained.  The requirement to call Clock_start()/Clock_stop() “from the context of the Clock Swi” essentially means calling during execution of the Clock object’s function when it is running, and is to avoid race conditions from changing Clock object parameters at times when it may cause issues with Clock’s ability to properly service its list of Clock objects.

    Scott