Hi guys, i have a big dubt, i have been doing project for one of my subjects on university and i cant understand why i have to have this return, return(result>>1) for it to get the return rigth
this is the function where i use it:
Code:
uint16_t getPulseWidth1()
{
uint16_t i,resultado1;
for(i=0;i<60000;i++)
{
if(!(PIN_sd & (1<<ECHO1)))
continue;
else
break;
}
if(i==60000)
return Time_out_sd1;
TCCR1A=0x00;
TCCR1B=(1<<CS10);
TCNT1=0x00;
for(i=0;i<60000;i++)
{
if(PIN_sd & (1<<ECHO1))
{
if(TCNT1>60000) break; else continue;
}
else
break;
}
if(i==1900)
return sem_obst_sd1;
resultado1=TCNT1;
TCCR1B=0x00;
if(resultado1>1900)
return sem_obst_sd1;
else
return (resultado1>>1);
}
if any one could explain it to me, thaks a lot, sry for the bad ing :/