Measuring pulse duration more accurately with ESP32

One way to a solution would be to provide your code in code tags so we can possibly see where the error is. But if you'll not be posting your code in code tags then the issue is line 12056 of your code.

The ESP32 can detect a 12.5 nanosecond pulse. I'd not use the micros() with an ESP32, I'd use the built in ESP32 micros counter instead.