Skip to main content
ZExpo.1
Associate III
September 29, 2023
Question

Addition Problem

  • September 29, 2023
  • 8 replies
  • 2328 views

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
   
This topic has been closed for replies.

8 replies

Issamos
Super User
September 29, 2023

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

Tesla DeLorean
Guru
September 29, 2023

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
ZExpo.1
ZExpo.1Author
Associate III
September 29, 2023

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.

Issamos
Super User
September 29, 2023

uint8_t N[100];

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

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

{.     

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

}

Best regards

II 

TDK
September 29, 2023

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""."
Tesla DeLorean
Guru
September 29, 2023

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
ZExpo.1
ZExpo.1Author
Associate III
September 30, 2023

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
September 30, 2023

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""."