Trying AD9833 as per Application Note AN-1070

Discussion in 'Embedded Systems and Microcontrollers' started by vineet_barc, Jul 30, 2014.

  1. vineet_barc

    Thread Starter New Member

    Sep 4, 2009
    3
    0
    Hi,
    I am trying to generate sine wave ( using MSP430FG4618 ) from AD9833. Studied the application note AN-1070 but not getting output.

    Code ( (Unknown Language)):
    1.  
    2. *********************** Code ************************
    3.  
    4. #include "msp430xG46x.h"
    5.  
    6. #define FSYNC_AD9833_DIR    P4DIR |= BIT6;
    7. #define FSYNC_AD9833_HIGH   P4OUT |= BIT6;    // Set FSYNC HIGH
    8. #define FSYNC_AD9833_LOW    P4OUT &= ~BIT6;    // Set FSYNC LOW
    9.  
    10. #define AD9833_REG_CMD      (0 << 14)
    11. #define AD9833_REG_FREQ0    (1 << 14)
    12. #define AD9833_REG_FREQ1    (2 << 14)
    13. #define AD9833_REG_PHASE0   (6 << 13)
    14. #define AD9833_REG_PHASE1   (7 << 13)
    15.  
    16. /* Command Control Bits */
    17.  
    18. #define AD9833_B28          (1 << 13)
    19. #define AD9833_HLB          (1 << 12)
    20. #define AD9833_FSEL0        (0 << 11)
    21. #define AD9833_FSEL1        (1 << 11)
    22. #define AD9833_PSEL0        (0 << 10)
    23. #define AD9833_PSEL1        (1 << 10)
    24. #define AD9833_PIN_SW       (1 << 9)
    25. #define AD9833_RESET        (1 << 8)
    26. #define AD9833_SLEEP1       (1 << 7)
    27. #define AD9833_SLEEP12      (1 << 6)
    28. #define AD9833_OPBITEN      (1 << 5)
    29. #define AD9833_SIGN_PIB     (1 << 4)
    30. #define AD9833_DIV2         (1 << 3)
    31. #define AD9833_MODE         (1 << 1)
    32.  
    33. #define AD9833_OUT_SINUS    ((0 << 5) | (0 << 1) | (0 << 3))
    34. #define AD9833_OUT_TRIANGLE ((0 << 5) | (1 << 1) | (0 << 3))
    35. #define AD9833_OUT_MSB      ((1 << 5) | (0 << 1) | (1 << 3))
    36. #define AD9833_OUT_MSB2     ((1 << 5) | (0 << 1) | (0 << 3))
    37.  
    38. void AD9833_Write_Word(unsigned int value)
    39. {
    40.     int i;
    41.     char clsb, cmsb;
    42.  
    43.     clsb = (char)value;
    44.     cmsb = value >> 8;
    45.  
    46.     FSYNC_AD9833_LOW
    47.     for(i=5;i>0;i--){}            // delay
    48.  
    49.     while (!(IFG2 & UTXIFG1));  // USART1 TX buffer ready?
    50.     U1TXBUF = cmsb;             //send_AD9833char(cmsb);
    51.     while (!(IFG2 & UTXIFG1));  // USART1 TX buffer ready?
    52.     U1TXBUF = clsb;             //send_AD9833char(clsb);
    53.     while (!(IFG2 & UTXIFG1));  // USART1 TX buffer ready?
    54.  
    55.     for(i=10;i>0;i--){}            // delay
    56.     FSYNC_AD9833_HIGH
    57.  
    58. }// AD9833_Write_Word
    59.  
    60. void main()    // ##################################
    61. {
    62.     int i;
    63.  
    64.     WDTCTL = WDTPW + WDTHOLD;       // Stop watchdog timer
    65.  
    66.     FLL_CTL0 |= XCAP14PF;           // Configure load caps
    67.     do // Wait for xtal to stabilize
    68.     {
    69.         IFG1 &= ~OFIFG;                 // Clear OSCFault flag
    70.         for (i = 0x47FF; i > 0; i--);    // Time for flag to set
    71.     }
    72.     while ((IFG1 & OFIFG));            // OSCFault flag still set?
    73.  
    74.     FSYNC_AD9833_DIR                      
    75.     FSYNC_AD9833_HIGH                  
    76.  
    77.     P4SEL |= 0x28;                   // P4.3 & P4.5 = SPI SIMO1 & UCLK1
    78.     U1CTL |= SWRST;               // USART logic held in RESET state
    79.     U1CTL |= CHAR|SYNC|MM;   // 8-bit data, SPI mode, Mater mode
    80.  
    81.     U1TCTL |= CKPL|SSEL1|STC;
    82.     U1BR1 = 0;                  // Baud Rate = (1MHz/8) = 131072
    83.     U1BR0 = 8;                                
    84.     U1MCTL = 0x000;                        
    85.  
    86.     ME2 |= USPIE1;              // Enables the SPI mode for USART1
    87.     U1CTL &= ~SWRST;            // USART RESET released for operation
    88.    
    89.     AD9833_Write_Word(0x2100);
    90.     AD9833_Write_Word(0x50C7);  // For Generating Sinwave of
    91.     AD9833_Write_Word(0x4000);  // 400Hz...as per Application Note
    92.     AD9833_Write_Word(0xC000);  // AN-1070
    93.     AD9833_Write_Word(0x2000);
    94.  
    95.      while(1){}
    96.  
    97.  
    98. }// main
    99.  
     
    Last edited by a moderator: Jul 30, 2014
  2. bertus

    Administrator

    Apr 5, 2008
    15,635
    2,342
Loading...