The present specification describes a method for determining the distance of an object from the tip of an endoscope during an endoscopic procedure, wherein at least one lens is configured to converge light from outside the tip onto a sensor that includes a plurality of photodiodes a portion of which are adjacent pairs of photodiodes configured to be phase detection pixels. The method includes receiving light into each adjacent pair of photodiodes, wherein said light is reflected off a surface of said object; determining a first response curve to said light for a first photodiode of said adjacent pair of photodiodes and a second response curve to said light for a second photodiode of said adjacent pair of photodiodes; identifying an intersection between the first response curve and the second response curve; and using data derived from said intersection to determine said distance to the object.