AnsweredAssumed Answered

[STM32F3] How to create microseconds Delay using for?

Question asked by Felipe Caon on Nov 9, 2017
Latest reply on Nov 10, 2017 by Clive One

I'm using STM32F3 with HC-SR04 sensor, already made it work. But not with the accuracy I need, for some reason the output is off by 2-3 centimeter, I'm sure it's because of the delay. 

 

I tried to create a timer for it but with no success, so?

 

My board clock is 64 MHz and my Oscillator s 8 MHz. Correct if i`m wrong, but?

1/8MHz = 0.125microseconds, it sends one tick every 0.125us, so if I need to send a 10us ticks I need to send 80 ticks.

 

Call: pDelay(80);

 

void pDelay(int i){
static uint32_t j=0;
for(j=0;j<i;j++);

}

 

Is this right? Is there a better way to do it SINCE I don't even know how to set up timers. I'm probably sending a more than 10us wave with this function.

Outcomes