1) What do you mean by "largest" /"smallest" TOF . So this formula is based on "large" number of samples and I pick largest and smallest and substracts them to get "t" ?
This equation gives the wind speed when we have the TOF( say north to south) and the TOF in opposite direction(south to north).
In the example in the pdf for 1 kph wind we get:
tof from N to S tns = 0.36/(344.7 + 0.277) = 1043.5 micro sec. tof from S to N tsn = 0.36/(344.7 - 0.277) = 1045.2 micro sec.
So t = 1.7 usec. d = 0.36. C = 344.7.
subsitute into the equation and get v = 0.277 m/s (1 kph)
i still do not understand the big picture of you method to determine the wind speed
If you could measure the TOF using envelope detection (ping distance uses this) with an error of 0.1 usec there would be no problem. But the best we can get even with an average of 300 samples is 5 usec(wind noise is the problem). To get closer I incorporate phaseshift wich can give errors of 0.1 usec with 300 samples.
In your code i see you use TCNT1
Good, up to here you have got what I am doing.
The ZCD sets INT0 first. The counter value is recorded for the use as the phaseshift.
TCNT1 keeps counting
I set the detector levels so that the ZCD occurs first.
The envelope detector will then set INT1. The counter value is recorded as the coarse TOF.
TCTN1 is then reset.