2017-11-09 10:45 AM
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.
#stm32f3 #delay #for #stm32 #hc-sr042017-11-09 06:42 PM
I would use DWT_CYCCNT to count off processor cycles at 72 MHz.
You can always configure a free running timer at 1MHz, and delta 1us ticks from the TIM->CNT register.
Don't assume a single C equates to a since micro-processor instruction. The loop variables need to be volatile so the optimizer remove them.