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