How to create nanoseconds delay

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Krstevska
Employee
Employee
First question asked Welcome!

Hi, 

I am using ShieldBuddy TC375 and I am trying to use nanoseconds delay. 

I tried multiple tings with the STM timer:
- with IfxStm_waitTicks function, tried to wait 10 cycles ( the STM timer works on 100 MHz frequency, so I am trying to wait 100 ns) but this doesn't work. I guess because this function takes more time to execute than 100 ns. 

- with reading the STM.TIM0 at time = 0 and then reading the same register simultaneously and wait until the difference between these two values is bigger than 10. This also didn't work, I guess because of the same reason in point 1. 

- With generating interrupts via STM timer. This is working if I am generating interrupts every 500 ns. If I try to generate interrupts  every 400 ns, then it takes some time ( 5-10 seconds) and then in starts generating. Everything below 400 ns it's not doing anything . 

- The last thing I tried is with sending __nop() instructions. This is not consistent because the duration of 10 nop instructions is not equal to the duration of 1 nop instruction * 10. 

 

I am testing the delay with toggling a pin because I need the delay for implementing a communication protocol. 

Every suggestion is welcomed. 

Thank you in advance. 

 

0 Likes
1 Reply
Di_W
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 250 solutions authored

Hi Krstevska,

Could you please try functions of Time APIs in bsp.h?

You can use GPIO ON/OFF to measure the time interval. But please note disable interrupt first.

And assembly code would be more accurate than C.

dw

0 Likes