My team and I are designing a project which requires the detection of rising edge of a square wave and then storing the time using time.time() in a variable.If a same square wave is given to 3 different pins of RPi,and event detection is applied on each pin,theoretically,they should occur at the same time,but they have a delay which causes a difference in phase too (we are calculating phase from time).
We concluded that time.time() is a slow function.
Can anyone please help me as to which function to use to get SOC more precise than time.time()?
Or please provide me with the programming behind the function time.time().
I'll be really thankful.
time.time uses gettimeofday on platforms that support it. That means its resolution is in microseconds.
You might try using time.clock_gettime(time.CLOCK_REALTIME) which provides nanosecond resolution (assuming the underlying hardware/OS provides that). The result still gets converted to floating point as with time.time.
It's also possible to load up the libc shared object and invoke the native clock_gettime using the ctypes module. In that way, you could obtain access to the actual nanosecond count provided by the OS. (Using ctypes has a fairly steep learning curve though.)
something better than time.time()?