109 int8_t address_shift;
112 address_shift =(address << 1) | 0x01;
129 int bit_shift,
i, num_reg;
130 long field_val, maskbits, pow2;
137 bit_shift = (MSB_loc+1)- (numbits-num_reg*8);
138 field_val=
LTC6945_read(cs, (address+num_reg))+(field_val<<8);
141 while ((bit_shift<0) && (num_reg<4));
146 for (i=1, maskbits=1; i<numbits; i++)
149 maskbits = maskbits+pow2;
152 field_val=(field_val >>bit_shift) &maskbits;
178 address=address << 1;
192 long current_content, desired_content, reg_val;
193 int LSB_loc,
i, j, num_reg, bit_shift;
196 for (i=0; i<32 ; i++) temp_arr[i]=0;
203 bit_shift=(MSB_loc+1)-(numbits-num_reg*8);
204 current_content=
LTC6945_read(cs, (address+num_reg)) + (current_content<<8);
208 while ((bit_shift<0) && (num_reg<4));
209 for (i=0; i<(8*num_reg); i++)
211 temp_arr[
i]=(current_content>>
i) & 1;
215 LSB_loc = 8*(num_reg-1)+MSB_loc-numbits+1;
216 for (i=LSB_loc, j=0; i<=(MSB_loc+(num_reg-1)*8); i++, j++)
218 temp_arr[
i] = (field_data>>j) &1;
223 for (i=0; i<(8*num_reg); i++)
225 desired_content = desired_content | (temp_arr[
i]<<
i);
229 for (i=0; i<num_reg; i++)
231 reg_val = (desired_content >> 8*(num_reg-1-
i)) & 0xff;
284 void set_LTC6945_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)
452 void set_LTC6945_global_vcolim(
unsigned long fvco_max_MHz,
unsigned long fvco_max_Hz,
unsigned long fvco_min_MHz,
unsigned long fvco_min_Hz)
510 unsigned long odiv,
i;
511 unsigned long max_fout64[2];
512 unsigned long min_fout64[2];
513 unsigned long temp_fout[2];
514 unsigned long temp_i[2];
515 boolean valid_input=
false;
526 temp_fout[0] = frf[0];
527 temp_fout[1] = frf[1];
528 mul64(temp_fout,temp_i);
529 if (
lt64(temp_fout,max_fout64) ||
eq64(temp_fout, max_fout64))
531 if (
lt64(min_fout64,temp_fout) ||
eq64(temp_fout, min_fout64))
539 if (valid_input ==
false) odiv= 999L;
585 unsigned long frf_MHz, frf_Hz, fref_MHz, fref_Hz, odiv, rdiv, ndiv, N_remainder;
586 unsigned long N64[2], R64[2], O64[2], temp_long[2];
588 unsigned long frf[2], frf_act[2];
589 unsigned long fref[2];
590 unsigned long temp_math[2];
591 unsigned long frf_rdiv_odiv[2];
592 unsigned long frf_rdiv_odiv_int[2];
593 unsigned long roundup[2];
599 HZto64(frf, frf_MHz, frf_Hz);
603 HZto64(fref,fref_MHz,fref_Hz);
613 frf_rdiv_odiv[1]=odiv*rdiv;
614 mul64(frf_rdiv_odiv, frf);
615 frf_rdiv_odiv_int[0]=frf_rdiv_odiv[0];
616 frf_rdiv_odiv_int[1]=frf_rdiv_odiv[1];
619 temp_math[0]=fref[0];
620 temp_math[1]=fref[1];
621 div64(frf_rdiv_odiv_int, temp_math);
622 ndiv=frf_rdiv_odiv_int[1];
625 temp_math[0]=fref[0];
626 temp_math[1]=fref[1];
628 div64(frf_rdiv_odiv,temp_math);
630 sub64(frf_rdiv_odiv,frf_rdiv_odiv_int);
636 N_remainder = (frf_rdiv_odiv[1] & 8191L);
637 if (N_remainder >= 4096)
644 Serial.print(
"OD = ");
645 Serial.println(odiv);
647 Serial.print(
"RD = ");
648 Serial.println(rdiv);
651 Serial.print(F(
"ND = "));
652 Serial.println(ndiv);
670 Serial.print(F(
"Actual Output Frequency (closest available) is "));
671 Serial.print(frf_act[1]);
672 Serial.println(
"Hz");
676 temp_math[0]=frf_act[0];
677 temp_math[1]=frf_act[1];
680 div64(temp_math,temp_long);
681 Serial.print(F(
"Actual Output Frequency (closest available) is "));
682 Serial.print(temp_math[1]);
683 Serial.print(
"MHz + ");
686 mul64(temp_math,temp_long);
687 sub64(frf_act,temp_math);
688 Serial.print(frf_act[1]);
689 Serial.println(
"Hz");
698 void prt(
unsigned long an[])
700 Serial.print(an[0],HEX);
702 Serial.println(an[1],HEX);
712 void init64(
unsigned long an[],
unsigned long bigPart,
unsigned long littlePart )
729 void HZto64(
unsigned long an[],
unsigned long MHzPart,
unsigned long HzPart )
732 if ((MHzPart>4295) || ((MHzPart==4294) && (HzPart>=967296)))
735 an[1] =(MHzPart-4294L)*
OneMHz + HzPart-967296L;
740 an[1] = MHzPart*
OneMHz+HzPart;
751 if (an[1] & 0x80000000)
774 void shl64by(
unsigned long an[], uint8_t shiftnum)
778 for (i=0; i<shiftnum; i++)
781 if (an[1] & 0x80000000)
792 void shr64by(
unsigned long an[], uint8_t shiftnum)
796 for (i=0; i<shiftnum; i++)
810 void add64(
unsigned long an[],
unsigned long ann[])
813 if (an[1] + ann[1] < ann[1])
823 void sub64(
unsigned long an[],
unsigned long ann[])
838 boolean eq64(
unsigned long an[],
unsigned long ann[])
840 return (an[0]==ann[0]) && (an[1]==ann[1]);
848 boolean lt64(
unsigned long an[],
unsigned long ann[])
850 if (an[0]>ann[0])
return false;
851 return (an[0]<ann[0]) || (an[1]<ann[1]);
859 void div64(
unsigned long num[],
unsigned long den[])
861 unsigned long quot[2];
862 unsigned long qbit[2];
863 unsigned long tmp[2];
875 init64(num,0xffffffff,0xffffffff);
880 while (
lt64(den,tmp))
898 init64(num,quot[0],quot[1]);
906 void mul64(
unsigned long an[],
unsigned long ann[])
908 unsigned long p[2] = {0,0};
909 unsigned long y[2] = {ann[0], ann[1]};
boolean lt64(unsigned long an[], unsigned long ann[])
64 bit, if an < ann, then true
#define LTC6945_CP
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long get_LTC6945_global_VCO_MIN_Hz()
returns global LTC6945_VCO_Min_Freq_Hz
unsigned long LTC6945_Fref_Hz
Default Fref frequency - Hz portion (yyy,yyy); Fref = x,xxx, yyy,yyy.
void set_LTC6945_global_frf(unsigned long frf_MHz, unsigned long frf_Hz)
sets globals LTC6945_Frf_MHz and LTC6945_Frf_Hz
void init64(unsigned long an[], unsigned long bigPart, unsigned long littlePart)
Creates a equivalent 64 bit number from 2 32 bit numbers.
#define LTC6945_LOCK
for spi_map array, defines location for field specific information used to create the spi map ...
long LTC6945_read_field(uint8_t cs, uint8_t address, uint8_t MSB_loc, uint8_t numbits)
LTC6945 Read Single Field For SPI FIELDS located in 1 or multiple address location reads specific add...
#define LTC6945_NUM_REGADDR
Defines number of LTC6945 SPI registers, used in spi_map array.
long get_LTC6945_SPI_FIELD(uint8_t cs, uint8_t f)
Gets the LTC6945 SPI field value calls function LTC6945_read_field, which reads specific address loca...
void sub64(unsigned long an[], unsigned long ann[])
64 bit Subtract ann from an (an[] = an[] - ann[])
void div64(unsigned long num[], unsigned long den[])
64 bit Divide, num=num/div
void set_LTC6945_SPI_FIELD(uint8_t cs, uint8_t f, long field_data)
Sets the LTC6945 SPI field value calls function LTC6945_read_field, which reads specific address/fiel...
#define LTC6945_FILT
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6945_CPRST
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.
uint8_t LTC6945_read(uint8_t cs, int8_t address)
LTC6945 Read Single Address reads 8 bit Data field to LTC6945.
#define LTC6945_NUM_REGFIELD
Defines number of LTC6945 SPI fields, used in spi_map array.
Header File for Linduino Libraries and Demo Code.
uint8_t get_LTC6945_SPI_FIELD_RW(uint8_t f)
returns if the given field name is (0)read/write or (1)read_only field
#define LTC6945_LKEN
for spi_map array, defines location for field specific information used to create the spi map ...
void shl64(unsigned long an[])
Single Bit shift left of equivalent 64 bit number (an[] = an[]<<1)
#define LTC6945_BST
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long LTC6945_calc_odiv(unsigned long frf[2])
calculates the output divider setting based on the frf and on board VCO frequencies of LTC6945 ...
void shr64(unsigned long an[])
Single Bit shift right of equivalent 64 bit number (an[] = an[]<<1)
#define LTC6945_TLO
for spi_map array, defines location for field specific information used to create the spi map ...
uint8_t get_LTC6945_SPI_FIELD_NUMBITS(uint8_t f)
returns the number of bits for a given field name in the SPI map
unsigned long get_LTC6945_global_fref_MHz()
returns global LTC6945_Fref_MHz
#define OneMHz
1MHz in long format, used in 64 bit math
boolean eq64(unsigned long an[], unsigned long ann[])
64 bit, if an == ann, then true
uint8_t LTC6945_reg[LTC6945_NUM_REGADDR]
number of LTC6945 spi addresses
unsigned long LTC6945_VCO_Min_Freq_MHz
Min Vco frequency for default on board VCO - MHz portion (xxxx); Fvco min = x,xxx, yyy,yyy.
void LTC6945_init()
Initializes the SPI MAP arrays The values set in initialization are used for all the LTC6945 SPI/WRIT...
#define LTC6945_PDALL
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6945_ND
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6945_OD
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.
uint8_t LTC6945_spi_map[(LTC6945_NUM_REGFIELD+1)][4]
LTC6945 spi map, stores MSB address location, MSB bit location, field length in bits, and R or RW capability.
void set_LTC6945_global_fref(unsigned long fref_MHz, unsigned long fref_Hz)
sets globals LTC6945_Fref_MHz and LTC6945_Fref_Hz
unsigned long get_LTC6945_global_fref_Hz()
returns global LTC6945_Fref_Hz
#define LTC6945_POR
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long get_LTC6945_global_frf_MHz()
returns global LTC6945_Frf_MHz
unsigned long LTC6945_Frf_MHz
Default Frf frequency - MHz portion (xxxx); Frf = x,xxx, yyy,yyy.
unsigned long LTC6945_VCO_Min_Freq_Hz
Min Vco frequency for default on board VCO - Hz portion (yyy,yyy); Fvco min= x,xxx, yyy,yyy.
#define LTC6945_PDOUT
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6945_THI
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6945_PDPLL
for spi_map array, defines location for field specific information used to create the spi map ...
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 LTC6945_VCO_Max_Freq_Hz
Max Vco frequency for default on board VCO - Hz portion (yyy,yyy); Fvco max = x,xxx, yyy,yyy.
void spi_transfer_word(uint8_t cs_pin, uint16_t tx, uint16_t *rx)
Reads and sends a word.
void set_LTC6945_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)
Writes values to ALL LTC6945 RW addresses.
unsigned long get_LTC6945_global_frf_Hz()
returns global LTC6945_Frf_Hz
#define LTC6945_LKWIN
for spi_map array, defines location for field specific information used to create the spi map ...
void LTC6945_set_frf()
FUNCTION: LTC6945_set_frf Calculates the integer (N), fractional (NUM) and output divider (OD) SPI va...
unsigned long get_LTC6945_global_VCO_MAX_Hz()
returns global LTC6945_VCO_Max_Freq_Hz
#define LTC6945_CPINV
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long get_LTC6945_global_VCO_MAX_MHz()
returns global LTC6945_VCO_Max_Freq_MHz
#define LTC6945_CS
Define the SPI CS pin.
#define LTC6945_RFO
for spi_map array, defines location for field specific information used to create the spi map ...
LT_SPI: Routines to communicate with ATmega328P's hardware SPI port.
unsigned long zero64[]
for 64bit math functions
#define LTC6945_LKCT
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long LTC6945_Fref_MHz
Default Fref frequency - MHz portion (xxx); Fref = xxx, yyy,yyy.
#define LTC6945_CPMID
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 LTC6945_CPDN
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[])
unsigned long LTC6945_VCO_Max_Freq_MHz
Max Vco frequency for default on board VCO - MHz portion (xxxx); Fvco max = xxx, yyy,yyy.
#define LTC6945_CPCHI
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 LTC6945_PART
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6945_CPWIDE
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6945_CPCLO
for spi_map array, defines location for field specific information used to create the spi map ...
uint8_t LTC6945_write_field(uint8_t cs, long field_data, uint8_t address, uint8_t MSB_loc, uint8_t numbits)
LTC6945 Write Single Field For SPI FIELDS in 1 or multiple address locations reads specific address/f...
void LTC6945_write(uint8_t cs, uint8_t address, uint8_t Data)
LTC6945 Write Single Address writes 8 bit Data field to LTC6945.
LTC6945: Ultralow Noise and Spurious 0.35GHz to 6GHz Integer-N Synthesizer.
unsigned long get_LTC6945_global_VCO_MIN_MHz()
returns global LTC6945_VCO_Min_Freq_MHz
#define LTC6945_RD
for spi_map array, defines location for field specific information used to create the spi map ...
uint8_t get_LTC6945_REGSIZE()
returns # of addresses in parts register map (array size)
#define LTC6945_x
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 shl64by(unsigned long an[], uint8_t shiftnum)
Multi Bit shift left of equivalent 64 bit number (an[] = an[]<<shiftnum)
#define LTC6945_PDREFO
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long LTC6945_Frf_Hz
Default Frf frequency - Hz portion (yyy,yyy); Frf = x,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 LTC6945_OMUTE
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6945_UNLOCK
for spi_map array, defines location for field specific information used to create the spi map ...
void set_LTC6945_global_vcolim(unsigned long fvco_max_MHz, unsigned long fvco_max_Hz, unsigned long fvco_min_MHz, unsigned long fvco_min_Hz)
sets globals LTC6945_VCO_Max_Freq_MHz, LTC6945_VCO_Max_Freq_Hz, LTC6945_VCO_Min_Freq_MHz and LTC6945_...
#define LTC6945_REV
for spi_map array, defines location for field specific information used to create the spi map ...
void mul64(unsigned long an[], unsigned long ann[])
64 bit multiply, an=an*ann
#define LTC6945_CPUP
for spi_map array, defines location for field specific information used to create the spi map ...
#define DxMSB
used for 2nd dim of 2d spi_map array