// PLL-Reg-R0 = 32bit
// Registerselect 4bit
// int N_Int = 92; // 16bit
int Prescal = 0; // 1bit geht nicht
it does not work
// int Autocal = 1; //1 bit =0 для мелких изменений <10кГц =1 для остальных изменений.
// reserved // 10bit
// PLL-Reg-R1 = 32bit
// Registerselect 4bit
// int FRAC1 = 10; // 24 bit
// reserved // 4bit
// PLL-Reg-R2 = 32bit
// Registerselect 4bit
int M_Mod2 = 16383; // 14 bit
// int Frac2 = 0; // 14 bit
// PLL-Reg-R3 = 32bit - FIXED !
// Registerselect 4bit
//Fixed value to be written = 0x3 =3
// PLL-Reg-R4 = 32bit
// Registerselect 4bit
int U1_CountRes = 0; // 1bit
int U2_Cp3state = 0; // 1bit
int U3_PwrDown = 0; // 1bit
int U4_PDpola = 1; // 1bit
int U5_MuxLog = 1; // 1bit
int U6_RefMode = 1; // 1bit
// int U5_LPD = 0; // 1bit
// int U6_LPF = 1; // 1bit 1=Integer, 0=Frac not spported yet
int CP_ChgPump = 9; // 4bit
int D1_DoublBuf = 0; // 1bit
int R_Counter = 1; // 10bit
int RD1_Rdiv2 = 0; // 1bit
int RD2refdoubl = 0; // 1bit
int M_Muxout = 6; // 3bit
// reserved // 2bit
// PLL-Reg-R5 = 32bit
// Registerselect // 4bit
// Phase Select: Not of partcular interst in Amatuer radio applications. Leave at a string of zeros.
// PLL-Reg-R6 = 32bit
// Registerselect // 4bit
//Variable value to be written!!!
int D_out_PWR = mdbm; // 2bit OutPwr 0-3 3= +5dBm Power out 1
int D_RF_ena = 1; // 1bit OutPwr 1=on 0 = off Outport Null freischalten
int Reserved = 0; // 3bit
int D_RFoutB = 1; // 1bit aux OutSel
int D_MTLD = 0; // 1bit
int CPBleed = 126; // 8bit
int D_RfDivSel = 3; // 3bit 3=70cm 4=2m lokale Variable
int D_FeedBack = 1; // 1bit
// reserved // 7bit
// PLL-Reg-R7 = 32bit
// Registerselect // 4bit
//Fixed value to be written = 0x120000E7 = 301990119 (dec)
// PLL-Reg-R8 = 32bit
// Registerselect // 4bit
//Fixed value to be written = 0x102D0428 = 271385640 (dec)
// PLL-Reg-R9 = 32bit
// Registerselect // 4bit
//Fixed value to be written = 0x5047CC9 = 84180169 (dec)
// PLL-Reg-R10 = 32bit
// Registerselect // 4bit
//Fixed value to be written = 0xC0067A = 12584570 9dec)
// PLL-Reg-R11 = 32bit
// Registerselect // 4bit
//Fixed value to be written = 0x61300B = 6369291 (dec)
// PLL-Reg-R12 = 32bit
// Registerselect // 4bit
//Fixed value to be written = 0x1041C = 66588 (dec)
// Referenz Freg Calc
// int F4_BandSel = 10.0 * B_BandSelClk / PFDFreq;
double RFout = Freq; // VCO-Frequenz 144200000 Freq ist global, RFout ist lokal
// calc bandselect und RF-div
float outdiv = 1;
if (RFout >= 680000000) {
outdiv = 0.5f;
D_RfDivSel = 0;
D_RFoutB = 0;
D_RF_ena = 0;
}
if (RFout < 680000000) {
outdiv = 1;
D_RfDivSel = 0;
D_RFoutB = 1;
D_RF_ena = 1;
}
if (RFout < 340000000) {
outdiv = 2;
D_RfDivSel = 1;
D_RFoutB = 1;
D_RF_ena = 1;
}
if (RFout < 170000000) {
outdiv = 4;
D_RfDivSel = 2;
D_RFoutB = 1;
D_RF_ena = 1;
}
if (RFout < 85000000) {
outdiv = 8;
D_RfDivSel = 3;
D_RFoutB = 1;
D_RF_ena = 1;
}
if (RFout < 42500000) {
outdiv = 16;
D_RfDivSel = 4;
D_RFoutB = 1;
D_RF_ena = 1;
}
if (RFout < 21250000) {
outdiv = 32;
D_RfDivSel = 5;
D_RFoutB = 1;
D_RF_ena = 1;
}
if (RFout < 10625000) {
outdiv = 64;
D_RfDivSel = 6;
D_RFoutB = 1;
D_RF_ena = 1;
}
/////////////////////////////////////////////////////////////////////////////
//////////////////////// N and Frac1 and Frac2 calculations /////////////////
//////////////////////// Done using double precision 64 bit /////////////////
//////////////////////// Results agree exactly with AD demo /////////////////
/////////////////////////////////////////////////////////////////////////////
double PFDFreq = refin * ((1.0 + RD2refdoubl) / (R_Counter * (1.0 + RD1_Rdiv2))); //Phase detector frequency
double N = (outdiv*RFout) / PFDFreq; // Calculate N
int N_Int = (int)N; // N= 50 for 5 GHz // Turn N into integer
double F_Frac1x = (N - N_Int) * pow(2, 24); // Calculate Frac1 (N remainder * 2^24)
int F_FracN = (int)F_Frac1x; // turn Frac1 into an integer
double F_Frac2x = ((F_Frac1x - F_FracN)) * pow(2, 14); // Claculate Frac2 (F_FracN remainder * 2^14)
int F_Frac1 = (int)F_Frac1x; // turn Frac1 into integer
int F_Frac2 = (int)F_Frac2x; // turn Frac2 into integer
////////////////// Set 32 bit register values R0 to R12 ///////////////////////////
R[0] = (unsigned long)(0 + N_Int * pow(2, 4) + Prescal * pow(2, 20) + Autocal * pow(2,21)); // R0 für Startfrequenz ok
// R[0] = (unsigned long)(0x203200);
R[1]=(unsigned long)(1 + F_Frac1 * pow(2, 4));
//R[1] = (unsigned long)(0x20C491);
R[2] = (unsigned long)(2 + M_Mod2 * pow(2, 4) + F_Frac2 * pow(2, 18)); //
R[3] = (unsigned long)(0x3); //Fixed value (Phase control not needed)
R[4] = (unsigned long)(4 + U1_CountRes * pow(2, 4) + U2_Cp3state * pow(2, 5) + U3_PwrDown * pow(2, 6) + U4_PDpola * pow(2, 7) + U5_MuxLog * pow(2,
+ U6_RefMode * pow(2, 9) + CP_ChgPump * pow(2, 10) + D1_DoublBuf * pow(2, 14) + R_Counter * pow(2, 15) + RD1_Rdiv2 * pow(2, 25) + RD2refdoubl * pow(2, 26) + M_Muxout * pow(2, 27));
// R[4] = (unsigned long)(0x32050B84); //Variable But probably can leave fixed.
R[5] = (unsigned long) (0x800025); // Fixed (Reserved)
R[6] = (unsigned long)(6 + D_out_PWR * pow(2, 4) + D_RF_ena * pow(2, 6) + Reserved * pow(2, 7) + D_RFoutB * pow(2, 10) + D_MTLD * pow(2, 11) + Reserved * pow(2, 12) + CPBleed * pow(2, 13) + D_RfDivSel * pow(2, 21) + D_FeedBack * pow(2, 24) +10 * pow(2, 25));
// R[6] = (unsigned long) (0x35002076); //variable
R[7] = (unsigned long) (0x120000E7);
R[8] = (unsigned long) (0x102D0428);
R[9] = (unsigned long) (0x302FCC9);
R[10] = (unsigned long) (0xC0043A);
R[11] = (unsigned long) (0x61300B);
R[12] = (unsigned long) (0x1041C);