100 address_shift =(address << 1) | 0x01;
117 int bit_shift,
i, num_reg;
118 long field_val, maskbits, pow2;
125 bit_shift = (MSB_loc+1)- (numbits-num_reg*8);
126 field_val=
LTC6948_read(cs, (address+num_reg))+(field_val<<8);
129 while ((bit_shift<0) && (num_reg<4));
134 for (i=1, maskbits=1; i<numbits; i++)
137 maskbits = maskbits+pow2;
140 field_val=(field_val >>bit_shift) &maskbits;
166 address=address << 1;
180 long current_content, desired_content, reg_val;
181 int LSB_loc,
i, j, num_reg, bit_shift;
184 for (i=0; i<32 ; i++) temp_arr[i]=0;
191 bit_shift=(MSB_loc+1)-(numbits-num_reg*8);
192 current_content=
LTC6948_read(cs, (address+num_reg)) + (current_content<<8);
196 while ((bit_shift<0) && (num_reg<4));
197 for (i=0; i<(8*num_reg); i++)
199 temp_arr[
i]=(current_content>>
i) & 1;
203 LSB_loc = 8*(num_reg-1)+MSB_loc-numbits+1;
204 for (i=LSB_loc, j=0; i<=(MSB_loc+(num_reg-1)*8); i++, j++)
206 temp_arr[
i] = (field_data>>j) &1;
211 for (i=0; i<(8*num_reg); i++)
213 desired_content = desired_content | (temp_arr[
i]<<
i);
217 for (i=0; i<num_reg; i++)
219 reg_val = (desired_content >> 8*(num_reg-1-
i)) & 0xff;
272 void set_LTC6948_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)
547 unsigned long odiv, max_fout, min_fout, temp_val,
i, temp_out;
548 unsigned long max_fout64[2];
549 unsigned long min_fout64[2];
550 unsigned long temp_fout[2];
551 unsigned long temp_i[2];
552 boolean valid_input=
false;
555 if (part_version[8]==
'1')
560 else if (part_version[8]==
'2')
565 else if (part_version[8]==
'3')
570 else if (part_version[8]==
'4')
577 Serial.print(
"No default Frequencies for this board: ");
578 Serial.println(part_version);
580 HZto64(max_fout64,max_fout,0L);
581 HZto64(min_fout64,min_fout,0L);
588 temp_fout[0] = frf[0];
589 temp_fout[1] = frf[1];
590 mul64(temp_fout,temp_i);
591 if (
lt64(temp_fout,max_fout64) ||
eq64(temp_fout, max_fout64))
593 if (
lt64(min_fout64,temp_fout) ||
eq64(temp_fout, min_fout64))
601 if (valid_input ==
false) odiv= 999L;
661 unsigned long frf_MHz, frf_Hz, fref_MHz, fref_Hz, odiv, rdiv, ndiv, fracN_num, frac_num_remainder;
662 unsigned long N64[2], NUM64[2], R64[2], O64[2], temp_long[2];
664 unsigned long frf[2], frf_act[2];
665 unsigned long fref[2];
666 unsigned long temp_math[2];
667 unsigned long frf_rdiv_odiv[2];
668 unsigned long frf_rdiv_odiv_int[2];
669 unsigned long roundup[2];
675 HZto64(frf, frf_MHz, frf_Hz);
679 HZto64(fref,fref_MHz,fref_Hz);
689 frf_rdiv_odiv[1]=odiv*rdiv;
690 mul64(frf_rdiv_odiv, frf);
691 frf_rdiv_odiv_int[0]=frf_rdiv_odiv[0];
692 frf_rdiv_odiv_int[1]=frf_rdiv_odiv[1];
695 temp_math[0]=fref[0];
696 temp_math[1]=fref[1];
697 div64(frf_rdiv_odiv_int, temp_math);
698 ndiv=frf_rdiv_odiv_int[1];
704 div64(frf_rdiv_odiv, fref);
708 sub64(frf_rdiv_odiv,frf_rdiv_odiv_int);
715 frac_num_remainder=(frf_rdiv_odiv[1] & 31L);
716 if (frac_num_remainder >= 16L)
720 add64(frf_rdiv_odiv,roundup);
725 fracN_num=frf_rdiv_odiv[1];
729 Serial.print(
"OD = ");
730 Serial.println(odiv);
732 Serial.print(
"RD = ");
733 Serial.println(rdiv);
736 Serial.print(F(
"ND = "));
737 Serial.println(ndiv);
743 if ( (ndiv<35) || (ndiv>1019) ) Serial.print(F(
"N DIV set to invalid setting - REFER TO DATASHEET\n"));
748 Serial.print(F(
"When NUM=0, changes to Integer Mode (NUM can not be 0)\n"));
749 if ( (ndiv<32) || (ndiv>1023) ) Serial.print(F(
"N DIV set to invalid setting - REFER TO DATASHEET\n"));
751 Serial.print(F(
"NUM = "));
752 Serial.println(fracN_num);
777 Serial.print(F(
"Actual Output Frequency (closest available) is "));
778 Serial.print(frf_act[1]);
779 Serial.println(
"Hz");
783 temp_math[0]=frf_act[0];
784 temp_math[1]=frf_act[1];
787 div64(temp_math,temp_long);
788 Serial.print(F(
"Actual Output Frequency (closest available) is "));
789 Serial.print(temp_math[1]);
790 Serial.print(
"MHz + ");
793 mul64(temp_math,temp_long);
794 sub64(frf_act,temp_math);
795 Serial.print(frf_act[1]);
796 Serial.println(
"Hz");
805 void prt(
unsigned long an[])
807 Serial.print(an[0],HEX);
809 Serial.println(an[1],HEX);
819 void init64(
unsigned long an[],
unsigned long bigPart,
unsigned long littlePart )
836 void HZto64(
unsigned long an[],
unsigned long MHzPart,
unsigned long HzPart )
839 if ((MHzPart>4295) || ((MHzPart==4294) && (HzPart>=967296)))
842 an[1] =(MHzPart-4294L)*
OneMHz + HzPart-967296L;
847 an[1] = MHzPart*
OneMHz+HzPart;
858 if (an[1] & 0x80000000)
881 void shl64by(
unsigned long an[], uint8_t shiftnum)
885 for (i=0; i<shiftnum; i++)
888 if (an[1] & 0x80000000)
899 void shr64by(
unsigned long an[], uint8_t shiftnum)
903 for (i=0; i<shiftnum; i++)
917 void add64(
unsigned long an[],
unsigned long ann[])
920 if (an[1] + ann[1] < ann[1])
930 void sub64(
unsigned long an[],
unsigned long ann[])
945 boolean eq64(
unsigned long an[],
unsigned long ann[])
947 return (an[0]==ann[0]) && (an[1]==ann[1]);
955 boolean lt64(
unsigned long an[],
unsigned long ann[])
957 if (an[0]>ann[0])
return false;
958 return (an[0]<ann[0]) || (an[1]<ann[1]);
966 void div64(
unsigned long num[],
unsigned long den[])
968 unsigned long quot[2];
969 unsigned long qbit[2];
970 unsigned long tmp[2];
982 init64(num,0xffffffff,0xffffffff);
987 while (
lt64(den,tmp))
1005 init64(num,quot[0],quot[1]);
1013 void mul64(
unsigned long an[],
unsigned long ann[])
1015 unsigned long p[2] = {0,0};
1016 unsigned long y[2] = {ann[0], ann[1]};
void init64(unsigned long an[], unsigned long bigPart, unsigned long littlePart)
Creates a equivalent 64 bit number from 2 32 bit numbers.
void mul64(unsigned long an[], unsigned long ann[])
64 bit multiply, an=an*ann
#define LTC6948_2_MINFREQ
LTC6948-2 lower freq limit.
#define LTC6948_3_MINFREQ
LTC6948-3 lower freq limit.
uint8_t LTC6948_read(uint8_t cs, int8_t address)
LTC6948 Read Single Address reads 8 bit Data field to LTC6948.
void sub64(unsigned long an[], unsigned long ann[])
64 bit Subtract ann from an (an[] = an[] - ann[])
unsigned long LTC6948_Fref_Hz
Default Fref frequency - Hz portion (yyy,yyy); Fref = x,xxx, yyy,yyy.
#define LTC6948_UNLOK
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long LTC6948_Frf_Hz
Default Frf frequency - Hz portion (yyy,yyy); Frf = x,xxx, yyy,yyy.
#define LTC6948_PDOUT
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_OMUTE
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_1_MINFREQ
LTC6948-1 lower freq limit.
#define LTC6948_ALCEN
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
void prt(unsigned long an[])
Prints HEX representation of 64 bit an.
#define LTC6948_CPCLO
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_PART
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_SEED
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_CPRST
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_LKWIN
for spi_map array, defines location for field specific information used to create the spi map ...
long LTC6948_read_field(uint8_t cs, uint8_t address, uint8_t MSB_loc, uint8_t numbits)
LTC6948 Read Single Field For SPI FIELDS located in 1 or multiple address locations reads specific ad...
#define LTC6948_LKCT
for spi_map array, defines location for field specific information used to create the spi map ...
long get_LTC6948_SPI_FIELD(uint8_t cs, uint8_t f)
Gets the LTC6948 SPI field value calls function LTC6948_read_field, which reads specific address loca...
#define LTC6948_ALCULOK
for spi_map array, defines location for field specific information used to create the spi map ...
Header File for Linduino Libraries and Demo Code.
void shl64(unsigned long an[])
Single Bit shift left of equivalent 64 bit number (an[] = an[]<<1)
#define LTC6948_CPINV
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_CPCHI
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_CPUP
for spi_map array, defines location for field specific information used to create the spi map ...
uint8_t get_LTC6948_REGSIZE()
returns # of addresses in parts register map (array size)
#define LTC6948_RSTFN
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_OD
for spi_map array, defines location for field specific information used to create the spi map ...
void LTC6948_write(uint8_t cs, uint8_t address, uint8_t Data)
LTC6948 Write Single Address writes 8 bit Data field to LTC6948.
#define LTC6948_NUM
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_FILT
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_ALCHI
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_MTCAL
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long get_LTC6948_global_frf_Hz()
returns global LTC6948_Frf_Hz
#define LTC6948_AUTORST
for spi_map array, defines location for field specific information used to create the spi map ...
#define OneMHz
1MHz in long format, used in 64 bit math
void shr64(unsigned long an[])
Single Bit shift right of equivalent 64 bit number (an[] = an[]<<1)
#define LTC6948_4_MAXFREQ
LTC6948-4 upper freq limit.
void set_LTC6948_SPI_FIELD(uint8_t cs, uint8_t f, long field_data)
Sets the LTC6948 SPI field value calls function LTC6948_read_field, which reads specific address/fiel...
#define LTC6948_4_MINFREQ
LTC6948-4 lower freq limit.
boolean eq64(unsigned long an[], unsigned long ann[])
64 bit, if an == ann, then true
#define LTC6948_AUTOCAL
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long get_LTC6948_global_fref_Hz()
returns global LTC6948_Fref_Hz
#define LTC6948_CPMID
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.
#define LTC6948_LDOV
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_ALCLO
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_CS
Define the SPI CS pin.
void LTC6948_init()
Initializes the SPI MAP arrays The values set in initialization are used all the LTC6948 SPI/WRITE an...
#define LTC6948_1_MAXFREQ
LTC6948-1 upper freq limit.
uint8_t get_LTC6948_SPI_FIELD_RW(uint8_t f)
returns if the given field name is (0)read/write or (1)read_only field
void set_LTC6948_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 LTC6948 RW address.
#define LTC6948_PDFN
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_ND
for spi_map array, defines location for field specific information used to create the spi map ...
uint8_t LTC6948_write_field(uint8_t cs, long field_data, uint8_t address, uint8_t MSB_loc, uint8_t numbits)
LTC6948 Write Single Field For SPI FIELDS in 1 or multiple address locations reads specific address/f...
uint16_t LT_uint16
16-bit unsigned integer to be converted to two bytes
#define LTC6948_DITHEN
for spi_map array, defines location for field specific information used to create the spi map ...
#define R_ONLY
used for 2nd dim of 2d spi_map array
#define LTC6948_PDALL
for spi_map array, defines location for field specific information used to create the spi map ...
void spi_transfer_word(uint8_t cs_pin, uint16_t tx, uint16_t *rx)
Reads and sends a word.
#define LTC6948_CPWIDE
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_INTN
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_3_MAXFREQ
LTC6948-3 upper freq limit.
uint8_t LTC6948_spi_map[(LTC6948_NUM_REGFIELD+1)][4]
LTC6948 spi map, stores MSB address location, MSB bit location, field length in bits, and R or RW capability.
#define LTC6948_NUM_REGADDR
Defines number of LTC6948 SPI registers, used in spi_map array.
void set_LTC6948_global_fref(unsigned long fref_MHz, unsigned long fref_Hz)
sets globals LTC6948_Fref_MHz and LTC6948_Fref_Hz
unsigned long zero64[]
for 64bit math functions
void LTC6948_set_frf(char part_version[])
FUNCTION: LTC6948_set_frf Calculates the integer (N), fractional (NUM) and output divider (OD) SPI va...
#define LTC6948_POR
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.
#define LTC6948_x
for spi_map array, defines location for field specific information used to create the spi map ...
void set_LTC6948_global_frf(unsigned long frf_MHz, unsigned long frf_Hz)
sets globals LTC6948_Frf_MHz and LTC6948_Frf_Hz
void add64(unsigned long an[], unsigned long ann[])
64 bit Add ann to an (an[] = an[] + ann[])
#define LTC6948_CP
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_THI
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 ADDRx
used for 2nd dim of 2d spi_map array
unsigned long LTC6948_Fref_MHz
Default Fref frequency - MHz portion (xxx); Fref = xxx, yyy,yyy.
uint8_t LTC6948_reg[LTC6948_NUM_REGADDR]
number of LTC6948 spi addresses
#define LTC6948_NUM_REGFIELD
Defines number of LTC6948 SPI fields, used in spi_map array.
#define LTC6948_CAL
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_ALCCAL
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_LDOEN
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_REV
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 ...
LTC6948: Ultralow Noise and Spurious 0.37GHz to 6.39GHz FracN Synthesizer with Integrated VCO...
#define LTC6948_ALCMON
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_BD
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long get_LTC6948_global_fref_MHz()
returns global LTC6948_Fref_MHz
void shl64by(unsigned long an[], uint8_t shiftnum)
Multi Bit shift left of equivalent 64 bit number (an[] = an[]<<shiftnum)
#define LTC6948_RFO
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_RD
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 LTC6948_CPLE
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_2_MAXFREQ
LTC6948-2 upper freq limit.
#define LTC6948_PDVCO
for spi_map array, defines location for field specific information used to create the spi map ...
uint8_t get_LTC6948_SPI_FIELD_NUMBITS(uint8_t f)
returns the number of bits for a given field name in the SPI map
unsigned long LTC6948_calc_odiv(char part_version[], unsigned long frf[2])
calculates the output divider setting based on the frf and version of LTC6948
unsigned long LTC6948_Frf_MHz
Default Frf frequency - MHz portion (xxxx); Frf = x,xxx, yyy,yyy.
#define LTC6948_CPDN
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_PDPLL
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6948_LOCK
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 LTC6948_BST
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long get_LTC6948_global_frf_MHz()
returns global LTC6948_Frf_MHz
#define DxMSB
used for 2nd dim of 2d spi_map array
#define LTC6948_TLO
for spi_map array, defines location for field specific information used to create the spi map ...