Gast
#985446
Servus zusammen, ich muss um den AD9833 anzusteuern 2 14-Bit Codewörter übertragen. Da meine AVR Kenntnisse fast 0 sind, wollte ich mal fragen, ob mir hier jmd. helfen kann... Leider kommt der AD9833 nicht in Wallung, ich vermute aber einen gravierenden Fehler in meinem Code... Besten Dank für alle Hinweise ! Lg Christian //includes ////////// #include "avr/io.h" //defines ///////// #define DDS_MCLK 24000000 /* DDS Clock */ #define DDS_CONSTANT 268435456 /* 2^28 */ #define DDS_DDR DDRD /* data direction reg*/ #define DDS_PORT PORTD #define DDS_SDATA PIN0 #define DDS_SCLCK PIN1 #define DDS_FSYNC PIN2 //predeclarations void DDS_WriteBits(int16_t nValue); //calculate codeword: //CW = (Freq / DDS_MCLK) * DDS_CONSTANT //for 5 mhz with 25 MHz clock: 0x33333333 int main(void) { //variables /////////// int32_t dwFreq = 5000000; int32_t dwCodeWord = (dwFreq / DDS_MCLK) * DDS_CONSTANT; //port init DDS_DDR = 0xFF; //all output DDS_WriteBits(dwCodeWord & 0xFFFF); DDS_WriteBits((dwCodeWord & 0x0000FFFF) << 16); while(1) { } return 0; } void DDS_WriteBits(int16_t nValue) { DDS_PORT &= ~_BV(DDS_FSYNC); SPDR = (nValue >> 8) & 0xFF; while(!(SPSR & _BV(SPIF))); SPDR = nValue & 0xFF; while(!(SPSR & _BV(SPIF))); DDS_PORT |= _BV(DDS_FSYNC); }