Trenz Electronic GmbH Support Forum

Trenz Electronic Products => Trenz Electronic FPGA Modules => Topic started by: sonic on March 22, 2018, 04:14:36 PM

Title: Generate time delay
Post by: sonic on March 22, 2018, 04:14:36 PM
Hello,
Not sure if I can get help about this on this forum or not!

We want to generate time delay between controlling GPIO pins. The easier approach would be to create a loop, but it is not a way to generate a Time delay.

Here is what we are doing,

XGpio_DiscreteWrite(&output, TRIG, 0x1); // Start trigger
for( i = 0; i < Delay; i++){
}
XGpio_DiscreteWrite(&output, TRIG, 0x0); // Stop trigger

Can someone guide us regarding what would be the best way to use delay?

Appreciate your help!

Best Regards
Title: Re: Generate time delay
Post by: Oleksandr Kiyenko on March 22, 2018, 04:19:47 PM
Hello,

for correct delay generation better to use platform library functions like "udelay" or "MB_sleep" (depending on platform and OS).
Your example, in most cases, will be optimized by compilator and not produce required delay.

Best regards
Oleksandr Kiyenko
Title: Re: Generate time delay
Post by: sonic on March 22, 2018, 05:00:14 PM
Hi,

Thank you for the reply.

usleep(delay);  function worked.

Yes, The generating time delay using a loop is not a way to do it, Everytime program compiles it changed.!

Thank you

Best regards