100 int8_t address_shift;
103 address_shift =(address << 1) | 0x01;
120 int bit_shift,
i, num_reg;
121 long field_val, maskbits, pow2;
128 bit_shift = (MSB_loc+1)- (numbits-num_reg*8);
129 field_val=
LTC6947_read(cs, (address+num_reg))+(field_val<<8);
132 while ((bit_shift<0) && (num_reg<4));
137 for (i=1, maskbits=1; i<numbits; i++)
140 maskbits = maskbits+pow2;
143 field_val=(field_val >>bit_shift) &maskbits;
169 address=address << 1;
183 long current_content, desired_content, reg_val;
184 int LSB_loc,
i, j, num_reg, bit_shift;
187 for (i=0; i<32 ; i++) temp_arr[i]=0;
194 bit_shift=(MSB_loc+1)-(numbits-num_reg*8);
195 current_content=
LTC6947_read(cs, (address+num_reg)) + (current_content<<8);
199 while ((bit_shift<0) && (num_reg<4));
200 for (i=0; i<(8*num_reg); i++)
202 temp_arr[
i]=(current_content>>
i) & 1;
206 LSB_loc = 8*(num_reg-1)+MSB_loc-numbits+1;
207 for (i=LSB_loc, j=0; i<=(MSB_loc+(num_reg-1)*8); i++, j++)
209 temp_arr[
i] = (field_data>>j) &1;
214 for (i=0; i<(8*num_reg); i++)
216 desired_content = desired_content | (temp_arr[
i]<<
i);
220 for (i=0; i<num_reg; i++)
222 reg_val = (desired_content >> 8*(num_reg-1-
i)) & 0xff;
275 void set_LTC6947_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)
478 void set_LTC6947_global_vcolim(
unsigned long fvco_max_MHz,
unsigned long fvco_max_Hz,
unsigned long fvco_min_MHz,
unsigned long fvco_min_Hz)
536 unsigned long odiv,
i;
537 unsigned long max_fout64[2];
538 unsigned long min_fout64[2];
539 unsigned long temp_fout[2];
540 unsigned long temp_i[2];
541 boolean valid_input=
false;
552 temp_fout[0] = frf[0];
553 temp_fout[1] = frf[1];
554 mul64(temp_fout,temp_i);
555 if (
lt64(temp_fout,max_fout64) ||
eq64(temp_fout, max_fout64))
557 if (
lt64(min_fout64,temp_fout) ||
eq64(temp_fout, min_fout64))
565 if (valid_input ==
false) odiv= 999L;
625 unsigned long frf_MHz, frf_Hz, fref_MHz, fref_Hz, odiv, rdiv, ndiv, fracN_num, frac_num_remainder;
626 unsigned long N64[2], NUM64[2], R64[2], O64[2], temp_long[2];
628 unsigned long frf[2], frf_act[2];
629 unsigned long fref[2];
630 unsigned long temp_math[2];
631 unsigned long frf_rdiv_odiv[2];
632 unsigned long frf_rdiv_odiv_int[2];
633 unsigned long roundup[2];
639 HZto64(frf, frf_MHz, frf_Hz);
643 HZto64(fref,fref_MHz,fref_Hz);
653 frf_rdiv_odiv[1]=odiv*rdiv;
654 mul64(frf_rdiv_odiv, frf);
655 frf_rdiv_odiv_int[0]=frf_rdiv_odiv[0];
656 frf_rdiv_odiv_int[1]=frf_rdiv_odiv[1];
659 temp_math[0]=fref[0];
660 temp_math[1]=fref[1];
661 div64(frf_rdiv_odiv_int, temp_math);
662 ndiv=frf_rdiv_odiv_int[1];
668 div64(frf_rdiv_odiv, fref);
672 sub64(frf_rdiv_odiv,frf_rdiv_odiv_int);
679 frac_num_remainder=(frf_rdiv_odiv[1] & 31L);
680 if (frac_num_remainder >= 16L)
684 add64(frf_rdiv_odiv,roundup);
689 fracN_num=frf_rdiv_odiv[1];
693 Serial.print(
"OD = ");
694 Serial.println(odiv);
696 Serial.print(
"RD = ");
697 Serial.println(rdiv);
700 Serial.print(F(
"ND = "));
701 Serial.println(ndiv);
707 if ( (ndiv<35) || (ndiv>1019) ) Serial.print(F(
"N DIV set to invalid setting - REFER TO DATASHEET\n"));
712 Serial.print(F(
"When NUM=0, changes to Integer Mode (NUM can not be 0)\n"));
713 if ( (ndiv<32) || (ndiv>1023) ) Serial.print(F(
"N DIV set to invalid setting - REFER TO DATASHEET\n"));
715 Serial.print(F(
"NUM = "));
716 Serial.println(fracN_num);
739 Serial.print(F(
"Actual Output Frequency (closest available) is "));
740 Serial.print(frf_act[1]);
741 Serial.println(
"Hz");
745 temp_math[0]=frf_act[0];
746 temp_math[1]=frf_act[1];
749 div64(temp_math,temp_long);
750 Serial.print(F(
"Actual Output Frequency (closest available) is "));
751 Serial.print(temp_math[1]);
752 Serial.print(
"MHz + ");
755 mul64(temp_math,temp_long);
756 sub64(frf_act,temp_math);
757 Serial.print(frf_act[1]);
758 Serial.println(
"Hz");
767 void prt(
unsigned long an[])
769 Serial.print(an[0],HEX);
771 Serial.println(an[1],HEX);
781 void init64(
unsigned long an[],
unsigned long bigPart,
unsigned long littlePart )
798 void HZto64(
unsigned long an[],
unsigned long MHzPart,
unsigned long HzPart )
801 if ((MHzPart>4295) || ((MHzPart==4294) && (HzPart>=967296)))
804 an[1] =(MHzPart-4294L)*
OneMHz + HzPart-967296L;
809 an[1] = MHzPart*
OneMHz+HzPart;
820 if (an[1] & 0x80000000)
843 void shl64by(
unsigned long an[], uint8_t shiftnum)
847 for (i=0; i<shiftnum; i++)
850 if (an[1] & 0x80000000)
861 void shr64by(
unsigned long an[], uint8_t shiftnum)
865 for (i=0; i<shiftnum; i++)
879 void add64(
unsigned long an[],
unsigned long ann[])
882 if (an[1] + ann[1] < ann[1])
892 void sub64(
unsigned long an[],
unsigned long ann[])
907 boolean eq64(
unsigned long an[],
unsigned long ann[])
909 return (an[0]==ann[0]) && (an[1]==ann[1]);
917 boolean lt64(
unsigned long an[],
unsigned long ann[])
919 if (an[0]>ann[0])
return false;
920 return (an[0]<ann[0]) || (an[1]<ann[1]);
928 void div64(
unsigned long num[],
unsigned long den[])
930 unsigned long quot[2];
931 unsigned long qbit[2];
932 unsigned long tmp[2];
944 init64(num,0xffffffff,0xffffffff);
949 while (
lt64(den,tmp))
967 init64(num,quot[0],quot[1]);
975 void mul64(
unsigned long an[],
unsigned long ann[])
977 unsigned long p[2] = {0,0};
978 unsigned long y[2] = {ann[0], ann[1]};
#define LTC6947_CPCHI
for spi_map array, defines location for field specific information used to create the spi map ...
void div64(unsigned long num[], unsigned long den[])
64 bit Divide, num=num/div
uint8_t LTC6947_write_field(uint8_t cs, long field_data, uint8_t address, uint8_t MSB_loc, uint8_t numbits)
LTC6947 Write Single Field For SPI FIELDS in 1 or multiple address locations reads specific address/f...
#define LTC6947_NUM_REGFIELD
Defines number of LTC6947 SPI fields, used in spi_map array.
#define LTC6947_ND
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long get_LTC6947_global_VCO_MIN_Hz()
returns global LTC6947_VCO_Min_Freq_Hz
#define LTC6947_INTN
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6947_PDALL
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6947_PDPLL
for spi_map array, defines location for field specific information used to create the spi map ...
uint8_t get_LTC6947_SPI_FIELD_NUMBITS(uint8_t f)
returns the number of bits for a given field name in the SPI map
#define LTC6947_CPUP
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6947_POR
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[])
#define LTC6947_x
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6947_RSTFN
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long LTC6947_VCO_Min_Freq_Hz
Min Vco frequency for default on board VCO - Hz portion (yyy,yyy); Fvco min= x,xxx, yyy,yyy.
#define LTC6947_BST
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long LTC6947_Fref_MHz
Default Fref frequency - MHz portion (xxx); Fref = xxx, yyy,yyy.
void set_LTC6947_global_fref(unsigned long fref_MHz, unsigned long fref_Hz)
sets globals LTC6947_Fref_MHz and LTC6947_Fref_Hz
void prt(unsigned long an[])
Prints HEX representation of 64 bit an.
void set_LTC6947_SPI_FIELD(uint8_t cs, uint8_t f, long field_data)
Sets the LTC6947 SPI field value calls function LTC6947_read_field, which reads specific address/fiel...
Header File for Linduino Libraries and Demo Code.
uint8_t get_LTC6947_SPI_FIELD_RW(uint8_t f)
returns if the given field name is (0)read/write or (1)read_only field
#define LTC6947_CPRST
for spi_map array, defines location for field specific information used to create the spi map ...
boolean eq64(unsigned long an[], unsigned long ann[])
64 bit, if an == ann, then true
void LTC6947_write(uint8_t cs, uint8_t address, uint8_t Data)
LTC6947 Write Single Address writes 8 bit Data field to LTC6947.
unsigned long LTC6947_VCO_Max_Freq_MHz
Max Vco frequency for default on board VCO - MHz portion (xxxx); Fvco max = xxx, yyy,yyy.
#define LTC6947_NUM_REGADDR
Defines number of LTC6947 SPI registers, used in spi_map array.
uint8_t LTC6947_read(uint8_t cs, int8_t address)
LTC6947 Read Single Address reads 8 bit Data field to LTC6947.
#define OneMHz
1MHz in long format, used in 64 bit math
void shl64(unsigned long an[])
Single Bit shift left of equivalent 64 bit number (an[] = an[]<<1)
unsigned long get_LTC6947_global_VCO_MIN_MHz()
returns global LTC6947_VCO_Min_Freq_MHz
void shr64(unsigned long an[])
Single Bit shift right of equivalent 64 bit number (an[] = an[]<<1)
#define LTC6947_THI
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6947_RD
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6947_CPLE
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6947_REV
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long LTC6947_VCO_Max_Freq_Hz
Max Vco frequency for default on board VCO - Hz portion (yyy,yyy); Fvco max = x,xxx, yyy,yyy.
#define LTC6947_OD
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6947_FILT
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6947_CP
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 get_LTC6947_global_VCO_MAX_MHz()
returns global LTC6947_VCO_Max_Freq_MHz
uint8_t LTC6947_spi_map[(LTC6947_NUM_REGFIELD+1)][4]
LTC6947 spi map, stores MSB address location, MSB bit location, field length in bits, and R or RW capability.
#define LTC6947_CPMID
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6947_OMUTE
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6947_PART
for spi_map array, defines location for field specific information used to create the spi map ...
void set_LTC6947_global_frf(unsigned long frf_MHz, unsigned long frf_Hz)
sets globals LTC6947_Frf_MHz and LTC6947_Frf_Hz
#define LTC6947_LDOEN
for spi_map array, defines location for field specific information used to create the spi map ...
long LTC6947_read_field(uint8_t cs, uint8_t address, uint8_t MSB_loc, uint8_t numbits)
LTC6947 Read Single Field For SPI FIELDS located in 1 or multiple address location reads specific add...
unsigned long LTC6947_Frf_MHz
Default Frf frequency - MHz portion (xxxx); Frf = x,xxx, yyy,yyy.
#define LTC6947_CPDN
for spi_map array, defines location for field specific information used to create the spi map ...
void LTC6947_set_frf()
FUNCTION: LTC6947_set_frf Calculates the integer (N), fractional (NUM) and output divider (OD) SPI va...
uint16_t LT_uint16
16-bit unsigned integer to be converted to two bytes
#define R_ONLY
used for 2nd dim of 2d spi_map array
unsigned long get_LTC6947_global_frf_MHz()
returns global LTC6947_Frf_MHz
void spi_transfer_word(uint8_t cs_pin, uint16_t tx, uint16_t *rx)
Reads and sends a word.
unsigned long LTC6947_VCO_Min_Freq_MHz
Min Vco frequency for default on board VCO - MHz portion (xxxx); Fvco min = x,xxx, yyy,yyy.
#define LTC6947_RFO
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long get_LTC6947_global_fref_Hz()
returns global LTC6947_Fref_Hz
#define LTC6947_CPINV
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long LTC6947_Fref_Hz
Default Fref frequency - Hz portion (yyy,yyy); Fref = x,xxx, yyy,yyy.
unsigned long zero64[]
for 64bit math functions
#define LTC6947_PDFN
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long get_LTC6947_global_fref_MHz()
returns global LTC6947_Fref_MHz
#define LTC6947_LKWIN
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)
LT_SPI: Routines to communicate with ATmega328P's hardware SPI port.
unsigned long get_LTC6947_global_VCO_MAX_Hz()
returns global LTC6947_VCO_Max_Freq_Hz
#define LTC6947_PDOUT
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6947_TLO
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6947_CPWIDE
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6947_CPCLO
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6947_LDOV
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
#define LTC6947_UNLOK
for spi_map array, defines location for field specific information used to create the spi map ...
LTC6947: Ultralow Noise and Spurious 0.35GHz to 6GHz FracN Synthesizer.
long get_LTC6947_SPI_FIELD(uint8_t cs, uint8_t f)
Gets the LTC6947 SPI field value calls function LTC6947_read_field, which reads specific address loca...
uint8_t LTC6947_reg[LTC6947_NUM_REGADDR]
number of LTC6947 spi addresses
void add64(unsigned long an[], unsigned long ann[])
64 bit Add ann to an (an[] = an[] + ann[])
#define LTC6947_LKCT
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6947_NUM
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6947_LOCK
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6947_SEED
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6947_DITHEN
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 LTC6947_init()
Initializes the SPI MAP arrays The values set in initialization are used for all the LTC6947 SPI/WRIT...
unsigned long LTC6947_calc_odiv(unsigned long frf[2])
calculates the output divider setting based on the frf and on board VCO frequencies of LTC6947 ...
void shl64by(unsigned long an[], uint8_t shiftnum)
Multi Bit shift left of equivalent 64 bit number (an[] = an[]<<shiftnum)
#define LTC6947_AUTORST
for spi_map array, defines location for field specific information used to create the spi map ...
uint8_t LT_byte[2]
2 bytes (unsigned 8-bit integers) to be converted to a 16-bit signed or unsigned integer ...
#define LTC6947_CS
Define the SPI CS pin.
uint8_t get_LTC6947_REGSIZE()
returns # of addresses in parts register map (array size)
void mul64(unsigned long an[], unsigned long ann[])
64 bit multiply, an=an*ann
unsigned long get_LTC6947_global_frf_Hz()
returns global LTC6947_Frf_Hz
boolean lt64(unsigned long an[], unsigned long ann[])
64 bit, if an < ann, then true
void init64(unsigned long an[], unsigned long bigPart, unsigned long littlePart)
Creates a equivalent 64 bit number from 2 32 bit numbers.
void set_LTC6947_global_vcolim(unsigned long fvco_max_MHz, unsigned long fvco_max_Hz, unsigned long fvco_min_MHz, unsigned long fvco_min_Hz)
sets globals LTC6947_VCO_Max_Freq_MHz, LTC6947_VCO_Max_Freq_Hz, LTC6947_VCO_Min_Freq_MHz and LTC6947_...
void set_LTC6947_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)
Writes values to ALL LTC6947 RW addresses.
unsigned long LTC6947_Frf_Hz
Default Frf frequency - Hz portion (yyy,yyy); Frf = x,xxx, yyy,yyy.
#define DxMSB
used for 2nd dim of 2d spi_map array