AnsweredAssumed Answered

Use of timers with large software

Question asked by colla.ivan on Sep 13, 2016
Latest reply on Sep 14, 2016 by Erwan Y
Good day to everyone,

I am writing here in order to have some suggestions on the use of timers. 
I am writing a spc5 application whee I have a lot of operations and I must do various things at specific moments. For example, I have to change the vlaue of a pin every millisecond.

In order to do this, I read the value of the counter in STM module and use that in a code like the following.

if ( (STM.CNT.R - startTime)  > ONE_MILLISECOND) 
{ /* Do operation. */}

startTime is initialized with the startting value of the STM.CNT.R counter. Then I use the statement to verify when a number of counter ticks corresponding to 1 ms is passed.

The problem is that I have many operations. So, when the code returns to the above statement, more than 1 ms is already passed. Obviously the condition is verified and the code in the if block is executed, but too late.

Somebody has some suggestion on how this type of problem can be resolved?

Thanks,
Ivan 

Outcomes