cancel
Showing results for 
Search instead for 
Did you mean: 

STM8S timer is working properly

Chayan Roy
Associate III
Posted on February 26, 2017 at 14:43

The original post was too long to process during our migration. Please click on the attachment to read the original post.
4 REPLIES 4
Max
ST Employee
Posted on February 27, 2017 at 04:57

Hello,

First remark, I think you should not use READ-MODIFY-WRITE operation when you are clearing hardware register flags.

If another event happens between the READ operation and the WRITE operation, you will end up clearing the new event without knowing it (therefore missing it...).

For example, I recommend to replace :

TIM2_SR1 &=~(1<<0);  // READ TIM2_SR1; AND with ~(1<<0) ; WRITE back to 

TIM2_SR1

by

TIM2_SR1 =~(1<<0); // WRITE 

~(1<<0) to TIM2_SR1

the register is described as rc_w0 meaning 'read and clear only by writing 0', it means that writing one wont change the content.

regards,

Max

Chayan Roy
Associate III
Posted on February 27, 2017 at 05:16

Hi Max,

Many many Thanx for your valuable suggestion. I have done the modification you  have suggested, but unfortunately the problem still remains. Timer 1 stops responding when ever.any environmental disturbance occurs. Its very wired problem for me, I have never seen this kind of problem before.

Posted on February 27, 2017 at 09:07

With your code, it seems the same thing could happen with 

TIM1_CR1 because it is being modified inside the interruption.

Ask yourself what would happen if the interruption happens in the middle of the 

READ-MODIFY-WRITE operation...

I recommend to use the debug mode to understand the status of TIM1 when your problem happen (ON/OFF, pending bit...).

This kind of issue looks to me like one interrupt happening at the wrong time...

Chayan Roy
Associate III
Posted on February 27, 2017 at 11:12

Hi Max,

Thanx buddy,  I got your point.