I'm trying to build an AFE circuit (image below) to better manipulate the AC signal AD5933 supply to my DUT. Everything works as intended, I can measure the impedance and phase of a resistor without problens, but when I try to do it with a capacitor it gets strange, it will give me values of impedance that makes sense but the phase values dont match. For example, when I try to measure a capacitor (like the 10 pF in the datasheet) on a frequency sweep of 10k Hz to 100k Hz with 200kOhm calibration and feedback resistors, the phase values will start at -90º and finish at aproximately -42º. 
This is the first stage with an ad8606, after that it is the DUT/Rcal and Rrfb.
I'm using an arduino with a code I found on the internet to make the measurements(.cpp file):
bool AD5933::calibrate(int real[], int imag[], double gain[], double phase[], long int ref, int n) {
// REMOVIDO: A alocação dinâmica de memória
// int *real = new int[n];
// int *imag = new int[n];
// Realiza a varredura de frequência, usando os arrays 'real' e 'imag' que foram passados como parâmetro.
if (!frequencySweep(real, imag, n)) {
// Não precisamos mais do 'delete', pois não usamos 'new'
return false;
}
// Para cada ponto da varredura, calcula o fator de ganho e a fase do sistema
for (int i = 0; i < n; i++) {
// Cálculo do Fator de Ganho (para Magnitude)
double magnitude = sqrt(pow((double)real[i], 2) + pow((double)imag[i], 2));
gain[i] = (1.0 / ref) / magnitude;
// Cálculo da Fase do Sistemas
phase[i] = (atan((double)imag[i]/(double)real[i]) * 180.0 )/ 3.1415;
}
// REMOVIDO: A liberação de memória
// delete [] real;
// delete [] imag;
return true;
}
How I get the real phase value (.ino file):
double faseSistema = (atan((double)imag/(double)real) *180.0)/3.1415;
double faseReal = faseSistema - phase[i];
I don't understand what I'm doing wrong.
Edit Notes
Justo correcting title[edited by: Texspray at 9:24 PM (GMT -4) on 26 Sep 2025]









