/*************************************************************************
Function: Freq_change()
Purpose: change the frequency and select AD9833 onboard register
Input: unsigned short freq_out = frequency, unsigned int select = register 0 or 1
Returns: none
Comment: uses 14 bit filter and adds control words,
**************************************************************************/
void Freq_change ( unsigned short freq_out, unsigned int select ) // take base10 frequency and do frequency hop
{
unsigned long freq_reg = freq_out * 13.4217728; // make freq register from frequency // set for 20 MHz Mclk
unsigned short MS_reg = ((freq_reg>>14) & 0x3FFF); // filter out MS -- make 2 x 14 bit frequency words
unsigned short LS_reg = (freq_reg & 0x3FFF); // filter out LS -- make 2 x 14 bit frequency words
MS_reg += 0x4000; // add control bits hex = 0x4000
LS_reg += 0x4000; // add control bits hex = 0x4000
if (select == 0 ) { SPI_write16(0x2000);} // prep ad9833 to recieve full 28bit word for freq 0
if (select == 1 ) { SPI_write16(0x2800);} // prep ad9833 to recieve full 28bit word for freq 1
SPI_write16(LS_reg); // send the LS word first, to the ad9833
SPI_write16(MS_reg); // send the MS word last, to the ad9833
}
/*************************************************************************
Function: AD9833_init()
Purpose: Init the AD9833
Input: none
Returns: none
Comment: this function isn't nessecary, can be done manually
**************************************************************************/
void AD9833_init (void)
{
SPI_write16(0x2100); // control word, set output to mid value voltage
SPI_write16(0x7288); // Freq0 registerdata MSB = approx. 29 khz
SPI_write16(0x4017); // Freq0 registerdata LSB = approx. 29 khz
SPI_write16(0xACEA); // Freq1 registerdata MSB = approx. 24 khz
SPI_write16(0x8013); // Freq1 registerdata LSB = approx. 24 khz
SPI_write16(0xC000); // Phase offset of Freq0 = 0
SPI_write16(0xE000); // Phase offset of Freq1 = 0
SPI_write16(0x2000); // control word, set output = sine
}