| 1 | /*********************************************************************** |
| 2 | * This following mashup was put together by Per Vices, starting with a |
| 3 | * a file generated by gen_adf4350_regs.py, written by Ettus Research, |
| 4 | * and references parts of adf4350.{c,h} from Analog Devices. |
| 5 | * |
| 6 | * (c) 2012 Ettus Research |
| 7 | * (c) 2012 Analog Devices |
| 8 | * (c) 2013 Per Vices Corporation |
| 9 | * Licensed under the GPL v2. |
| 10 | **********************************************************************/ |
| 11 | |
| 12 | #ifndef INCLUDED_ADF4351_REGS_HPP |
| 13 | #define INCLUDED_ADF4351_REGS_HPP |
| 14 | |
| 15 | /* Specifications */ |
| 16 | #define ADF4350_MAX_OUT_FREQ 4400000000ULL /* Hz */ |
| 17 | #define ADF4350_MIN_OUT_FREQ 137500000 /* Hz */ |
| 18 | #define ADF4351_MIN_OUT_FREQ 34375000 /* Hz */ |
| 19 | #define ADF4350_MIN_VCO_FREQ 2200000000ULL /* Hz */ |
| 20 | #define ADF4350_MAX_FREQ_45_PRESC 3000000000ULL /* Hz */ |
| 21 | #define ADF4350_MIN_INT_DIV_45 23 |
| 22 | #define ADF4350_MIN_INT_DIV_89 75 |
| 23 | #define ADF4350_MAX_FREQ_PFD 32000000 /* Hz */ |
| 24 | #define ADF4350_MAX_BANDSEL_CLK 125000 /* Hz */ |
| 25 | #define ADF4350_MAX_FREQ_REFIN 250000000 /* Hz */ |
| 26 | #define ADF4350_MAX_MODULUS 4095 |
| 27 | |
| 28 | #define ADF4350_DESIGN_PFD 31250000 /* Hz */ |
| 29 | |
| 30 | #include <stdint.h> |
| 31 | #include <math.h> |
| 32 | #include <set> |
| 33 | #include <iostream> |
| 34 | #include <bitset> |
| 35 | |
| 36 | |
| 37 | class adf4351_regs_t{ |
| 38 | public: |
| 39 | uint16_t frac_12_bit; |
| 40 | uint16_t int_16_bit; |
| 41 | uint16_t mod_12_bit; |
| 42 | uint16_t phase_12_bit; |
| 43 | enum prescaler_t{ |
| 44 | PRESCALER_4_5 = 0, |
| 45 | PRESCALER_8_9 = 1 |
| 46 | }; |
| 47 | prescaler_t prescaler; |
| 48 | enum phase_adj_t{ |
| 49 | PHASE_ADJ_OFF = 0, |
| 50 | PHASE_ADJ_ON = 1 |
| 51 | }; |
| 52 | phase_adj_t phase_adj; |
| 53 | enum counter_reset_t{ |
| 54 | COUNTER_RESET_DISABLED = 0, |
| 55 | COUNTER_RESET_ENABLED = 1 |
| 56 | }; |
| 57 | counter_reset_t counter_reset; |
| 58 | enum cp_three_state_t{ |
| 59 | CP_THREE_STATE_DISABLED = 0, |
| 60 | CP_THREE_STATE_ENABLED = 1 |
| 61 | }; |
| 62 | cp_three_state_t cp_three_state; |
| 63 | enum power_down_t{ |
| 64 | POWER_DOWN_DISABLED = 0, |
| 65 | POWER_DOWN_ENABLED = 1 |
| 66 | }; |
| 67 | power_down_t power_down; |
| 68 | enum pd_polarity_t{ |
| 69 | PD_POLARITY_NEGATIVE = 0, |
| 70 | PD_POLARITY_POSITIVE = 1 |
| 71 | }; |
| 72 | pd_polarity_t pd_polarity; |
| 73 | enum ldp_t{ |
| 74 | LDP_10NS = 0, |
| 75 | LDP_6NS = 1 |
| 76 | }; |
| 77 | ldp_t ldp; |
| 78 | enum ldf_t{ |
| 79 | LDF_FRAC_N = 0, |
| 80 | LDF_INT_N = 1 |
| 81 | }; |
| 82 | ldf_t ldf; |
| 83 | enum charge_pump_current_t{ |
| 84 | CHARGE_PUMP_CURRENT_0_31MA = 0, |
| 85 | CHARGE_PUMP_CURRENT_0_63MA = 1, |
| 86 | CHARGE_PUMP_CURRENT_0_94MA = 2, |
| 87 | CHARGE_PUMP_CURRENT_1_25MA = 3, |
| 88 | CHARGE_PUMP_CURRENT_1_56MA = 4, |
| 89 | CHARGE_PUMP_CURRENT_1_88MA = 5, |
| 90 | CHARGE_PUMP_CURRENT_2_19MA = 6, |
| 91 | CHARGE_PUMP_CURRENT_2_50MA = 7, |
| 92 | CHARGE_PUMP_CURRENT_2_81MA = 8, |
| 93 | CHARGE_PUMP_CURRENT_3_13MA = 9, |
| 94 | CHARGE_PUMP_CURRENT_3_44MA = 10, |
| 95 | CHARGE_PUMP_CURRENT_3_75MA = 11, |
| 96 | CHARGE_PUMP_CURRENT_4_07MA = 12, |
| 97 | CHARGE_PUMP_CURRENT_4_38MA = 13, |
| 98 | CHARGE_PUMP_CURRENT_4_69MA = 14, |
| 99 | CHARGE_PUMP_CURRENT_5_00MA = 15 |
| 100 | }; |
| 101 | charge_pump_current_t charge_pump_current; |
| 102 | enum double_buffer_t{ |
| 103 | DOUBLE_BUFFER_DISABLED = 0, |
| 104 | DOUBLE_BUFFER_ENABLED = 1 |
| 105 | }; |
| 106 | double_buffer_t double_buffer; |
| 107 | uint16_t r_counter_10_bit; |
| 108 | enum reference_divide_by_2_t{ |
| 109 | REFERENCE_DIVIDE_BY_2_DISABLED = 0, |
| 110 | REFERENCE_DIVIDE_BY_2_ENABLED = 1 |
| 111 | }; |
| 112 | reference_divide_by_2_t reference_divide_by_2; |
| 113 | enum reference_doubler_t{ |
| 114 | REFERENCE_DOUBLER_DISABLED = 0, |
| 115 | REFERENCE_DOUBLER_ENABLED = 1 |
| 116 | }; |
| 117 | reference_doubler_t reference_doubler; |
| 118 | enum muxout_t{ |
| 119 | MUXOUT_3STATE = 0, |
| 120 | MUXOUT_DVDD = 1, |
| 121 | MUXOUT_DGND = 2, |
| 122 | MUXOUT_RDIV = 3, |
| 123 | MUXOUT_NDIV = 4, |
| 124 | MUXOUT_ANALOG_LD = 5, |
| 125 | MUXOUT_DLD = 6, |
| 126 | MUXOUT_RESERVED = 7 |
| 127 | }; |
| 128 | muxout_t muxout; |
| 129 | enum low_noise_and_spur_t{ |
| 130 | LOW_NOISE_AND_SPUR_LOW_NOISE = 0, |
| 131 | LOW_NOISE_AND_SPUR_RESERVED0 = 1, |
| 132 | LOW_NOISE_AND_SPUR_RESERVED1 = 2, |
| 133 | LOW_NOISE_AND_SPUR_LOW_SPUR = 3 |
| 134 | }; |
| 135 | low_noise_and_spur_t low_noise_and_spur; |
| 136 | uint16_t clock_divider_12_bit; |
| 137 | enum clock_div_mode_t{ |
| 138 | CLOCK_DIV_MODE_CLOCK_DIVIDER_OFF = 0, |
| 139 | CLOCK_DIV_MODE_FAST_LOCK = 1, |
| 140 | CLOCK_DIV_MODE_RESYNC_ENABLE = 2, |
| 141 | CLOCK_DIV_MODE_RESERVED = 3 |
| 142 | }; |
| 143 | clock_div_mode_t clock_div_mode; |
| 144 | enum cycle_slip_reduction_t{ |
| 145 | CYCLE_SLIP_REDUCTION_DISABLED = 0, |
| 146 | CYCLE_SLIP_REDUCTION_ENABLED = 1 |
| 147 | }; |
| 148 | cycle_slip_reduction_t cycle_slip_reduction; |
| 149 | enum output_power_t{ |
| 150 | OUTPUT_POWER_M4DBM = 0, |
| 151 | OUTPUT_POWER_M1DBM = 1, |
| 152 | OUTPUT_POWER_2DBM = 2, |
| 153 | OUTPUT_POWER_5DBM = 3 |
| 154 | }; |
| 155 | output_power_t output_power; |
| 156 | enum charge_cancel_t{ |
| 157 | CHARGE_CANCEL_DISABLED = 0, |
| 158 | CHARGE_CANCEL_ENABLED = 1 |
| 159 | }; |
| 160 | enum antibacklash_pulse_t{ |
| 161 | ANTIBACKLASH_PULSE_6NS = 0, |
| 162 | ANTIBACKLASH_PULSE_3NS = 1 |
| 163 | }; |
| 164 | antibacklash_pulse_t antibacklash_pulse; |
| 165 | charge_cancel_t charge_cancel; |
| 166 | enum band_sel_clk_mode_t{ |
| 167 | BAND_SEL_CLK_MODE_LOW = 0, |
| 168 | BAND_SEL_CLK_MODE_HIGH = 1 |
| 169 | }; |
| 170 | band_sel_clk_mode_t band_sel_clk_mode; |
| 171 | enum rf_output_enable_t{ |
| 172 | RF_OUTPUT_ENABLE_DISABLED = 0, |
| 173 | RF_OUTPUT_ENABLE_ENABLED = 1 |
| 174 | }; |
| 175 | rf_output_enable_t rf_output_enable; |
| 176 | enum aux_output_power_t{ |
| 177 | AUX_OUTPUT_POWER_M4DBM = 0, |
| 178 | AUX_OUTPUT_POWER_M1DBM = 1, |
| 179 | AUX_OUTPUT_POWER_2DBM = 2, |
| 180 | AUX_OUTPUT_POWER_5DBM = 3 |
| 181 | }; |
| 182 | aux_output_power_t aux_output_power; |
| 183 | enum aux_output_enable_t{ |
| 184 | AUX_OUTPUT_ENABLE_DISABLED = 0, |
| 185 | AUX_OUTPUT_ENABLE_ENABLED = 1 |
| 186 | }; |
| 187 | aux_output_enable_t aux_output_enable; |
| 188 | enum aux_output_select_t{ |
| 189 | AUX_OUTPUT_SELECT_DIVIDED = 0, |
| 190 | AUX_OUTPUT_SELECT_FUNDAMENTAL = 1 |
| 191 | }; |
| 192 | aux_output_select_t aux_output_select; |
| 193 | enum mute_till_lock_detect_t{ |
| 194 | MUTE_TILL_LOCK_DETECT_MUTE_DISABLED = 0, |
| 195 | MUTE_TILL_LOCK_DETECT_MUTE_ENABLED = 1 |
| 196 | }; |
| 197 | mute_till_lock_detect_t mute_till_lock_detect; |
| 198 | enum vco_power_down_t{ |
| 199 | VCO_POWER_DOWN_VCO_POWERED_UP = 0, |
| 200 | VCO_POWER_DOWN_VCO_POWERED_DOWN = 1 |
| 201 | }; |
| 202 | vco_power_down_t vco_power_down; |
| 203 | int8_t band_select_clock_div; |
| 204 | enum rf_divider_select_t{ |
| 205 | RF_DIVIDER_SELECT_DIV1 = 0, |
| 206 | RF_DIVIDER_SELECT_DIV2 = 1, |
| 207 | RF_DIVIDER_SELECT_DIV4 = 2, |
| 208 | RF_DIVIDER_SELECT_DIV8 = 3, |
| 209 | RF_DIVIDER_SELECT_DIV16 = 4, |
| 210 | RF_DIVIDER_SELECT_DIV32 = 5, |
| 211 | RF_DIVIDER_SELECT_DIV64 = 6 |
| 212 | }; |
| 213 | rf_divider_select_t rf_divider_select; |
| 214 | |
| 215 | enum feedback_select_t{ |
| 216 | FEEDBACK_SELECT_DIVIDED = 0, |
| 217 | FEEDBACK_SELECT_FUNDAMENTAL = 1 |
| 218 | }; |
| 219 | feedback_select_t feedback_select; |
| 220 | enum ld_pin_mode_t{ |
| 221 | LD_PIN_MODE_LOW0 = 0, |
| 222 | LD_PIN_MODE_DLD = 1, |
| 223 | LD_PIN_MODE_LOW = 2, |
| 224 | LD_PIN_MODE_HIGH = 3 |
| 225 | }; |
| 226 | ld_pin_mode_t ld_pin_mode; |
| 227 | |
| 228 | //Powers down frequency synthesizer |
| 229 | void turn_off(){ |
| 230 | power_down = POWER_DOWN_ENABLED; |
| 231 | }; |
| 232 | |
| 233 | //Turns on the frequency synthesizer |
| 234 | void turn_on(){ |
| 235 | power_down = POWER_DOWN_DISABLED; |
| 236 | cp_three_state = CP_THREE_STATE_DISABLED; |
| 237 | rf_output_enable = RF_OUTPUT_ENABLE_ENABLED; |
| 238 | }; |
| 239 | |
| 240 | //Output current register contents to stdout. |
| 241 | void show_regs(){ |
| 242 | for (int i=0;i<=5;i++){ |
| 243 | std::cout << "\tRegister " << i << "=>\t" << std::hex << uint32_t ( get_reg(i) )<< std::endl; |
| 244 | }; |
| 245 | }; |
| 246 | |
| 247 | //INITIALIZATION ROUTINE (Initialize in Safe State, lowest power output, outputs disabled, powered down) |
| 248 | //POWER OFF, OUTPUTS MUTED, LOWEST POWER SETTING. |
| 249 | adf4351_regs_t(){ |
| 250 | frac_12_bit = 0; |
| 251 | int_16_bit = 23; |
| 252 | mod_12_bit = 2; |
| 253 | phase_12_bit = 1; |
| 254 | prescaler = PRESCALER_4_5; |
| 255 | phase_adj = PHASE_ADJ_OFF; |
| 256 | counter_reset = COUNTER_RESET_DISABLED; |
| 257 | cp_three_state = CP_THREE_STATE_ENABLED; |
| 258 | power_down = POWER_DOWN_ENABLED; |
| 259 | pd_polarity = PD_POLARITY_POSITIVE; |
| 260 | ldp = LDP_10NS; |
| 261 | ldf = LDF_FRAC_N; |
| 262 | charge_pump_current = CHARGE_PUMP_CURRENT_0_31MA; |
| 263 | double_buffer = DOUBLE_BUFFER_DISABLED; |
| 264 | r_counter_10_bit = 1; |
| 265 | reference_divide_by_2 = REFERENCE_DIVIDE_BY_2_DISABLED; |
| 266 | reference_doubler = REFERENCE_DOUBLER_DISABLED; |
| 267 | muxout = MUXOUT_3STATE; |
| 268 | low_noise_and_spur = LOW_NOISE_AND_SPUR_LOW_NOISE; |
| 269 | clock_divider_12_bit = 0; |
| 270 | clock_div_mode = CLOCK_DIV_MODE_CLOCK_DIVIDER_OFF; |
| 271 | cycle_slip_reduction = CYCLE_SLIP_REDUCTION_DISABLED; |
| 272 | charge_cancel = CHARGE_CANCEL_DISABLED; |
| 273 | antibacklash_pulse = ANTIBACKLASH_PULSE_6NS; |
| 274 | band_sel_clk_mode = BAND_SEL_CLK_MODE_LOW; |
| 275 | output_power = OUTPUT_POWER_M4DBM; |
| 276 | rf_output_enable = RF_OUTPUT_ENABLE_DISABLED; |
| 277 | aux_output_power = AUX_OUTPUT_POWER_M4DBM; |
| 278 | aux_output_enable = AUX_OUTPUT_ENABLE_DISABLED; |
| 279 | aux_output_select = AUX_OUTPUT_SELECT_DIVIDED; |
| 280 | mute_till_lock_detect = MUTE_TILL_LOCK_DETECT_MUTE_DISABLED; |
| 281 | vco_power_down = VCO_POWER_DOWN_VCO_POWERED_DOWN; |
| 282 | band_select_clock_div = 1; |
| 283 | rf_divider_select = RF_DIVIDER_SELECT_DIV1; |
| 284 | feedback_select = FEEDBACK_SELECT_DIVIDED; |
| 285 | ld_pin_mode = LD_PIN_MODE_DLD; |
| 286 | } |
| 287 | |
| 288 | enum addr_t{ |
| 289 | ADDR_R0 = 0, |
| 290 | ADDR_R1 = 1, |
| 291 | ADDR_R2 = 2, |
| 292 | ADDR_R3 = 3, |
| 293 | ADDR_R4 = 4, |
| 294 | ADDR_R5 = 5 |
| 295 | }; |
| 296 | |
| 297 | //Generate the registers |
| 298 | uint32_t get_reg(int8_t addr){ |
| 299 | int32_t reg = addr & 0x7; |
| 300 | switch(addr){ |
| 301 | case 0: |
| 302 | reg |= (uint32_t(frac_12_bit) & 0xfff) << 3; |
| 303 | reg |= (uint32_t(int_16_bit) & 0xffff) << 15; |
| 304 | break; |
| 305 | case 1: |
| 306 | reg |= (uint32_t(mod_12_bit) & 0xfff) << 3; |
| 307 | reg |= (uint32_t(phase_12_bit) & 0xfff) << 15; |
| 308 | reg |= (uint32_t(prescaler) & 0x1) << 27; |
| 309 | break; |
| 310 | case 2: |
| 311 | reg |= (uint32_t(counter_reset) & 0x1) << 3; |
| 312 | reg |= (uint32_t(cp_three_state) & 0x1) << 4; |
| 313 | reg |= (uint32_t(power_down) & 0x1) << 5; |
| 314 | reg |= (uint32_t(pd_polarity) & 0x1) << 6; |
| 315 | reg |= (uint32_t(ldp) & 0x1) << 7; |
| 316 | reg |= (uint32_t(ldf) & 0x1) << 8; |
| 317 | reg |= (uint32_t(charge_pump_current) & 0xf) << 9; |
| 318 | reg |= (uint32_t(double_buffer) & 0x1) << 13; |
| 319 | reg |= (uint32_t(r_counter_10_bit) & 0x3ff) << 14; |
| 320 | reg |= (uint32_t(reference_divide_by_2) & 0x1) << 24; |
| 321 | reg |= (uint32_t(reference_doubler) & 0x1) << 25; |
| 322 | reg |= (uint32_t(muxout) & 0x7) << 26; |
| 323 | reg |= (uint32_t(low_noise_and_spur) & 0x3) << 29; |
| 324 | break; |
| 325 | case 3: |
| 326 | reg |= (uint32_t(clock_divider_12_bit) & 0xfff) << 3; |
| 327 | reg |= (uint32_t(clock_div_mode) & 0x3) << 15; |
| 328 | reg |= (uint32_t(cycle_slip_reduction) & 0x1) << 18; |
| 329 | break; |
| 330 | case 4: |
| 331 | reg |= (uint32_t(output_power) & 0x3) << 3; |
| 332 | reg |= (uint32_t(rf_output_enable) & 0x1) << 5; |
| 333 | reg |= (uint32_t(aux_output_power) & 0x3) << 6; |
| 334 | reg |= (uint32_t(aux_output_enable) & 0x1) << 8; |
| 335 | reg |= (uint32_t(aux_output_select) & 0x1) << 9; |
| 336 | reg |= (uint32_t(mute_till_lock_detect) & 0x1) << 10; |
| 337 | reg |= (uint32_t(vco_power_down) & 0x1) << 11; |
| 338 | reg |= (uint32_t(band_select_clock_div) & 0xff) << 12; |
| 339 | reg |= (uint32_t(rf_divider_select) & 0x7) << 20; |
| 340 | reg |= (uint32_t(feedback_select) & 0x1) << 23; |
| 341 | break; |
| 342 | case 5: |
| 343 | reg |= (uint32_t(3) & 0x3) << 19; |
| 344 | reg |= (uint32_t(0) & 0x1) << 21; |
| 345 | reg |= (uint32_t(ld_pin_mode) & 0x3) << 22; |
| 346 | break; |
| 347 | } |
| 348 | return reg; |
| 349 | }; |
| 350 | |
| 351 | //Set the frequency |
| 352 | double set_freq(double TargetFreq, double RefIn, int chan_mod = 4095, bool debug = false) { |
| 353 | //cout << "Target Frequency is: " << (TargetFreq/1e6) << "MHz" << endl; |
| 354 | |
| 355 | double actual_freq, pfd_freq; |
| 356 | //************************************************************************** |
| 357 | //Set reference oscillator frequency here |
| 358 | //************************************************************************** |
| 359 | double ref_freq = RefIn; |
| 360 | int R=0, BS=0, N=0, FRAC=0, MOD=0; |
| 361 | int RFdiv = 1; |
| 362 | int RFreg = 0; |
| 363 | |
| 364 | //Sanity check frequency |
| 365 | if ( ( TargetFreq < ADF4351_MIN_OUT_FREQ) || (TargetFreq > ADF4350_MAX_OUT_FREQ) ) { |
| 366 | std::cerr << "Error Setting Frequency: Valid values limited to [34375000,4400000000]" << std::endl; |
| 367 | return 1; |
| 368 | }; |
| 369 | |
| 370 | adf4351_regs_t::reference_divide_by_2_t T = adf4351_regs_t::REFERENCE_DIVIDE_BY_2_DISABLED; |
| 371 | adf4351_regs_t::reference_doubler_t D = adf4351_regs_t::REFERENCE_DOUBLER_DISABLED; |
| 372 | |
| 373 | //Reference doubler for 50% duty cycle |
| 374 | // if ref_freq < 12.5MHz enable regs.reference_divide_by_2 |
| 375 | if(ref_freq <= 12.5e6) D = adf4351_regs_t::REFERENCE_DOUBLER_ENABLED; |
| 376 | |
| 377 | //increase RF divider until acceptable VCO frequency |
| 378 | double vco_freq = TargetFreq; |
| 379 | while (vco_freq < 2.2e9) { |
| 380 | vco_freq *= 2; |
| 381 | RFdiv *= 2; |
| 382 | RFreg++; |
| 383 | } |
| 384 | |
| 385 | //use 8/9 prescaler for vco_freq > 3 GHz (pg.18 prescaler) |
| 386 | adf4351_regs_t::prescaler_t prescaler = vco_freq > 3e9 ? adf4351_regs_t::PRESCALER_8_9 : adf4351_regs_t::PRESCALER_4_5; |
| 387 | int min_int_divider = prescaler == adf4351_regs_t::PRESCALER_4_5 ? 23 : 75; //Min Int divider is 23 for 4/5 and 75 for 8/9 |
| 388 | |
| 389 | //cout << "Minimum Divider is: " << int(min_int_divider) << endl; |
| 390 | |
| 391 | /* |
| 392 | * The goal here is to loop though possible R dividers, |
| 393 | * band select clock dividers, N (int) dividers, and FRAC |
| 394 | * (frac) dividers. |
| 395 | * |
| 396 | * Calculate the N and F dividers for each set of values. |
| 397 | * The loop exists when it meets all of the constraints. |
| 398 | * The resulting loop values are loaded into the registers. |
| 399 | * |
| 400 | * from pg.21 |
| 401 | * |
| 402 | * f_pfd = f_ref*(1+D)/(R*(1+T)) |
| 403 | * f_vco = (N + (FRAC/MOD))*f_pfd |
| 404 | * N = f_vco/f_pfd - FRAC/MOD = f_vco*((R*(T+1))/(f_ref*(1+D))) - FRAC/MOD |
| 405 | * f_rf = f_vco/RFdiv) |
| 406 | * f_actual = f_rf |
| 407 | */ |
| 408 | |
| 409 | for(R = 1; R <= 1023; R+=1){ |
| 410 | //PFD input frequency = f_ref/R ... ignoring Reference doubler/divide-by-2 (D & T) |
| 411 | pfd_freq = ref_freq*(1+D)/(R*(1+T)); |
| 412 | |
| 413 | //keep the PFD frequency at or below 31.25e6MHz (Loop Filter Bandwidth) |
| 414 | if (pfd_freq > ADF4350_DESIGN_PFD) continue; |
| 415 | |
| 416 | //ignore fractional part of tuning |
| 417 | N = int(floor(vco_freq/pfd_freq)); |
| 418 | |
| 419 | //keep N > minimum int divider requirement |
| 420 | if (N < min_int_divider) continue; |
| 421 | |
| 422 | for(BS=1; BS <= 255; BS+=1){ |
| 423 | //keep the band select frequency at or below 125KHz |
| 424 | //constraint on band select clock |
| 425 | if (pfd_freq/BS > 125e3) continue; |
| 426 | goto done_loop; |
| 427 | } |
| 428 | } done_loop: |
| 429 | |
| 430 | //Fractional-N calculation |
| 431 | // MOD = 4095; //max fractional accuracy //DEBUGGING ADF |
| 432 | MOD = chan_mod; |
| 433 | |
| 434 | FRAC = round( double( ((vco_freq/pfd_freq) - N)*MOD) ); |
| 435 | |
| 436 | //Reference divide-by-2 for 50% duty cycle |
| 437 | // if R even, move one divide by 2 to to regs.reference_divide_by_2 |
| 438 | if(R % 2 == 0){ |
| 439 | T = adf4351_regs_t::REFERENCE_DIVIDE_BY_2_ENABLED; |
| 440 | R /= 2; |
| 441 | } |
| 442 | |
| 443 | //actual frequency calculation |
| 444 | actual_freq = double((N + (double(FRAC)/double(MOD))) * ref_freq * (1+int(D)) / (R*(1+int(T))) /RFdiv ); |
| 445 | |
| 446 | frac_12_bit = FRAC; |
| 447 | int_16_bit = N; |
| 448 | mod_12_bit = MOD; |
| 449 | prescaler = prescaler; |
| 450 | r_counter_10_bit = R; |
| 451 | reference_divide_by_2 = T; |
| 452 | reference_doubler = D; |
| 453 | band_select_clock_div = BS; |
| 454 | rf_divider_select = (adf4351_regs_t::rf_divider_select_t)(RFreg); |
| 455 | |
| 456 | aux_output_power = adf4351_regs_t::AUX_OUTPUT_POWER_M4DBM; |
| 457 | aux_output_enable = adf4351_regs_t::AUX_OUTPUT_ENABLE_DISABLED; |
| 458 | aux_output_select = adf4351_regs_t::AUX_OUTPUT_SELECT_DIVIDED; |
| 459 | |
| 460 | if (debug == true){ |
| 461 | std::cout |
| 462 | << "Synth Param: " |
| 463 | << "\tpfd= " << (ref_freq*(1+int(D))/(R*(1+int(T)))) |
| 464 | << "\toutdiv= " << double(RFdiv) |
| 465 | << "\tfbdiv= " << double(N + double(FRAC)/double(MOD)) |
| 466 | << std::endl |
| 467 | |
| 468 | << "Registers Set: " |
| 469 | << std::dec |
| 470 | << "\tR= " << R |
| 471 | << "\tBS= " << BS |
| 472 | << "\tN= " << N |
| 473 | << "\tFRAC= " << FRAC |
| 474 | << "\tMOD= " << MOD |
| 475 | << "\tT= " << T |
| 476 | << "\tD= " << D |
| 477 | << "\tRFdiv= " << int(RFdiv) |
| 478 | << std::endl |
| 479 | |
| 480 | << "Calc (MHz):" |
| 481 | << "\tREQ= " << double(TargetFreq/1e6) |
| 482 | << "\tACT= " << double(actual_freq/1e6) |
| 483 | << "\tVCO= " << double(vco_freq/1e6) |
| 484 | << "\tPFD= " << double(pfd_freq/1e6) |
| 485 | << "\tSPAC= " << double(pfd_freq/BS/1e6) |
| 486 | << std::endl |
| 487 | |
| 488 | << "Actual Frequency is " |
| 489 | << (actual_freq/1e6) |
| 490 | << "MHz" |
| 491 | << std::endl; |
| 492 | }; |
| 493 | |
| 494 | return actual_freq; |
| 495 | }; |
| 496 | |
| 497 | }; |
| 498 | |
| 499 | |
| 500 | |
| 501 | |
| 502 | #endif /* INCLUDED_ADF4350_REGS_HPP */ |