Skip to main content
RRajb.1
Associate II
December 21, 2020
Question

Issue with microseconds delay with timer

  • December 21, 2020
  • 3 replies
  • 2290 views

Hi,

we are using stm32f745xx and bellow are our configurations.

we are using total 6 timers, out of which we are using TIM6 to generate 50us interrupt.

htim6.Instance = TIM6;

htim6.Init.Prescaler = 1;

htim6.Init.CounterMode = TIM_COUNTERMODE_UP;

htim6.Init.Period = 2250; // for 50 micro sec.

I got the above values from bellow equation.

period = 90000000 / ((1+prescaller) * (required delay))

system frequency is 180 Mhz, APB1 is 90MHz

Bellow is my queries

1) When generating delay of 50us, we are getting delay with some deviation. like (0.05%)

2) If we reduce the delay time below 50 us, then we are getting more deviation and fluctuation as well.

3) we are not able to generate timer of 1us or 5us.(board is getting reboot)

4) Please let me know the correct settings for prescaller and period.

Please help us with some solution. also please let me know if you need any other information.

Thanks

This topic has been closed for replies.

3 replies

TDK
Super User
December 21, 2020

APB1 is 45MHz max, but its timers may be at 90 MHz. Maybe this is your configuration.

The timer period is (prescaler + 1) * (period + 1) / (timer clock)

In your case, this is likely 2 * 2251 / 90 MHz = 50.02 us.

So you probably want period = 2249.

The jitter is likely caused by the method you're using to measure it. A jitter of 0.05% on 50us is 25 ns, or 2 instruction cycles. How are you measuring the jitter?

"If you feel a post has answered your question, please click ""Accept as Solution""."
RRajb.1
RRajb.1Author
Associate II
December 21, 2020

Hi TDK,

Thanks for the quick response.

will give you the info what you needed, but for more celerity I am attaching the clock configuration in my post.

RRajb.1
RRajb.1Author
Associate II
December 22, 2020

Hi TDK,

I have configured one timer as input capture and on that pin I am giving different - different frequencies, so for 1000hz I should get 1000 count(number of rising edge). and I have one timer which is running at 50us so I am deriving 1 second of time from this 50us timer, so when I am reading the count for 1000Hz at 1 second of interval I am getting 1001, or near around count.

TDK
Super User
December 22, 2020

I'm having a hard time understanding what you're trying to do. If you're generating an interrupt every 50us, that's going to tax the CPU quite a bit and is probably the source of your issue.

If you want a timer that increments once per 50us, that is easy to do with the timer alone. There's no need to generate an interrupt for this.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Tesla DeLorean
Guru
December 21, 2020

Interruption at these ​speeds is probably ill-advised.

Can you do what you need in hardware? ie TIM, TIM+DMA, etc

Can you use a software delay routine using a TIM clock a 16 or 32-bit counter at 1 MHz or faster to mark time.​

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
RRajb.1
RRajb.1Author
Associate II
December 22, 2020

Hi Clive,

Thanks for the response but I will not able to do what I need using hardware.

My main goal is to read frequency of 1Hz - 40khz on 5 pins.

so even if I use interrupt than it will keep giving interrupt. I am using 50us timer and in that ISR I am polling all 5 pins, but with 50us I am able to read up to 20khz frequency

Tesla DeLorean
Guru
December 22, 2020

TiM can measure cycle times and duty, can also count pulses over a measurement interval.​

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..