EU1KY AA
adf4351.c File Reference
#include "stm32746g_discovery.h"
#include "adf4351.h"
#include <math.h>
#include "si5351.h"
#include "custom_spi2.h"

Data Structures

union  ADF4351_Reg0_t
 Union type for the structure of Register0 in ADF4351. More...
 
union  ADF4351_Reg1_t
 Union type for the structure of Register1 in ADF4351. More...
 
union  ADF4351_Reg2_t
 Union type for the structure of Register2 in ADF4351. More...
 
union  ADF4351_Reg3_t
 Union type for the structure of Register3 in ADF4351. More...
 
union  ADF4351_Reg4_t
 Union type for the structure of Register4 in ADF4351. More...
 
union  ADF4351_Reg5_t
 Union type for the structure of Register5 in ADF4351. More...
 

Macros

#define ADF5451_PFD_MAX   32.0e6
 
#define ADF4351_RFOUT_MAX   4400.0e6
 
#define ADF4351_RFOUTMIN   34.375e6
 
#define ADF4351_REFINMAX   250.0e6
 

Enumerations

enum  ADF4351_PHASE_ADJ_t { ADF4351_PHASE_ADJ_OFF, ADF4351_PHASE_ADJ_ON }
 Phase adjust type The phase adjust bit (Bit DB28) enables adjustment of the output phase of a given output frequency. More...
 
enum  ADF4351_PRESCALER_t { ADF4351_PRESCALER_4_5, ADF4351_PRESCALER_8_9 }
 Prescaler Value type The dual-modulus prescaler (P/P + 1), along with the INT, FRAC, and MOD values, determines the overall division ratio from the VCO output to the PFD input. More...
 
enum  ADF4351_SPURNOISE_t { ADF4351_LOW_NOISE_MODE, ADF4351_LOW_SPUR_MODE = 3 }
 Low Noise and Low Spur Modes type The noise mode allows the user to optimize a design either for improved spurious performance or for improved phase noise performance. More...
 
enum  ADF4351_MUX_t {
  ADF4351_MUX_THREESTATE, ADF4351_MUX_DVDD, ADF4351_MUX_DGND, ADF4351_MUX_RCOUNTER,
  ADF4351_MUX_NDIVIDER, ADF4351_MUX_ANALOGLOCK, ADF4351_MUX_DIGITALLOCK
}
 MUXOUT type The on-chip multiplexer. More...
 
enum  ADF4351_ED_t { ADF4351_DISABLE, ADF4351_ENABLE }
 Disable/Enable type various bits are Disable(0)/Enable(1) type. More...
 
enum  ADF4351_CPCURRENT_t {
  ADF4351_CPCURRENT_0_31, ADF4351_CPCURRENT_0_63, ADF4351_CPCURRENT_0_94, ADF4351_CPCURRENT_1_25,
  ADF4351_CPCURRENT_1_56, ADF4351_CPCURRENT_1_88, ADF4351_CPCURRENT_2_19, ADF4351_CPCURRENT_2_50,
  ADF4351_CPCURRENT_2_81, ADF4351_CPCURRENT_3_13, ADF4351_CPCURRENT_3_44, ADF4351_CPCURRENT_3_75,
  ADF4351_CPCURRENT_4_06, ADF4351_CPCURRENT_4_38, ADF4351_CPCURRENT_4_69, ADF4351_CPCURRENT_5_00
}
 Charge Pump Current Setting type This value should be set to the charge pump current that the loop filter is designed with. More...
 
enum  ADF4351_LDF_t { ADF4351_LDF_FRAC, ADF4351_LDF_INT }
 Lock Detect Function type The LDF controls the number of PFD cycles monitored by the lock detect circuit to ascertain whether lock has been achieved. More...
 
enum  ADF4351_LDP_t { ADF4351_LDP_10NS, ADF4351_LDP_6NS }
 Lock Detect Precision type The lock detect precision sets the comparison window in the lock detect circuit. More...
 
enum  ADF4351_POLARITY_t { ADF4351_POLARITY_NEGATIVE, ADF4351_POLARITY_POSITIVE }
 Phase Detector Polarity type Phase Detector Polarity. More...
 
enum  ADF4351_BANDCLOCK_t { ADF4351_BANDCLOCK_LOW, ADF4351_BANDCLOCK_HIGH }
 Band Select Clock Mode type. More...
 
enum  ADF4351_ABP_t { ADF4351_ABP_6NS, ADF4351_ABP_3NS }
 Antibacklash Pulse Width type. More...
 
enum  ADF4351_CLKDIVMODE_t { ADF4351_CLKDIVMODE_OFF, ADF4351_CLKDIVMODE_FAST_LOCK, ADF4351_CLKDIVMODE_RESYNC }
 Clock Divider Mode type. More...
 
enum  ADF4351_FEEDBACK_t { ADF4351_FEEDBACK_DIVIDED, ADF4351_FEEDBACK_FUNDAMENTAL }
 Feedback Select type. More...
 
enum  ADF4351_RFDIV_t {
  ADF4351_RFDIV_1, ADF4351_RFDIV_2, ADF4351_RFDIV_4, ADF4351_RFDIV_8,
  ADF4351_RFDIV_16, ADF4351_RFDIV_32, ADF4351_RFDIV_64
}
 RF Divider Select type. More...
 
enum  ADF4351_REFDIV_t { ADF4351_REFDIV_1, ADF4351_REFDIV_2 }
 Reference Divider. More...
 
enum  ADF4351_REFMUL_t { ADF4351_REFMUL_1, ADF4351_REFMUL_2 }
 Reference Doubler. More...
 
enum  ADF4351_VCO_POWER_t { ADF4351_VCO_POWERUP, ADF4351_VCO_POWERDOWN }
 VCO Power-Down type. More...
 
enum  ADF4351_POWER_t { ADF4351_POWER_MINUS4DB, ADF4351_POWER_MINUS1DB, ADF4351_POWER_PLUS2DB, ADF4351_POWER_PLUS5DB }
 Output Power type. More...
 
enum  ADF4351_LD_PIN_t { ADF4351_LD_PIN_LOW, ADF4351_LD_PIN_DIGITAL_LOCK, ADF4351_LD_PIN_LOW_, ADF4351_LD_PIN_HIGH }
 Lock Detect Pin Operation type. More...
 
enum  ADF4351_ERR_t {
  ADF4351_Err_None, ADF4351_Err_PFD, ADF4351_Err_BandSelFreqTooHigh, ADF4351_Err_InvalidRCounterValue,
  ADF4351_Err_NoGCD_PhaseAdj, ADF4351_Err_RFoutTooHigh, ADF4351_Err_RFoutTooLow, ADF4351_Err_REFinTooHigh,
  ADF4351_Err_InvalidN, ADF4351_Err_InvalidMOD, ADF4351_Warn_NotTuned, ADF4351_Err_InvalidMODLowSpur
}
 ADF4351 Driver Error codes. More...
 

Functions

static ADF4351_ERR_t UpdateFrequencyRegisters (double RFout, double REFin, double OutputChannelSpacing, int gcd, int AutoBandSelectClock, double *RFoutCalc)
 Main function to calculate register values based on required PLL output. More...
 
static uint32_t ADF4351_GetRegisterBuf (int addr)
 Returns current value from local register buffer. More...
 
static void ADF4351_SetRegisterBuf (int addr, uint32_t val)
 Set local register buffer value. More...
 
static void ADF4351_ClearRegisterBuf (void)
 Clear local register buffer values to 0. More...
 
static ADF4351_RFDIV_t ADF4351_Select_Output_Divider (double RFoutFrequency)
 Private Function Prototypes. More...
 
static uint32_t gcd_iter (uint32_t u, uint32_t v)
 
static ADF4351_ERR_t ADF4351_SetRcounterVal (uint16_t val)
 Set R counter value. More...
 
void ADF4351_Init (void)
 
void ADF4351_Off (void)
 
void ADF4351_SetF0 (uint32_t fhz)
 
void ADF4351_SetLO (uint32_t fhz)
 

Variables

static ADF4351_Reg0_t ADF4351_Reg0
 ADF4351 registers - local storage. More...
 
static ADF4351_Reg1_t ADF4351_Reg1
 
static ADF4351_Reg2_t ADF4351_Reg2
 
static ADF4351_Reg3_t ADF4351_Reg3
 
static ADF4351_Reg4_t ADF4351_Reg4
 
static ADF4351_Reg5_t ADF4351_Reg5
 

Macro Definition Documentation

#define ADF4351_REFINMAX   250.0e6
#define ADF4351_RFOUT_MAX   4400.0e6
#define ADF4351_RFOUTMIN   34.375e6
#define ADF5451_PFD_MAX   32.0e6

Enumeration Type Documentation

Antibacklash Pulse Width type.

Enumerator
ADF4351_ABP_6NS 
ADF4351_ABP_3NS 

Band Select Clock Mode type.

Enumerator
ADF4351_BANDCLOCK_LOW 
ADF4351_BANDCLOCK_HIGH 

Clock Divider Mode type.

Enumerator
ADF4351_CLKDIVMODE_OFF 
ADF4351_CLKDIVMODE_FAST_LOCK 
ADF4351_CLKDIVMODE_RESYNC 

Charge Pump Current Setting type This value should be set to the charge pump current that the loop filter is designed with.

Enumerator
ADF4351_CPCURRENT_0_31 
ADF4351_CPCURRENT_0_63 
ADF4351_CPCURRENT_0_94 
ADF4351_CPCURRENT_1_25 
ADF4351_CPCURRENT_1_56 
ADF4351_CPCURRENT_1_88 
ADF4351_CPCURRENT_2_19 
ADF4351_CPCURRENT_2_50 
ADF4351_CPCURRENT_2_81 
ADF4351_CPCURRENT_3_13 
ADF4351_CPCURRENT_3_44 
ADF4351_CPCURRENT_3_75 
ADF4351_CPCURRENT_4_06 
ADF4351_CPCURRENT_4_38 
ADF4351_CPCURRENT_4_69 
ADF4351_CPCURRENT_5_00 

Disable/Enable type various bits are Disable(0)/Enable(1) type.

Enumerator
ADF4351_DISABLE 
ADF4351_ENABLE 

ADF4351 Driver Error codes.

Enumerator
ADF4351_Err_None 

No error.

ADF4351_Err_PFD 

PFD max error check.

ADF4351_Err_BandSelFreqTooHigh 

Band select frequency too high.

ADF4351_Err_InvalidRCounterValue 

Invalid R couinter value.

ADF4351_Err_NoGCD_PhaseAdj 

No GCD when Phase adjust enabled.

ADF4351_Err_RFoutTooHigh 

Output frequency too high.

ADF4351_Err_RFoutTooLow 

Output frequency too low.

ADF4351_Err_REFinTooHigh 

Reference input too high.

ADF4351_Err_InvalidN 

N out of range.

ADF4351_Err_InvalidMOD 

MOD out of range.

ADF4351_Warn_NotTuned 

PLL output could not be tuned to exact frequency.

ADF4351_Err_InvalidMODLowSpur 

Min. MOD in low spur mode is 50.

Feedback Select type.

Enumerator
ADF4351_FEEDBACK_DIVIDED 

the signal is taken from the output of the output dividers

ADF4351_FEEDBACK_FUNDAMENTAL 

he signal is taken directly from the VCO

Lock Detect Pin Operation type.

Enumerator
ADF4351_LD_PIN_LOW 
ADF4351_LD_PIN_DIGITAL_LOCK 
ADF4351_LD_PIN_LOW_ 
ADF4351_LD_PIN_HIGH 

Lock Detect Function type The LDF controls the number of PFD cycles monitored by the lock detect circuit to ascertain whether lock has been achieved.

Enumerator
ADF4351_LDF_FRAC 
ADF4351_LDF_INT 

Lock Detect Precision type The lock detect precision sets the comparison window in the lock detect circuit.

Enumerator
ADF4351_LDP_10NS 
ADF4351_LDP_6NS 

MUXOUT type The on-chip multiplexer.

Enumerator
ADF4351_MUX_THREESTATE 
ADF4351_MUX_DVDD 
ADF4351_MUX_DGND 
ADF4351_MUX_RCOUNTER 
ADF4351_MUX_NDIVIDER 
ADF4351_MUX_ANALOGLOCK 
ADF4351_MUX_DIGITALLOCK 

Phase adjust type The phase adjust bit (Bit DB28) enables adjustment of the output phase of a given output frequency.

Enumerator
ADF4351_PHASE_ADJ_OFF 
ADF4351_PHASE_ADJ_ON 

Phase Detector Polarity type Phase Detector Polarity.

Enumerator
ADF4351_POLARITY_NEGATIVE 

For active filter with an inverting charac-teristic.

ADF4351_POLARITY_POSITIVE 

For passive loop filter or a noninverting active loop filter.

Output Power type.

Enumerator
ADF4351_POWER_MINUS4DB 
ADF4351_POWER_MINUS1DB 
ADF4351_POWER_PLUS2DB 
ADF4351_POWER_PLUS5DB 

Prescaler Value type The dual-modulus prescaler (P/P + 1), along with the INT, FRAC, and MOD values, determines the overall division ratio from the VCO output to the PFD input.

Enumerator
ADF4351_PRESCALER_4_5 

Prescaler = 4/5: NMIN = 23.

ADF4351_PRESCALER_8_9 

Prescaler = 8/9: NMIN = 75.

Reference Divider.

Enumerator
ADF4351_REFDIV_1 
ADF4351_REFDIV_2 

Reference Doubler.

Enumerator
ADF4351_REFMUL_1 
ADF4351_REFMUL_2 

RF Divider Select type.

Enumerator
ADF4351_RFDIV_1 
ADF4351_RFDIV_2 
ADF4351_RFDIV_4 
ADF4351_RFDIV_8 
ADF4351_RFDIV_16 
ADF4351_RFDIV_32 
ADF4351_RFDIV_64 

Low Noise and Low Spur Modes type The noise mode allows the user to optimize a design either for improved spurious performance or for improved phase noise performance.

Enumerator
ADF4351_LOW_NOISE_MODE 
ADF4351_LOW_SPUR_MODE 

VCO Power-Down type.

Enumerator
ADF4351_VCO_POWERUP 
ADF4351_VCO_POWERDOWN 

Function Documentation

static void ADF4351_ClearRegisterBuf ( void  )
static

Clear local register buffer values to 0.

Parameters
none
static uint32_t ADF4351_GetRegisterBuf ( int  addr)
static

Returns current value from local register buffer.

Parameters
addrRegister address
Return values
registervalue
void ADF4351_Init ( void  )
void ADF4351_Off ( void  )
static ADF4351_RFDIV_t ADF4351_Select_Output_Divider ( double  RFoutFrequency)
static

Private Function Prototypes.

void ADF4351_SetF0 ( uint32_t  fhz)
void ADF4351_SetLO ( uint32_t  fhz)
static ADF4351_ERR_t ADF4351_SetRcounterVal ( uint16_t  val)
static

Set R counter value.

Parameters
valCounter value (1...1023)
Return values
registervalue
static void ADF4351_SetRegisterBuf ( int  addr,
uint32_t  val 
)
static

Set local register buffer value.

Parameters
addrRegister address
static uint32_t gcd_iter ( uint32_t  u,
uint32_t  v 
)
static
static ADF4351_ERR_t UpdateFrequencyRegisters ( double  RFout,
double  REFin,
double  OutputChannelSpacing,
int  gcd,
int  AutoBandSelectClock,
double *  RFoutCalc 
)
static

Main function to calculate register values based on required PLL output.

Parameters
RFoutRequired PLL output frequency in Hz REFin: Reference clock in Hz OutputChannelSpacing: Output channel spacing in Hz gcd: calculate CGD (1) or not (0) AutoBandSelectClock: automatic calc of band selection clock RFoutCalc: Calculated actual output frequency in Hz
Return values
0=OK,orError code (ADF4351_ERR_t)

LOW

Variable Documentation

ADF4351_Reg0_t ADF4351_Reg0
static

ADF4351 registers - local storage.

ADF4351_Reg1_t ADF4351_Reg1
static
ADF4351_Reg2_t ADF4351_Reg2
static
ADF4351_Reg3_t ADF4351_Reg3
static
ADF4351_Reg4_t ADF4351_Reg4
static
ADF4351_Reg5_t ADF4351_Reg5
static