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

ok, I will configure , and let you know

dbgarasiya
Senior II

I have updated my code, but still not working,

RCC->APB1ENR |= (1<<0);   // Enable clok for timer 2

RCC->APB1ENR |= (1<<1);   // Enable clok for timer 3

TIM2->PSC = uwPrescalerValue;

TIM3->PSC = uwPrescalerValue;

TIM2->EGR = TIM_EGR_UG;

TIM3->EGR = TIM_EGR_UG;

TIM2->CR2 |= TIM_CR2_MMS_1;

TIM2->SMCR |= TIM_SMCR_ETPS_0;  // done

TIM3->SMCR |= TIM_SMCR_TS_0; // done

TIM3->SMCR |= TIM_SMCR_SMS_0 | TIM_SMCR_SMS_1 |TIM_SMCR_SMS_2; // done

TIM2->CR1 = TIM_CR1_CEN;

TIM3->CR1 = TIM_CR1_CEN;

Be more specific with "not working".

Read out and check the content of both TIMs' registers.

JW

0690X00000BwC8lQAF.pngI am attaching you two screenshot , which is at break point before entering in while loop, where i finally read timer count , all configuratin done before this step

for both timers

You can see the prescaler and period (ARR) values for TIM2. Using these and the APB clock value, you can calculate the period of TIM2. Now multiply this period with the prescaler of TIM3. That's when the counter of TIM3 will be incremented by 1.

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

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?

Piranha
Chief II

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.

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

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

JW