cancel
Showing results for 
Search instead for 
Did you mean: 

Addition Problem

ZExpo.1
Senior

Hi,

    I am doing something fundamental and cannot get this thing running.

 

 

n =(TIM1->CNT);
z= n + 3;

	  

 

 

for the first loop cycle 'z' is =3 This is as expected, But as soon as the CNT is increased by 1 the value of 'z' is 4 as shown

LOOP COUNTCOUNTER VALUESVARIABLE WITH +3 OPERATION
12023
22124
32225
42326
52427
   
8 REPLIES 8
Issamos
Lead II

Hello @ZExpo.1 

In the table you give, the difference between CNT and S is always 3. I don't see any problem.

Best regards.

II

You're not really explaining the problem very well. You're not showing any loops, and how they would relate to a counter in an independent timer.

The count will keep counting. The bus interactions in a load-store sense might take longer to execute than you expect.

Things like TIM3->CNT += 3; might actually make the counter go backward, or at least glitch/saw-tooth. Depends on the frequency and the number of cycles on the AHB/APB buses

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Yes, I did a logical error here, If I am adding +3 to the counter variable then I will be getting +3, I want to Create a table like this-

The initial Counter Value Should be 20

Value 2 =23

Value 3 =26

value 4= 29

.....

So on
Here Counter is driver by a Rotary Encoder which will have a limited range of 12 Dents only.

uint8_t N[100];

N[0]= =(TIM1->CNT);

For (i=1;i<100;I++)

{.     

          N[i] = N[0]+i*3;

}

Best regards

II 

TDK
Guru

Creating a table isn't really specific to a timer and doesn't have a whole lot of use.

Why don't you take a step back tell us what you're trying to achieve? Why is this table needed?

If you feel a post has answered your question, please click "Accept as Solution".

You can limit the count of the encoder by using TIM->ARR = 12 - 1; // Giving range 0 .. 11 [12 values]

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ZExpo.1
Senior

I want to generate the following numbers using my rotary encoder

Encoder dent 1->20

Enoder Dent 2    -> 23

Encoder Dent 3  -> 26

.

.

.

.

.

.

.

.

 

.

.

.

Dent 12->53

 

TDK
Guru

Okay, so dent = 17 + 3 * i; But how does that help you?

If you feel a post has answered your question, please click "Accept as Solution".