Finding PHASE between two sinusoids with FFT/DFT (ArduinoFFT w/ C) I am having trouble finding a known phase between two data sets, lets call them data set 11 and data set 12.
I am obtaining a sample size of 1024 samples, at a sampling rate of 500kHz with a total sample time of 2.048ms.
All data and code used in this question can be found at this repository - https://github.com/smake5730/fft_phase/graphs/contributors
As can be seen from the sample data below the two data sets show the voltage is leading the current by around 90°. (zoomed in)

When I compute the FFT with 1024 bins I get clear peaks. (zoomed in)

I apply the Hanning window during this and do not use zero-padding.
I use the location of the largest peak with the atan2(a/b) method to obtain the phase and find that I get the following below. The first data gives me +90° and the second data gives me -90°. The frequencies are correctly identified.

I have tried adding zero-padding to the end of the signal and it does not solve the issue. I have also tried upsampling and it does not give the correct phase either.
Does anyone have any ideas/hints on what I could try or where I am going wrong?

EDIT
As was pointed out below, my code takes individual bins and incorrectly matched bins were used in the second set.
You can't do better than this for accuracy in my experience.

A Two Bin Solution

Select a frame size of 1 1/2 cycles or 2 1/2 cycles.
You only need to calculate two bins, either 1 and 2, or 2 and 3.  No need for a full DFT.  So it is very efficient as well.  By placing the frequency squarely near the center of the two bins you minimize noise effects and avoid needing to deal with near bin frequencies which call for a different set of equations for the fitting vector.
The alternative form is for when the frequency is really close to a bin.

DFT Bin Value Formulas for Pure Real Tones
An Alternative Form of the Pure Real Tone DFT Bin Value Formula

There are other tricks to do it point by point.  I'll let others provide those.