cancel
Showing results for 
Search instead for 
Did you mean: 

how to set long delay with use of timer(like up to 5 minute,)

dbgarasiya
Senior II

part number: STM32F779BI

I am using clock frequency 108 MHz ( not system clock , system clock is 216 MHZ)

I don't want to use loop

if not possible what is the maximum value i could set using timer

46 REPLIES 46
dbgarasiya
Senior II

I have modified my code as given below

Start_All_Timers();

for (int i = 0;i<10;i++)

{

HAL_Delay(1000);

arr[i]= TIM6->CNT ;

}

for(int j=0;j<10;j++)

{

printf("value is %d is=%d\n\r",j,arr[j]);

}

output i got here

value is 0 is=432

value is 1 is=1432

value is 2 is=2432

value is 3 is=3432

value is 4 is=4432

value is 5 is=5432

value is 6 is=6432

value is 7 is=7432

value is 8 is=8432

value is 9 is=9432

i am not getting here 10 ms of delay here also

turboscrew
Senior III

Hmm, this needs another look...

Also HAL_Delay delays the given number of milliseconds.

HAL_Delay(1000) delays one second. You should do HAL_Delay(1) and that might reveal something. It looks like the timer6 ticks milliseconds. As if the counting frequency is 1 ms instead of 1 us. I wonder if HAL uses the same timer or there's something very wrong with the clocks.

Just to make sure, you could try another timer (not tim6 nor tim7) on the same APB bus (like tim12). Maybe you and HAL mess with the same timer? HAL typically uses tim6, sometimes tim7.

You can also check which timer HAL_Delay uses.

dbgarasiya
Senior II

I have used another timer 13 with prescaler of 107 and reload value(ARR) is 9999 but still output is same as given below

value is 0 is=432

value is 1 is=1432

value is 2 is=2432

value is 3 is=3432

value is 4 is=4432

value is 5 is=5432

value is 6 is=6432

value is 7 is=7432

value is 8 is=8432

value is 9 is=9432

Dipak Garasya

Piranha
Chief II

How much years will it take for you to learn to use Code Snippet feature?

Your timer has a tick of 1 us and a period of 10 ms. You are reading it in a cycle with HAL_Delay(1000) which actually waits 1000+1 ms, because it's designed by idiots. During that 1 second your timer rolls around exactly 100 times and the additional 1 ms takes 1000 ticks of 1 us, which is exactly the result that you see in your latest comments. Everything works as it should. It's just that your code is nonsense and "tests" nothing.

just understand what is my requirement. i want 10 ms timer means each tick should come by 10 millisecond

so when 1 sec pass it should be increment only 100 ticks

Dipak gARASIYA

Ahh, not 10 ms period, but 10 ms ticks that the timer counts.

You need to divide the clock by 1080000. That won't fit into a 16-bit prescaler. you need to prescale the APB bus timer clock too. The down side is that all timers on the same APB bus are slowed down. 54000 fits in a 16-bit prescaler, so you need to divide the bus timer clock by 20. I don't have the reference manual for that chip at hand to check what you can do with the bus clocks.

If you have a timer with 32-bit prescaler, you write (1080000-1) into the prescaler (supposing that the bus clock to that timer is 108MHz too).

Then you probably have 32-bit counter (and ARR) too. The maximum is then 42949672,95 seconds = ~ 1.3 years.

The other way could be the earlier 10 ms timer and a software counter. The timer interrupts at ARR (=10000-1) and the interrupt adds 1 to a global variable.

Thanks @turboscrew (Community Member)​ for your all your support

I have done it using third way

Thanks again,

Have a nice day!

Dipak Garasiya