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=
LTC6946_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=
LTC6946_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_LTC6946_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)
512 unsigned long odiv, max_fout, min_fout, temp_val,
i, temp_out;
513 unsigned long max_fout64[2];
514 unsigned long min_fout64[2];
515 unsigned long temp_fout[2];
516 unsigned long temp_i[2];
517 boolean valid_input=
false;
520 if (part_version[8]==
'1')
525 else if (part_version[8]==
'2')
530 else if (part_version[8]==
'3')
535 else if (part_version[8]==
'4')
542 Serial.print(
"No default Frequencies for this board: ");
543 Serial.println(part_version);
545 HZto64(max_fout64,max_fout,0L);
546 HZto64(min_fout64,min_fout,0L);
553 temp_fout[0] = frf[0];
554 temp_fout[1] = frf[1];
555 mul64(temp_fout,temp_i);
556 if (
lt64(temp_fout,max_fout64) ||
eq64(temp_fout, max_fout64))
558 if (
lt64(min_fout64,temp_fout) ||
eq64(temp_fout, min_fout64))
566 if (valid_input ==
false) odiv= 999L;
611 unsigned long frf_MHz, frf_Hz, fref_MHz, fref_Hz, odiv, rdiv, ndiv, N_remainder, temp_val;
612 unsigned long N64[2], R64[2], O64[2], temp_long[2];
614 unsigned long frf[2], frf_act[2];
615 unsigned long fref[2];
616 unsigned long temp_math[2];
617 unsigned long frf_rdiv_odiv[2];
618 unsigned long frf_rdiv_odiv_int[2];
619 unsigned long roundup[2];
632 HZto64(frf, frf_MHz, frf_Hz);
636 HZto64(fref,fref_MHz,fref_Hz);
649 frf_rdiv_odiv[1]=odiv*rdiv;
650 mul64(frf_rdiv_odiv, frf);
651 frf_rdiv_odiv_int[0]=frf_rdiv_odiv[0];
652 frf_rdiv_odiv_int[1]=frf_rdiv_odiv[1];
655 temp_math[0]=fref[0];
656 temp_math[1]=fref[1];
657 div64(frf_rdiv_odiv_int, temp_math);
658 ndiv=frf_rdiv_odiv_int[1];
661 temp_math[0]=fref[0];
662 temp_math[1]=fref[1];
664 div64(frf_rdiv_odiv,temp_math);
666 sub64(frf_rdiv_odiv,frf_rdiv_odiv_int);
672 N_remainder = (frf_rdiv_odiv[1] & 8191L);
673 if (N_remainder >= 4096)
681 Serial.print(
"OD = ");
682 Serial.println(odiv);
684 Serial.print(
"RD = ");
685 Serial.println(rdiv);
687 Serial.print(F(
"ND = "));
688 Serial.println(ndiv);
702 tx2=(0xff00 & ndiv)>>8;
706 Serial.print(F(
"tx1 = "));
708 Serial.print(F(
"tx2 = "));
710 Serial.print(F(
"tx3 = "));
712 Serial.print(F(
"tx4 = "));
714 Serial.print(F(
"tx5 = "));
718 *rx = SPI.transfer(tx1);
719 *rx = SPI.transfer(tx2);
720 *rx = SPI.transfer(tx3);
721 *rx = SPI.transfer(tx4);
722 *rx = SPI.transfer(tx5);
741 Serial.print(F(
"Actual Output Frequency (closest available) is "));
742 Serial.print(frf_act[1]);
743 Serial.println(
"Hz");
747 temp_math[0]=frf_act[0];
748 temp_math[1]=frf_act[1];
751 div64(temp_math,temp_long);
752 Serial.print(F(
"Actual Output Frequency (closest available) is "));
753 Serial.print(temp_math[1]);
754 Serial.print(
"MHz + ");
757 mul64(temp_math,temp_long);
758 sub64(frf_act,temp_math);
759 Serial.print(frf_act[1]);
760 Serial.println(
"Hz");
769 void prt(
unsigned long an[])
771 Serial.print(an[0],HEX);
773 Serial.println(an[1],HEX);
783 void init64(
unsigned long an[],
unsigned long bigPart,
unsigned long littlePart )
800 void HZto64(
unsigned long an[],
unsigned long MHzPart,
unsigned long HzPart )
803 if ((MHzPart>4295) || ((MHzPart==4294) && (HzPart>=967296)))
806 an[1] =(MHzPart-4294L)*
OneMHz + HzPart-967296L;
811 an[1] = MHzPart*
OneMHz+HzPart;
822 if (an[1] & 0x80000000)
845 void shl64by(
unsigned long an[], uint8_t shiftnum)
849 for (i=0; i<shiftnum; i++)
852 if (an[1] & 0x80000000)
863 void shr64by(
unsigned long an[], uint8_t shiftnum)
867 for (i=0; i<shiftnum; i++)
881 void add64(
unsigned long an[],
unsigned long ann[])
884 if (an[1] + ann[1] < ann[1])
894 void sub64(
unsigned long an[],
unsigned long ann[])
909 boolean eq64(
unsigned long an[],
unsigned long ann[])
911 return (an[0]==ann[0]) && (an[1]==ann[1]);
919 boolean lt64(
unsigned long an[],
unsigned long ann[])
921 if (an[0]>ann[0])
return false;
922 return (an[0]<ann[0]) || (an[1]<ann[1]);
930 void div64(
unsigned long num[],
unsigned long den[])
932 unsigned long quot[2];
933 unsigned long qbit[2];
934 unsigned long tmp[2];
946 init64(num,0xffffffff,0xffffffff);
951 while (
lt64(den,tmp))
969 init64(num,quot[0],quot[1]);
977 void mul64(
unsigned long an[],
unsigned long ann[])
979 unsigned long p[2] = {0,0};
980 unsigned long y[2] = {ann[0], ann[1]};
void sub64(unsigned long an[], unsigned long ann[])
64 bit Subtract ann from an (an[] = an[] - ann[])
#define LTC6946_THI
for spi_map array, defines location for field specific information used to create the spi map ...
void shl64by(unsigned long an[], uint8_t shiftnum)
Multi Bit shift left of equivalent 64 bit number (an[] = an[]<<shiftnum)
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
void prt(unsigned long an[])
Prints HEX representation of 64 bit an.
unsigned long LTC6946_Frf_Hz
Default Frf frequency - Hz portion (yyy,yyy); Frf = x,xxx, yyy,yyy.
unsigned long get_LTC6946_global_fref_MHz()
returns global LTC6946_Fref_MHz
#define LTC6946_NUM_REGFIELD
Defines number of LTC6946 SPI fields, used in spi_map array.
void LTC6946_init()
Initializes the SPI MAP arrays The values set in initialization are used all the LTC6946 SPI/WRITE an...
#define LTC6946_TLO
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6946_CPINV
for spi_map array, defines location for field specific information used to create the spi map ...
#define output_high(pin)
Set "pin" high.
Header File for Linduino Libraries and Demo Code.
#define LTC6946_CP
for spi_map array, defines location for field specific information used to create the spi map ...
void shr64(unsigned long an[])
Single Bit shift right of equivalent 64 bit number (an[] = an[]<<1)
#define LTC6946_2_MINFREQ
LTC6946-2 lower freq limit.
#define LTC6946_4_MINFREQ
LTC6946-4 lower freq limit.
#define LTC6946_RD
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6946_REV
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6946_ALCULOK
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
#define LTC6946_CS
Define the SPI CS pin.
#define LTC6946_NUM_REGADDR
Defines number of LTC6946 SPI registers, used in spi_map array.
#define LTC6946_3_MINFREQ
LTC6946-3 lower freq limit.
#define LTC6946_3_MAXFREQ
LTC6946-3 upper freq limit.
#define LTC6946_PDOUT
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 shl64(unsigned long an[])
Single Bit shift left of equivalent 64 bit number (an[] = an[]<<1)
uint8_t LTC6946_spi_map[(LTC6946_NUM_REGFIELD+1)][4]
LTC6946 spi map, stores MSB address location, MSB bit location, field length in bits, and R or RW capability.
#define LTC6946_BD
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long LTC6946_Fref_Hz
Default Fref frequency - Hz portion (yyy,yyy); Fref = x,xxx, yyy,yyy.
#define LTC6946_OD
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6946_ALCMON
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6946_CPWIDE
for spi_map array, defines location for field specific information used to create the spi map ...
uint8_t get_LTC6946_SPI_FIELD_NUMBITS(uint8_t f)
returns the number of bits for a given field name in the SPI map
void set_LTC6946_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 LTC6946 RW address.
#define LTC6946_MTCAL
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6946_ALCLO
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long get_LTC6946_global_fref_Hz()
returns global LTC6946_Fref_Hz
#define LTC6946_PDVCO
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6946_LKEN
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6946_FILT
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6946_ALCHI
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6946_1_MAXFREQ
LTC6946-1 upper freq limit.
uint16_t LT_uint16
16-bit unsigned integer to be converted to two bytes
unsigned long LTC6946_calc_odiv(char part_version[], unsigned long frf[2])
calculates the output divider setting based on the frf and version of LTC6946
#define LTC6946_1_MINFREQ
LTC6946-1 lower freq limit.
#define output_low(pin)
Set "pin" low.
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 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.
void set_LTC6946_SPI_FIELD(uint8_t cs, uint8_t f, long field_data)
Sets the LTC6946 SPI field value calls function LTC6946_read_field, which reads specific address/fiel...
#define LTC6946_CPRST
for spi_map array, defines location for field specific information used to create the spi map ...
uint8_t LTC6946_write_field(uint8_t cs, long field_data, uint8_t address, uint8_t MSB_loc, uint8_t numbits)
LTC6946 Write Single Field For SPI FIELDS in 1 or multiple address locations reads specific address/f...
uint8_t get_LTC6946_REGSIZE()
returns # of addresses in parts register map (array size)
#define LTC6946_PDREFO
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6946_BST
for spi_map array, defines location for field specific information used to create the spi map ...
void LTC6946_write(uint8_t cs, uint8_t address, uint8_t Data)
LTC6946 Write Single Address writes 8 bit Data field to LTC6946.
#define LTC6946_CAL
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6946_LOCK
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.
LTC6946: Ultralow Noise and Spurious 0.37GHz to 6.39GHz Integer-N Synthesizer with Integrated VCO...
#define LTC6946_PDALL
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long zero64[]
for 64bit math functions
#define LTC6946_4_MAXFREQ
LTC6946-4 upper freq limit.
#define ADDRx
used for 2nd dim of 2d spi_map array
#define LTC6946_ALCCAL
for spi_map array, defines location for field specific information used to create the spi map ...
unsigned long get_LTC6946_global_frf_MHz()
returns global LTC6946_Frf_MHz
#define LTC6946_RFO
for spi_map array, defines location for field specific information used to create the spi map ...
void LTC6946_set_frf(char part_version[])
FUNCTION: LTC6946_set_frf Calculates the integer (N), fractional (NUM) and output divider (OD) SPI va...
void shr64by(unsigned long an[], uint8_t shiftnum)
Multi Bit shift right of equivalent 64 bit number (an[] = an[]>>shiftnum)
unsigned long LTC6946_Frf_MHz
Default Frf frequency - MHz portion (xxxx); Frf = x,xxx, yyy,yyy.
unsigned long LTC6946_Fref_MHz
Default Fref frequency - MHz portion (xxx); Fref = xxx, yyy,yyy.
long LTC6946_read_field(uint8_t cs, uint8_t address, uint8_t MSB_loc, uint8_t numbits)
LTC6946 Read Single Field For SPI FIELDS located in 1 or multiple address locations reads specific ad...
#define LTC6946_ALCEN
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6946_UNLOK
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 add64(unsigned long an[], unsigned long ann[])
64 bit Add ann to an (an[] = an[] + ann[])
void set_LTC6946_global_frf(unsigned long frf_MHz, unsigned long frf_Hz)
sets globals LTC6946_Frf_MHz and LTC6946_Frf_Hz
#define LTC6946_LKWIN
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6946_PDPLL
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
unsigned long get_LTC6946_global_frf_Hz()
returns global LTC6946_Frf_Hz
#define LTC6946_LKCT
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6946_2_MAXFREQ
LTC6946-2 upper freq limit.
#define LTC6946_CPUP
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6946_OMUTE
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6946_CPCHI
for spi_map array, defines location for field specific information used to create the spi map ...
uint8_t LTC6946_read(uint8_t cs, int8_t address)
LTC6946 Read Single Address reads 8 bit Data field to LTC6946.
#define LTC6946_x
for spi_map array, defines location for field specific information used to create the spi map ...
uint8_t get_LTC6946_SPI_FIELD_RW(uint8_t f)
returns if the given field name is (0)read/write or (1)read_only field
#define LTC6946_PART
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 QUIKEVAL_CS
QuikEval CS pin (SPI chip select on QuikEval connector pin 6) connects to Arduino SS pin...
uint8_t LTC6946_reg[LTC6946_NUM_REGADDR]
number of LTC6946 spi addresses
#define LTC6946_POR
for spi_map array, defines location for field specific information used to create the spi map ...
#define LTC6946_CPDN
for spi_map array, defines location for field specific information used to create the spi map ...
long get_LTC6946_SPI_FIELD(uint8_t cs, uint8_t f)
Gets the LTC6946 SPI field value calls function LTC6946_read_field, which reads specific address loca...
#define LTC6946_CPCLO
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
#define LTC6946_ND
for spi_map array, defines location for field specific information used to create the spi map ...
void set_LTC6946_global_fref(unsigned long fref_MHz, unsigned long fref_Hz)
sets globals LTC6946_Fref_MHz and LTC6946_Fref_Hz
#define LTC6946_CPMID
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