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

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

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

dbgarasiya
Senior II

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

In that case, check your clock tree.

dbgarasiya
Senior II

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

How do you know that it's 333 us?

How long takes Timer6_Read to execute, how did you measure it?

How did you verify that the timer didn't overflow?

How did you verify the system clocks?

How did you verify HAL_Delay accuracy?

What do RCC and TIM6 registers contain?

I am attaching you 2 sceenshot of configuration of register

  1. RCC register after timer clock configuration
  2. Timer register after initialization and before reading timer value

Dipak Garasiya

turboscrew
Senior III

Yes. Tim6 frequency should be 108 MHz before prescaler. With prescaler 107 the timer should have 1 MHz count frequency (1 us period).

With 9999 as the ARR the counter should wrap around every 10 000 us = 10 ms.

BTW, which timer does HAL use? Tim7?

Also, you read the timer6 after HAL_Delay(1000), but where do you start the timer6 (or reset it)?

It should happen right before HAL_Delay, or the while before it (it shouldn't get too much off that quickly).

If the clock really runs that wrong, I'm running out of ideas.

I manually checked the clock configurations, and the only wrong thing was that PLLR was zero (bits 30-28 of PLLCFGR), when it should have been at least 2 (says the reference manual). In the clock tree it looks like it should be 2, but in the register it seemed to be 0.

dbgarasiya
Senior II

I have check my clock frequency ,it is perfactly ok

system clock = 216 MHz , hclk clock = 216 MHz ,PCLK1= 54 MHz and PCLK2 = 108 MHz

eventhough it is not gettting 10 ms of delay

What I mean is that maybe tim6 has already counted so far before you start the HAL_Delay that it wraps during that delay.

Try writing zero to timer6 CNT-register just before the while-loop.

Also, what does that timer6 reading function do? If it uses printf, that may take milliseconds.

Rather, make a for-loop and make a small table of read values. Then check the table after the loop.