Skip to main content
Visitor II
October 5, 2019
Solved

a loop which iterates infinitely for x seconds - stm32mp157c-dk2

  • October 5, 2019
  • 4 replies
  • 1612 views

Hi,

In my M4 program within while loop, I have made a for loop which iterates infinitely for 0.75 seconds like this but didnt work at all. I used time.h for that.

Are we allowed to make this kind of loop within the while loop in M4 program ?

Do you have any idea why it didnt work ?

 clock_t begin;
 double time_spent;
 unsigned int i;
 
 begin = clock();
 for (i=0;1;i++)
 {
 /*do my staff */
 if (VirtUart0RxMsg) {
 Check_Delay(VirtUart0ChannelBuffRx, VirtUart0ChannelRxSize);
 VIRT_UART_Transmit(&huart0, VirtUart0ChannelBuffRx, VirtUart0ChannelRxSize);
 VirtUart0RxMsg = RESET;
 }
 
 time_spent = (double)(clock() - begin) / CLOCKS_PER_SEC;
 if (time_spent>=0.75)
 break;
 }
 }

    This topic has been closed for replies.
    Best answer by IYetk

    I used the contents of HAL_Delay() function to make a loop which iterates an amount of seconds.

    This issue can be closed.

    4 replies

    Technical Moderator
    October 7, 2019

    Hello,

    Maybe a basic SW issue, but I think you need to provide more details.

    Do you try to debug it ? Do the loop hang on some function ? Is the loop exit too early ? Did you check the clock() value returned ?

    IYetkAuthor
    Visitor II
    October 12, 2019

    I used the contents of HAL_Delay() function to make a loop which iterates an amount of seconds.

    This issue can be closed.

    IYetkAuthor
    Visitor II
    October 7, 2019

    I will debug it and write you the details...

    Graduate II
    October 9, 2019

    how can something iterate infinitely for a finite amount of seconds?

    IYetkAuthor
    Visitor II
    October 10, 2019

    You are right. There is a misunderstanding here.

    I just mean "a loop which iterates an amount of seconds"

    IYetkAuthorAnswer
    Visitor II
    October 12, 2019

    I used the contents of HAL_Delay() function to make a loop which iterates an amount of seconds.

    This issue can be closed.