R
R
Rudtoha2018-11-28 16:47:41
Microcontrollers
Rudtoha, 2018-11-28 16:47:41

How to properly set up a 32-bit timer?

How to set a timer to fire N * 3 * 10^(-6) seconds? I did this: the clock frequency of my MK is 48 MHz, which means that 48,000,000 ticks occur in 1 second, then about 155 ticks should pass in 3 * 10 (-6). Multiply by the number of seconds that we go to wait and put this number in the match value and, in theory, everything is ok. In this case, I bypass the prescaler setting, leaving it equal to one.
Something didn't work. Is the error in the method or in something else? How about a prescaler?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2018-11-29
@UPSA

MK was engaged in nuuu for a very long time ... do not scold)))
Purely for interest ...
Datashit to the studio. What MK are you on?
Is the timer supposed to be accurate to 1.5 microseconds? )))
I think that MK should be with an internal generator? Otherwise, there may be errors.
Check. I got 144 ticks, not 155. If I understood correctly what you mean. On what cycle will the counter count 3 * 10^(-6) seconds.
48MHz multiplied by 3 * 10^(-6).
or
3 * 10^(-6) divided by (1 divided by 48MHz).
But then there are different solutions:
1. I counted every 144th cycle from the first counter as another counter and when A*144=N. When the second counter counts N, then it's time. This is if you need to withstand more than 90 seconds.
2. But our counter will withstand 4294967296 cycles (I hope I didn’t lie), those 89 seconds. Immediately multiply N * 144 = you will get the value of the first counter.
3. There you can come up with a lot of things by examining the number 144. Some kind of binary transformation.

A
Alexander, 2018-11-29
@Fox_Alex

The logic of thinking is correct, but the frequency of the timers is not always equal to the frequency of the core. The datasheet to the studio is shorter.
The prescaler stupidly divides the frequency of the timers by a given number of times.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question