cancel
Showing results for 
Search instead for 
Did you mean: 

Create Delay Function using STM32

dnk
Associate

I'm having trouble making the delay function in stm32f411vet. When the power frequency for the chip is 16MHZ, it still works normally but when the frequency is increased to about 64MHZ, the error occurs. Let me all ask you what fault this is.

3 REPLIES 3

> delay function

Post it.

> when the frequency is increased to about 64MHZ, the error occurs

What error?

JW

Present the problem like we're not all psychic. Show code, show issues, explain.

You can't interrupt over a few hundred KHz, and the TIM are all 16-bit so limit the span of time over which they roll-over

For micro-second timing configure the TIM to divide down to 1 MHz, ie Prescaler of 72-1 for 72 MHz or 64-1 for 64 MHz system.

Set Period to 0xFFFF, don't enable the Update Interrupt

TIMx->CNT will count micro-seconds.

uint16_t start = TIMx->CNT;

while((TIMx->CNT- start) < 33); // 33 us delta

 

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

dnk_0-1703820357379.pngdnk_1-1703820376077.png