AnsweredAssumed Answered

AD9834 Output Problem

Question asked by nerbone85 on Mar 6, 2012
Latest reply on Mar 14, 2012 by nerbone85

Hi,

I need help!! :-) ...I'd like to generate a sinewave output at 5 kHz with two different phase values (0 and 180 degrees) using AD9834. To do it I drive DDS with SPI interface of my ATmega644P, with 3V power supply. Instead, for MCLK of DDS I have a 4MHz squarewave signal generated with the microcontroller.

Using "AD9834 Device Configuration Assistant" I set DDS as following:

 

#include <avr/io.h>

#define F_CPU 8000000UL

#include <util/delay.h>

#include <avr/interrupt.h>

//-----------------------------------SPI-----------------------------------//

#define DDR_SPI    DDRB

#define DD_MOSI    DDB5

#define DD_SCK    DDB7

#define DD_CS    DDB4

 

void SPI_MasterInit(void)  {

   DDR_SPI = (1<<DD_MOSI)|(1<<DD_SCK)|(1<<DD_CS);

   SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1) | (1<<CPOL);

}   

 

void SPI_MasterTransmit(char cData) {

   SPDR = cData;   

   while (!(SPSR &(1<<SPIF)));

}

 

void SPI_Begin(void) {

    PORTB &= ~( 1 << DD_CS);

}

 

void SPI_End(void) {

    PORTB |= 1 << DD_CS;

}

 

void SPI_Set(void) {

    PORTB |= 1 << DD_CS;

}

 

void spi_ad_16(unsigned short data) {

    unsigned char MSdata = ((data >>8) & 0x00FF);

    unsigned char LSdata = (data & 0x00FF);

   

    SPDR = MSdata; 

    while(!(SPSR & (1<<SPIF)));

    SPDR = LSdata;

    while(!(SPSR & (1<<SPIF)));

}

//-----------------------------------END SPI--------------------------------------------//

 

int main(void) {

 

//--------------- MCLK Generation 4 MHz----------------------------------------//

    DDRD = 0x60;    // OC1A as output CLOCK for MCLK   

    TCCR1B |= (1 << WGM12);    

    OCR1A = 0;   

    TCCR1A |= (1 << COM1A0);   

    TCCR1B |=(1 << CS10);   

//----------------- SPI -------------------------------------------------------------------//

    SPI_Set();

    SPI_MasterInit();

    SPI_Begin();

                 spi_ad_16(0x2300);    

                 spi_ad_16(0x5EB8);   

                 spi_ad_16(0x4014); 

                 spi_ad_16(0x8000); 

                 spi_ad_16(0x8000); 

                 spi_ad_16(0xC000);   

                 spi_ad_16(0xE800); 

                 spi_ad_16(0x2200);

     SPI_End();

     _delay_ms(200);

                               

    while(1) {}

}

...On DDS output pin I'm able to read only a constant voltage value on my oscilloscope and I can't see sinusoidal wave at my desiderable frequency 5 kHz. I don't understand why!? ...thanks for your help.

Attachments

Outcomes