View previous topic :: View next topic |
Author |
Message |
beaker404
Joined: 24 Jul 2012 Posts: 163
|
More on AD9833 |
Posted: Fri Jan 10, 2020 9:40 am |
|
|
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
|
Re: More on AD9833 |
Posted: Fri Jan 10, 2020 11:29 am |
|
|
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
|
|
Posted: Fri Jan 10, 2020 12:24 pm |
|
|
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
|
|
Posted: Fri Jan 10, 2020 12:49 pm |
|
|
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
|
|
Posted: Fri Jan 10, 2020 1:24 pm |
|
|
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. |
|
|
|