Hello everybody! Can anyone tell me, how to count number of microseconds ( not milliseconds ), since the arduino began running. Or how to count duration of some process, in milliseconds? Thanks!
I don't know if there is one, but such a timer would overflow in just over 71 minutes (232/1000000).
-j
It's not a problem, duration of process who i would like to count is maximum 1 millisecond.
If you need software to count and time things in micro seconds then you don't want to be programming in C, you need to be in assembler. If you use assembler you write single instructions and you can look up how long each instruction takes in machine cycles in the processor's data sheet. Then you look at the clock frequency feeding your processor and see how long it takes to execute one machine cycle. Finally add up all the machine cycles in your loop or read in code and then you know how many microseconds it will take.
The problem with C is you don't know how the compiler is going to translate what you write into assembler so you can't calculate it.
As Mike points out, timing can get pretty involved. Why don't you tell us a bit more about your project?
If, for example, you just need to time a pulse with with microsecond resolution, there's the pulseIn()
function.
-j
kg4wsv, it's exactly what i need! Why i didnt noticed she?
I have no concrete project now, but things who i do now, i will use in future. Now i'm receiving data from radio receiver, and i need to know, how long is pulse :). So that is that what i need. Thanks.