107 int8_t address_shift;
110 address_shift =(address << 1) | 0x01;
127 int bit_shift,
i, num_reg;
128 long field_val, maskbits, pow2;
135 bit_shift = (MSB_loc+1)- (numbits-num_reg*8);
136 field_val=
LTC6950_read(cs, (address+num_reg))+(field_val<<8);
139 while ((bit_shift<0) && (num_reg<4));
144 for (i=1, maskbits=1; i<numbits; i++)
147 maskbits = maskbits+pow2;
150 field_val=(field_val >>bit_shift) &maskbits;
176 address=address << 1;
190 long current_content, desired_content, reg_val;
191 int LSB_loc,
i, j, num_reg, bit_shift;
194 for (i=0; i<32 ; i++) temp_arr[i]=0;
201 bit_shift=(MSB_loc+1)-(numbits-num_reg*8);
202 current_content=
LTC6950_read(cs, (address+num_reg)) + (current_content<<8);
206 while ((bit_shift<0) && (num_reg<4));
207 for (i=0; i<(8*num_reg); i++)
209 temp_arr[
i]=(current_content>>
i) & 1;
213 LSB_loc = 8*(num_reg-1)+MSB_loc-numbits+1;
214 for (i=LSB_loc, j=0; i<=(MSB_loc+(num_reg-1)*8); i++, j++)
216 temp_arr[
i] = (field_data>>j) &1;
221 for (i=0; i<(8*num_reg); i++)
223 desired_content = desired_content | (temp_arr[
i]<<
i);
227 for (i=0; i<num_reg; i++)
229 reg_val = (desired_content >> 8*(num_reg-1-
i)) & 0xff;
282 void set_LTC6950_ALLREGS(uint8_t cs, uint8_t reg01, uint8_t reg02, uint8_t reg03, uint8_t reg04, uint8_t reg05, uint8_t reg06, uint8_t reg07,
283 uint8_t reg08, uint8_t reg09, uint8_t reg0A, uint8_t reg0B, uint8_t reg0C, uint8_t reg0D, uint8_t reg0E, uint8_t reg0F,
284 uint8_t reg10, uint8_t reg11, uint8_t reg12, uint8_t reg13, uint8_t reg14, uint8_t reg15)
631 void set_LTC6950_global_vcolim(
unsigned long fvco_max_MHz,
unsigned long fvco_max_Hz,
unsigned long fvco_min_MHz,
unsigned long fvco_min_Hz)
689 unsigned long odiv,
i;
690 unsigned long max_fout64[2];
691 unsigned long min_fout64[2];
692 unsigned long temp_fout[2];
693 unsigned long temp_i[2];
694 boolean valid_input=
false;
702 for (i=1; i<=63; i++)
705 temp_fout[0] = frf[0];
706 temp_fout[1] = frf[1];
707 mul64(temp_fout,temp_i);
708 if (
lt64(temp_fout,max_fout64) ||
eq64(temp_fout, max_fout64))
710 if (
lt64(min_fout64,temp_fout) ||
eq64(temp_fout, min_fout64))
718 if (valid_input ==
false) odiv= 999L;
768 unsigned long frf_MHz, frf_Hz, fref_MHz, fref_Hz, M0div, rdiv, ndiv, N_remainder;
769 unsigned long N64[2], R64[2], MO64[2], temp_long[2];
771 unsigned long frf[2], frf_act[2];
772 unsigned long fref[2];
773 unsigned long temp_math[2];
774 unsigned long frf_rdiv_M0div[2];
775 unsigned long frf_rdiv_M0div_int[2];
776 unsigned long roundup[2];
782 HZto64(frf, frf_MHz, frf_Hz);
786 HZto64(fref,fref_MHz,fref_Hz);
796 frf_rdiv_M0div[1]=M0div*rdiv;
797 mul64(frf_rdiv_M0div, frf);
798 frf_rdiv_M0div_int[0]=frf_rdiv_M0div[0];
799 frf_rdiv_M0div_int[1]=frf_rdiv_M0div[1];
802 temp_math[0]=fref[0];
803 temp_math[1]=fref[1];
804 div64(frf_rdiv_M0div_int, temp_math);
805 ndiv=frf_rdiv_M0div_int[1];
809 temp_math[0]=fref[0];
810 temp_math[1]=fref[1];
812 div64(frf_rdiv_M0div,temp_math);
813 shl64by(frf_rdiv_M0div_int,16);
814 sub64(frf_rdiv_M0div,frf_rdiv_M0div_int);
820 N_remainder = (frf_rdiv_M0div[1] & 65535L);
821 if (N_remainder >= 32768)
828 Serial.print(
"M0 = ");
829 Serial.println(M0div);
831 Serial.print(
"RD = ");
832 Serial.println(rdiv);
835 Serial.print(F(
"ND = "));
836 Serial.println(ndiv);
855 Serial.print(F(
"Actual Output Frequency (closest available) is "));
856 Serial.print(frf_act[1]);
857 Serial.println(
"Hz");
861 temp_math[0]=frf_act[0];
862 temp_math[1]=frf_act[1];
865 div64(temp_math,temp_long);
866 Serial.print(F(
"Actual Output Frequency (closest available) is "));
867 Serial.print(temp_math[1]);
868 Serial.print(
"MHz + ");
871 mul64(temp_math,temp_long);
872 sub64(frf_act,temp_math);
873 Serial.print(frf_act[1]);
874 Serial.println(
"Hz");
883 void prt(
unsigned long an[])
885 Serial.print(an[0],HEX);
887 Serial.println(an[1],HEX);
897 void init64(
unsigned long an[],
unsigned long bigPart,
unsigned long littlePart )
914 void HZto64(
unsigned long an[],
unsigned long MHzPart,
unsigned long HzPart )
917 if ((MHzPart>4295) || ((MHzPart==4294) && (HzPart>=967296)))
920 an[1] =(MHzPart-4294L)*
OneMHz + HzPart-967296L;
925 an[1] = MHzPart*
OneMHz+HzPart;
936 if (an[1] & 0x80000000)
959 void shl64by(
unsigned long an[], uint8_t shiftnum)
963 for (i=0; i<shiftnum; i++)
966 if (an[1] & 0x80000000)
977 void shr64by(
unsigned long an[], uint8_t shiftnum)
981 for (i=0; i<shiftnum; i++)
995 void add64(
unsigned long an[],
unsigned long ann[])
998 if (an[1] + ann[1] < ann[1])
1008 void sub64(
unsigned long an[],
unsigned long ann[])
1023 boolean eq64(
unsigned long an[],
unsigned long ann[])
1025 return (an[0]==ann[0]) && (an[1]==ann[1]);
1033 boolean lt64(
unsigned long an[],
unsigned long ann[])
1035 if (an[0]>ann[0])
return false;
1036 return (an[0]<ann[0]) || (an[1]<ann[1]);
1044 void div64(
unsigned long num[],
unsigned long den[])
1046 unsigned long quot[2];
1047 unsigned long qbit[2];
1048 unsigned long tmp[2];
1060 init64(num,0xffffffff,0xffffffff);
1064 init64(tmp,0x80000000,0);
1065 while (
lt64(den,tmp))
1073 if (
lt64(den,num) ||
eq64(den,num))
1083 init64(num,quot[0],quot[1]);
1091 void mul64(
unsigned long an[],
unsigned long ann[])
1093 unsigned long p[2] = {0,0};
1094 unsigned long y[2] = {ann[0], ann[1]};
#define LTC6950_RES6950
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_CPWIDE
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long get_LTC6950_global_frf_MHz()
returns global LTC6950_Frf_MHz
#define LTC6950_DEL4
for spi_map array, defines location for field specific information used to create the spi map ...
uint8_t get_LTC6950_SPI_FIELD_NUMBITS(uint8_t f)
returns the number of bits for a given field name in the SPI map
#define LTC6950_N
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_NO_REF
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_M3
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_PD_OUT2
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_RESET_N
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_PD_OUT1
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_FLDRV2
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_RESET_R
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_CS
Define the SPI CS pin.
#define LTC6950_LKCT
for spi_map array, defines location for field specific information used to create the spi map ...
void HZto64(unsigned long an[], unsigned long MHzPart, unsigned long HzPart)
create a 64 bit Hz number from 32 bit xxxx MHz number and 32 bit yyy yyy Hz number.
unsigned long LTC6950_calc_odiv(unsigned long frf[2])
calculates the output divider setting based on the frf and on board VCO frequencies of LTC6950 ...
#define LTC6950_CPCLO
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_SYNC_EN4
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_IBIAS2
for spi_map array, defines location for field specific information used to create the spi map ...
boolean lt64(unsigned long an[], unsigned long ann[])
64 bit, if an < ann, then true
#define LTC6950_SYNC_EN0
for spi_map array, defines location for field specific information used to create the spi map ...
Header File for Linduino Libraries and Demo Code.
#define LTC6950_PDALL
for spi_map array, defines location for field specific information used to create the spi map ...
void LTC6950_set_frf()
FUNCTION: LTC6950_set_frf Calculates the integer (N) and output divider (OD) SPI values using self cr...
#define LTC6950_SYNCMD
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_CPCHI
for spi_map array, defines location for field specific information used to create the spi map ...
void add64(unsigned long an[], unsigned long ann[])
64 bit Add ann to an (an[] = an[] + ann[])
#define LTC6950_PDREFAC
for spi_map array, defines location for field specific information used to create the spi map ...
void sub64(unsigned long an[], unsigned long ann[])
64 bit Subtract ann from an (an[] = an[] - ann[])
void set_LTC6950_global_frf(unsigned long frf_MHz, unsigned long frf_Hz)
sets globals LTC6950_Frf_MHz and LTC6950_Frf_Hz
#define OneMHz
1MHz in long format, used in 64 bit math
unsigned long LTC6950_Fref_MHz
Default Fref frequency - MHz portion (xxx); Fref = xxx, yyy,yyy.
#define LTC6950_TLO
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_INV_ST2
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_FILTV
for spi_map array, defines location for field specific information used to create the spi map ...
void shr64by(unsigned long an[], uint8_t shiftnum)
Multi Bit shift right of equivalent 64 bit number (an[] = an[]>>shiftnum)
#define LTC6950_PDPLL
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_PDVCOAC
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_PD_DIV3
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_R
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_M1
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long get_LTC6950_global_frf_Hz()
returns global LTC6950_Frf_Hz
#define LTC6950_SYNC_EN3
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_LKEN
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_LKWIN
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long LTC6950_Frf_MHz
Default Frf frequency - MHz portion (xxxx); Frf = x,xxx, yyy,yyy.
void mul64(unsigned long an[], unsigned long ann[])
64 bit multiply, an=an*ann
void shl64(unsigned long an[])
Single Bit shift left of equivalent 64 bit number (an[] = an[]<<1)
#define LTC6950_UNLOCK
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_SYNC_EN1
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_DEL0
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long LTC6950_VCO_Min_Freq_Hz
Min Vco frequency for default on board VCO - Hz portion (yyy,yyy); Fvco min= x,xxx, yyy,yyy.
#define LTC6950_CPUP
for spi_map array, defines location for field specific information used to create the spi map ...
long get_LTC6950_SPI_FIELD(uint8_t cs, uint8_t f)
Gets the LTC6950 SPI field value calls function LTC6950_read_field, which reads specific address loca...
void shl64by(unsigned long an[], uint8_t shiftnum)
Multi Bit shift left of equivalent 64 bit number (an[] = an[]<<shiftnum)
LTC6950: 1.4GHz Low Phase Noise, Low Jitter PLL with Clock Distribution.
void set_LTC6950_ALLREGS(uint8_t cs, uint8_t reg01, uint8_t reg02, uint8_t reg03, uint8_t reg04, uint8_t reg05, uint8_t reg06, uint8_t reg07, uint8_t reg08, uint8_t reg09, uint8_t reg0A, uint8_t reg0B, uint8_t reg0C, uint8_t reg0D, uint8_t reg0E, uint8_t reg0F, uint8_t reg10, uint8_t reg11, uint8_t reg12, uint8_t reg13, uint8_t reg14, uint8_t reg15)
Writes values to ALL LTC6950 RW addresses.
void div64(unsigned long num[], unsigned long den[])
64 bit Divide, num=num/div
uint16_t LT_uint16
16-bit unsigned integer to be converted to two bytes
void set_LTC6950_global_fref(unsigned long fref_MHz, unsigned long fref_Hz)
sets globals LTC6950_Fref_MHz and LTC6950_Fref_Hz
boolean eq64(unsigned long an[], unsigned long ann[])
64 bit, if an == ann, then true
#define R_ONLY
used for 2nd dim of 2d spi_map array
void spi_transfer_word(uint8_t cs_pin, uint16_t tx, uint16_t *rx)
Reads and sends a word.
#define LTC6950_M0
for spi_map array, defines location for field specific information used to create the spi map ...
uint8_t LTC6950_spi_map[(LTC6950_NUM_REGFIELD+1)][4]
LTC6950 spi map, stores MSB address location, MSB bit location, field length in bits, and R or RW capability.
unsigned long get_LTC6950_global_VCO_MAX_MHz()
returns global LTC6950_VCO_Max_Freq_MHz
#define LTC6950_DEL3
for spi_map array, defines location for field specific information used to create the spi map ...
uint8_t LTC6950_reg[LTC6950_NUM_REGADDR]
number of LTC6950 spi addresses
#define LTC6950_DEL1
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_FLDRV4
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_M4
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_PD_DIV2
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long get_LTC6950_global_VCO_MIN_MHz()
returns global LTC6950_VCO_Min_Freq_MHz
#define LTC6950_FLDRV0
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_REV
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_SM2
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_CPMID
for spi_map array, defines location for field specific information used to create the spi map ...
void LTC6950_write(uint8_t cs, uint8_t address, uint8_t Data)
LTC6950 Write Single Address writes 8 bit Data field to LTC6950.
LT_SPI: Routines to communicate with ATmega328P's hardware SPI port.
uint8_t get_LTC6950_SPI_FIELD_RW(uint8_t f)
returns if the given field name is (0)read/write or (1)read_only field
#define LTC6950_PD_OUT3
for spi_map array, defines location for field specific information used to create the spi map ...
uint8_t LTC6950_write_field(uint8_t cs, long field_data, uint8_t address, uint8_t MSB_loc, uint8_t numbits)
LTC6950 Write Single Field For SPI FIELDS in 1 or multiple address locations reads specific address/f...
#define LTC6950_NUM_REGADDR
Defines number of LTC6950 SPI registers, used in spi_map array.
void shr64(unsigned long an[])
Single Bit shift right of equivalent 64 bit number (an[] = an[]<<1)
#define LTC6950_M2
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_RDIVOUT
for spi_map array, defines location for field specific information used to create the spi map ...
#define ADDRx
used for 2nd dim of 2d spi_map array
uint8_t LTC6950_read(uint8_t cs, int8_t address)
LTC6950 Read Single Address reads 8 bit Data field to LTC6950.
#define LTC6950_NUM_REGFIELD
Defines number of LTC6950 SPI fields, used in spi_map array.
#define LTC6950_IBIAS0
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long get_LTC6950_global_fref_MHz()
returns global LTC6950_Fref_MHz
void set_LTC6950_global_vcolim(unsigned long fvco_max_MHz, unsigned long fvco_max_Hz, unsigned long fvco_min_MHz, unsigned long fvco_min_Hz)
sets globals LTC6950_VCO_Max_Freq_MHz, LTC6950_VCO_Max_Freq_Hz, LTC6950_VCO_Min_Freq_MHz and LTC6950_...
void set_LTC6950_SPI_FIELD(uint8_t cs, uint8_t f, long field_data)
Sets the LTC6950 SPI field value calls function LTC6950_read_field, which reads specific address/fiel...
void LTC6950_init()
Initializes the SPI MAP arrays The values set in initialization are used for all the LTC6950 SPI/WRIT...
#define LTC6950_CPRST
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_PART
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_INV_ST1
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_SYNC_EN2
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long LTC6950_Fref_Hz
Default Fref frequency - Hz portion (yyy,yyy); Fref = x,xxx, yyy,yyy.
unsigned long get_LTC6950_global_VCO_MIN_Hz()
returns global LTC6950_VCO_Min_Freq_Hz
#define LTC6950_NO_VCO
for spi_map array, defines location for field specific information used to create the spi map ...
This union splits one int16_t (16-bit signed integer) or uint16_t (16-bit unsigned integer) into two ...
void init64(unsigned long an[], unsigned long bigPart, unsigned long littlePart)
Creates a equivalent 64 bit number from 2 32 bit numbers.
unsigned long LTC6950_Frf_Hz
Default Frf frequency - Hz portion (yyy,yyy); Frf = x,xxx, yyy,yyy.
#define LTC6950_IBIAS1
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_FLDRV3
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long get_LTC6950_global_fref_Hz()
returns global LTC6950_Fref_Hz
#define LTC6950_CPDN
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long LTC6950_VCO_Max_Freq_Hz
Max Vco frequency for default on board VCO - Hz portion (yyy,yyy); Fvco max = x,xxx, yyy,yyy.
uint8_t get_LTC6950_REGSIZE()
returns # of addresses in parts register map (array size)
unsigned long get_LTC6950_global_VCO_MAX_Hz()
returns global LTC6950_VCO_Max_Freq_Hz
#define LTC6950_LOCK
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_SM1
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_PD_OUT0
for spi_map array, defines location for field specific information used to create the spi map ...
long LTC6950_read_field(uint8_t cs, uint8_t address, uint8_t MSB_loc, uint8_t numbits)
LTC6950 Read Single Field For SPI FIELDS located in 1 or multiple address location reads specific add...
#define LTC6950_CP
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_FLDRV1
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_PD_DIV1
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_CMSINV
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_PD_OUT4
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_PD_DIV0
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_LVCMS
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long LTC6950_VCO_Max_Freq_MHz
Max Vco frequency for default on board VCO - MHz portion (xxxx); Fvco max = xxx, yyy,yyy.
uint8_t LT_byte[2]
2 bytes (unsigned 8-bit integers) to be converted to a 16-bit signed or unsigned integer ...
#define LTC6950_DEL2
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_PD_DIV4
for spi_map array, defines location for field specific information used to create the spi map ...
void prt(unsigned long an[])
Prints HEX representation of 64 bit an.
#define LTC6950_IBIAS3
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_THI
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long LTC6950_VCO_Min_Freq_MHz
Min Vco frequency for default on board VCO - MHz portion (xxxx); Fvco min = x,xxx, yyy,yyy.
#define LTC6950_CPINV
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6950_FILTR
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long zero64[]
for 64bit math functions
#define DxMSB
used for 2nd dim of 2d spi_map array