Skip to main content
Associate
December 28, 2023
Question

Create Delay Function using STM32

  • December 28, 2023
  • 2 replies
  • 2546 views

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.

    2 replies

    waclawek.jan
    Super User
    December 28, 2023

    > delay function

    Post it.

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

    What error?

    JW

    Tesla DeLorean
    Guru
    December 28, 2023

    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 VenmoUp vote any posts that you find helpful, it shows what's working..
    dnkAuthor
    Associate
    December 29, 2023