CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

More on AD9833

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
beaker404



Joined: 24 Jul 2012
Posts: 163

View user's profile Send private message

More on AD9833
PostPosted: Fri Jan 10, 2020 9:40 am     Reply with quote

Getting a AD9833 DDS running for evaluation for a project.
I have been following the recent thread on the AD9833 using SPI.
As a test I am getting the Analog Devices application note AN-1070 example to run. Link: https://www.analog.com/media/en/technical-documentation/application-notes/AN-1070.pdf
and I am using the Analog Devices Data sheet for reference. There are two version running around the web. The complete datasheet is Link: https://www.analog.com/media/en/technical-documentation/data-sheets/ad9833.pdf

My problem can be stated as this: I can make the chip do different things, but I do not have control of it. I seem to get a square wave that is around 4.3MHz when coded with the AN-1070 example. I am running a MCLK of 25MHz from a TTL oscillator. This signal looks good. When I swap to a sine wave output I get a really poor sine wave, probably due to the frequency of the output being so high and too close to the MCLK.
My code snippets are:

Code:
#include <16f876.h>
#DEVICE ADC=10                                      // Makes 16F876 run AD in 10 bit mode.
#include <stdlib.h>
#include <stdint.h>

#use delay(crystal=4M)
#FUSES XT,NOWDT,NOPROTECT,PUT,NOBROWNOUT,NOLVP,NODEBUG

#DEFINE FSYNC        PIN_B4

void AD9833_Write(unsigned int16 value)
{
   int8 clsb, cmsb, dummy;

   clsb = make8(value,0); //faster than rotations etc..
   cmsb = make8(value,1);
   output_low(FSYNC);
   delay_us(1);
   dummy = spi_read(clsb);
   dummy = spi_read(cmsb);

   delay_ms(10);
   
   output_high (FSYNC);
}


void initialize_hardware() {
// necessary hardware setup.

setup_spi(SPI_MASTER | SPI_H_TO_L |SPI_CLK_DIV_16 );
output_high(LED);          //LED off     

}  // end initialize_hardware()

void LED_blink() {
// blinks the LED

if(LED_status == 1) {

   LED_status = 0;
   output_low(LED);

}
else {

   LED_status = 1;
   output_high(LED);

}


}  // end LED_blink()



My main loop is rather simple at this point:

Code:
void main() {


delay_ms(1000);
delay_ms(1000);

initialize_hardware();

AD9833_Write(0X2100);
delay_ms(10);
AD9833_Write(0X50C7);
delay_ms(10);
AD9833_Write(0X4000);
delay_ms(10);
AD9833_Write(0XC000);
delay_ms(10);
AD9833_Write(0X2000);


while(1)  {                      // Endless loop

LED_blink();
delay_ms(1000);

} // end endless while loop
}  // end main.


Running a 16F876 at 4MHz. Using SPI hardware port.

MPlab 8.91
CCS V 5.064
Windows 10

Thoughts/observations/comments welcome on this one.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: More on AD9833
PostPosted: Fri Jan 10, 2020 11:29 am     Reply with quote

beaker404 wrote:

I seem to get a square wave that is around 4.3MHz when coded with the
AN-1070 example.

AN-1070 says on page 3:
Quote:

The aim is to generate a 400 Hz output frequency using the
AD9833 with a 25 MHz MCLK.

So, if you're really getting 4.3 MHz, it's totally wrong. Are you getting 4.3 MHz ?
beaker404



Joined: 24 Jul 2012
Posts: 163

View user's profile Send private message

PostPosted: Fri Jan 10, 2020 12:24 pm     Reply with quote

Yes getting 4.3Mhz. I agree wrong, Just looking for ideas as to why and if possibly my SPI has something to do with it.
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jan 10, 2020 12:49 pm     Reply with quote

Since your setup/control data is as the example, I'm thinking the SPI 'mode' is wrong....
SPI has 4 modes, easy enough to check and test them out....
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jan 10, 2020 1:24 pm     Reply with quote

Quote:
void AD9833_Write(unsigned int16 value)
{
int8 clsb, cmsb, dummy;

clsb = make8(value,0); //faster than rotations etc..
cmsb = make8(value,1);
output_low(FSYNC);
delay_us(1);
dummy = spi_read(clsb);
dummy = spi_read(cmsb);

delay_ms(10);

output_high (FSYNC);
}

The AD9833 data sheet says bit 15 goes out first.
See "Figure 4. Serial Timing" on page 4.

You have the LSB going out first. This is wrong. You should have caught this.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group