cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
vatsal.naik
Adventurer
Adventurer
10,302 Views
Registered: ‎12-02-2016

Generate Time Delay in SDK

Jump to solution

Hello,

 

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, what would be the best way to use delay? Appreciate your help!

 

Best Regards

1 Solution

Accepted Solutions
johnmcd
Xilinx Employee
Xilinx Employee
10,843 Views
Registered: ‎02-01-2008

Depending on optimization, that loop may get removed and therefore, no time delay.

 

So it will depend on how small a delay you are looking for. There are delays available. Take a look at the baremetal bsp sleep.h file.

View solution in original post

4 Replies
johnmcd
Xilinx Employee
Xilinx Employee
10,844 Views
Registered: ‎02-01-2008

Depending on optimization, that loop may get removed and therefore, no time delay.

 

So it will depend on how small a delay you are looking for. There are delays available. Take a look at the baremetal bsp sleep.h file.

View solution in original post

ericv
Scholar
Scholar
10,215 Views
Registered: ‎04-13-2015

@vatsal.naik

 

If you declare the variable i as volatile, the compiler will not remove the loop.

You should also disable the interrupts before entering the loop and re-enable them at the end.

A S/W loop will likely have a latency hit before the code lands in the cache, but after that you'll get a precise delay.

 

vatsal.naik
Adventurer
Adventurer
10,201 Views
Registered: ‎12-02-2016
@johnmcd

Yes, usleep() function from sleep.h seems to work just fine.

Thank you!

Best regards!
vatsal.naik
Adventurer
Adventurer
10,200 Views
Registered: ‎12-02-2016
@ericv I haven't disabled the interrupts, The problem depended on the compile, Every time we got the different delay! Looks like usleep() function is the better way to do it. Thanks for the reply! Best Regards
0 Kudos