What does Fosc/4 mean, and what would that be on Atmega328 ?

I ran across a topic regarding interfacing HC-SR04 with some other microcontroller using interrupts and timers, and they used Fosc/4 for calculating distance with sensor, i wanna know what does it represent there, and why is it even used to get distance from sensor:
D[cm]=((4/FoscPrescalerTimer*c))/2 ?
... and how come here its 4/F instead of F/4, like they normally express SCK....

I understand Fosc is freq. of atmega 328, which is 20MHz right?, and also that F/n is how serial clock speed is derrived from uC clock, but just dont understand why is it used in calculating distance

I understand Fosc is freq. of atmega 328, which is 20MHz right?

Fosc depends on the board and it's configuration. For an Uno, it's 16MHz, for 3.3V pro mini it's 8MHz.

... and how come here its 4/F instead of F/4

Fosc is a frequency, 1/Fosc gives you a time; the distance is proportional to the time it takes to get the signal back.

That's all I can explain.

Was it a PIC they used in that topic? It looks like it would be a PIC.

FOSC is the macro symbol that is conventionally used for the main oscillator frequency in PIC-land. Many PICs divide this frequency by 2 or 4 before applying it to the rest of the chip. That explains where the /4 comes from.

The equivalent convention for AVRs is F_CPU. AVRs don't divide the clock down like PICs do so you don't need the random /4 when you port the code.

The sensor you're using measures calculates distance by measuring the time-of-flight of an ultrasonic sound pulse. That calculation converts that time into a distance.

Jiggy-Ninja:
Was it a PIC they used in that topic? It looks like it would be a PIC.

The sensor you're using measures calculates distance by measuring the time-of-flight of an ultrasonic sound pulse. That calculation converts that time into a distance.

Yeah its PIC microcontroller, ok things are now more clearer thank you ;), but still dont get it why we need that period from 1/Fosc to calculate distance, when we are using the width of echo pulse which represents time passed since the pulse is emitted, then calculate distance from that, just dont see what part does Fosc has in that, but nvm, my main question is answered :slight_smile:

Because it doesn't time in seconds (or ms, or ns or or or) but in the numbers of ticks passed in the counter. And that counter is driven by the main oscillator or in the case of a PIC, by Fosc/4. So if you want a real time as we know it (as in, seconds) you need to take that factor in account.