previousTime was reset at every loop iteration!

also added TTL pulse