Obtaining electrical angle using encoder

Hello everyone,
Frankly, I understood the point except the initial state of the foc algorithm. I want to drive my PMSM motor using FOC. I know that I need the electrical angle in various formulla for this. I use an incremental encoder to obtain the electrical angle. I divide the mechanical angle I find with this encoder by the number of poles and obtain the electrical angle. But when I start my code the pulse_counter variable starts from zero. And it always accepts the first point I run as the starting point. This does not seem like a correct approach. What should I do, how should I act?