Syncing digital input and analogue input

But I am unable to get the accurate results.

How are you measuring these results and how do you know they are not accurate?

What speed are things running at?

What is your application and why does it matter?