Skip to main content
dbgarasiya
Senior
Jan 18, 2020 6:26 AM UTC
Solved

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

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

This topic has been closed for replies.
turboscrew
turboscrewBest answer
Senior III
Mar 13, 2020 7:29 PM UTC

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.

46 replies

waclawek.jan
Super User
Jan 20, 2020 9:38 AM UTC

In other words, as TIM2 is 32-bit, if TIM2's input frequency is 54MHz, the first tick to TIM3 will come in cca 4'000'000 seconds, which is roughly one and a half month.

JW

dbgarasiya
Senior
Jan 20, 2020 11:51 AM UTC

I have follwing changed my code and used another TIM4 as master and same TIM3 as slave

APB1 Clock freqruency is=108MHz

TIM4->PSC=108

TIM3->PSC=1080

TIM4 & TIM3 both are 16 bit timer so ,ARR value is=65535 for both

so accoring to calculation i should get timer 3 will increment at ~71 sec by 1 but i am getting increment at ~143 sec

so what i am going wrong?

berendi
Principal
Jan 20, 2020 12:03 PM UTC

Check your clock configuration, because APB1 timer clock is at most 90 MHz.

Piranha
Principal III
Jan 20, 2020 11:52 AM UTC

Such type of delays are a job for software timers. Software timers with callbacks are absolute necessity for any serious non-trivial project. Therefore implement them once and then use everywhere. Ultimately task scheduler and software timers changes software architecture and your way of thinking forever and enables you to write actually useful systems, not only Arduino style "Hello world!"-s.

waclawek.jan
Super User
Jan 20, 2020 3:09 PM UTC

If APB divider is not 1, TIM is usually not clocked at APB clock but at twice that. Read the RCC chapter.

JW

dbgarasiya
Senior
Jan 21, 2020 6:38 AM UTC

Thanks to all of you @Community member​  ,@berendi​  ,@turboscrew​ ,@Community member​  for your support

dbgarasiya
Senior
Mar 2, 2020 8:20 AM UTC

I have total 14 timers in my controller ( STM32F779BI) , I have done some timers as master-slave configration

but some timers have not master-slave configration functionality

and i know that prescaler valu maximum goes up to , i could generate maximum value of 1 millisecond

but i want to make timer of 10 milliseconds . i tried but i am getting delay of 10 ms after setting prescaler and period value

Timer clock : 108 MHz & 216 MHz , both are used for diffrent timers

how could i do that?

Dipak Garasiya

berendi
Principal
Mar 2, 2020 8:49 AM UTC

These are the limitations. You can slow down the APB clocks, or implement longer delays in software.

turboscrew
Senior III
Mar 2, 2020 6:02 PM UTC

Cascade the timers. Make one of them tick and the other to count the first one's UGs (milliseconds), not APB-clock ticks.

Now you have a longer timer, even if in two parts.

dbgarasiya
Senior
Mar 3, 2020 4:59 AM UTC

I have configured timer 6 as below, my timer clock frequency (APB1) is 108 MHz

RCC->APB1ENR |= (1<<4);   // timer 6

TIM6->PSC = 108;

TIM6->EGR = TIM_EGR_UG;

TIM6->ARR = 10000;

TIM6->CR1 = TIM_CR1_CEN;

count = TIM6->CNT ;

I am not getting 10 millisecond of timer yet

turboscrew
Senior III
Mar 3, 2020 5:10 PM UTC

The counters start from zero. Try PSC=107 and ARR=9999. Any closer?

dbgarasiya
Senior
Mar 4, 2020 4:09 AM UTC

@turboscrew​  that is also not getting 10 milliseconds of timer

berendi
Principal
Mar 4, 2020 4:24 AM UTC

Are you going to tell how long is it then, or do we have to guess?

dbgarasiya
Senior
Mar 4, 2020 4:36 AM UTC

it is appoximately 333 us of timer with this configuration .

while (1)

{

HAL_Delay(1000);

Timer6_Read();

//Read_All_Timers();

}

i have written my code as above for reading timer count

terminal screenshot i have attached with this post

turboscrew
Senior III
Mar 4, 2020 5:13 AM UTC

In that case, check your clock tree.

dbgarasiya
Senior
Mar 4, 2020 5:26 AM UTC

I have used timer 6 which is clocked by timer clock register is RCC_APB1ENR

like this

RCC->APB1ENR |= (1<<4);  // timer 6 which is 108 MHz

i am attaching you my clock configuration sceenshot for this, so you will get better ide about this