AnsweredAssumed Answered

AD9833 problem - Frequency doesn't change

Question asked by javat15 on Apr 20, 2018
Latest reply on May 7, 2018 by mcee

Hi,

 

I use a MSP432 to program an AD9833 but I'm not capable to change the frequency of this integrated circuit. I have implemented an SPI protocol and it sends the information correctly (see image below [1 - SDATA , 2 - SCLK, 3- CS])

 

1 - SDATA (MOSI), 2 - SCLK & 3 - Chip Select

 

Using this protocol I can reset the device (command 0x2100) and enable the output (0x2000) but I always obtain the same response. When I write in the other registers (FREQ0 - 0x50C7 & 0x4000 , PHASE0 - 0xC000) the output oscillate but with a random frequency (see image bellow). Sometimes this frequency it is 20Hz and other times it is 500Hz.

 

 

I don't undestand why the output hasn't change if I'm capable to communicate with the integrated circuit. I have checked all the pins and it seems that are any problem with the signals and the power supply.

 

I think that it could be a problem of the circuit but I have checked the datasheet several times but I think that is it correct (see image bellow).

 

 

The only difference with the image is the capacitors due I have used a 100nF ceramic capacitor in place of a 10nF in the COMP pin. Also, I use a 1MHz as MCLK and it is generated by the microcontroller.

 

I have no idea how to fix my problem. Does anybody has see my error? Could the integrated circuit be broken?

 

Sorry for my grammar.

 

PD: I post my code bellow

 

/*CODE*/

#include "msp.h"
#include <stdint.h>

/*Definiciones*/
#define elements 5

 

/*Variables*/
uint16_t Data1[elements] = {0x2100,0x50C7,0x4000,0xC000,0x2000};//16Hz
uint16_t Data2[elements] = {0x2100,0x4086,0x4000,0xC000,0x2000};//1Hz
uint16_t Data3[elements] = {0x2100,0x453e,0x4000,0xC000,0x2002};//10Hz
uint16_t Data4[elements] = {0x2100,0x68db,0x4001,0xC000,0x2000};//20Hz
uint16_t Data5[elements] = {0x2100,0x5893,0x4010,0xC000,0x2000};//100Hz

 

/*Funciones*/
//Configuración del reloj
void init_PWR(void){
while ((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
PCM->CTL0 = PCM_CTL0_KEY_VAL | PCM_CTL0_AMR_1;
while ((PCM->CTL1 & PCM_CTL1_PMR_BUSY));
FLCTL->BANK0_RDCTL = (FLCTL->BANK0_RDCTL & ~(FLCTL_BANK0_RDCTL_WAIT_MASK)) | FLCTL_BANK0_RDCTL_WAIT_1;
FLCTL->BANK1_RDCTL = (FLCTL->BANK0_RDCTL & ~(FLCTL_BANK1_RDCTL_WAIT_MASK)) | FLCTL_BANK1_RDCTL_WAIT_1;
}

 

void init_Clk(void){
CS->KEY = CS_KEY_VAL ; //Desbloqueo Clk
CS->CTL0 = 0; //Reset Clk
CS->CTL0 = CS_CTL0_DCORSEL_5; //DCO = 48MHz
CS->CTL1 = CS->CTL1 & ~(CS_CTL1_SELM_MASK | CS_CTL1_DIVM_MASK) | CS_CTL1_SELM_3; //MCLK = DCO
CS->KEY = 0; //Bloqueo Clk
}

 

//Configuración de los puertos
void init_PX(void){
//Puerto 1
P1SEL0 |= BIT5 | BIT6; //P1.5 & P1.6 => SPI SCLK & MOSI
P1SEL1 &= 0x00;
P1DIR |= BIT5 | BIT6; //BIT0 | BIT5 | BIT6; //P1.0 => LED
P1OUT &= 0x00;//|= BIT0;
//Puerto 2
P2SEL0 |= BIT7; //P2.7 => Timer (PWM)
P2SEL1 &= 0x00;
P2DIR |= BIT4 | BIT6 | BIT7; //P2.4 & P2.6 => A1 & A2 (MUX)
P2OUT &= 0x00;
//Puerto 4
P4SEL0 &= 0x00;
P4SEL1 &= 0x00;
P4DIR |= BIT2 | BIT4; //P4.2 & P4.4 => A0 & EN (MUX)
P4OUT &= 0x00;
//Puerto 5
P5SEL0 |= BIT5; //P5.5 => ADC
P5SEL1 &= 0x00;
P5DIR &= 0x00;
P5OUT &= 0x00;
//Puerto 6
P6SEL0 &= 0x00;
P6SEL1 &= 0x00;
P6DIR |= BIT1; //P6.1 => FSYNC
P6OUT |= BIT1;
}

 

//Configuración del timer 0
void init_Timer(void){
TA0CCR0 = 12-1; //PWM period
TA0CCTL4 = TIMER_A_CCTLN_OUTMOD_7; //CCR1 reset/set
TA0CCR4 = 6; //CCR1 PWM duty cycle
TA0CTL = TIMER_A_CTL_SSEL__SMCLK | TIMER_A_CTL_MC__UP | TIMER_A_CTL_CLR; //SMCLK|Up mode|Clear TAR
}

 

//Configuración del SPI
void init_SPI(void){
EUSCI_B0->CTLW0 |= EUSCI_B_CTLW0_SWRST; // Put eUSCI state machine in reset
EUSCI_B0->CTLW0 = EUSCI_B_CTLW0_SWRST | // Remain eUSCI state machine in reset
EUSCI_B_CTLW0_MST | // Set as SPI master
EUSCI_B_CTLW0_SYNC | // Set as synchronous mode
EUSCI_B_CTLW0_CKPL | // Set clock polarity high
EUSCI_B_CTLW0_MSB; // MSB first
EUSCI_B0->CTLW0 |= EUSCI_B_CTLW0_SSEL__SMCLK; //EUSCI_B_CTLW0_SSEL__ACLK; // ACLK
EUSCI_B0->BRW = 0x20; // /2,fBitClock = fBRCLK/(UCBRx+1).
EUSCI_B0->CTLW0 &= ~EUSCI_B_CTLW0_SWRST; // Initialize USCI state machine
}

 

//Envio de dos bytes por el SPI
void send_2Bytes_SPI(uint16_t data){

uint32_t data_new_1 = (data>>8)&0xFF;
uint32_t data_new_2 = data&0xFF;
while(!(UCB0IFG&UCTXIFG));
P6OUT &=~ BIT1;
UCB0TXBUF = data_new_1;
UCB0TXBUF = data_new_2;
//while(!(UCB0IFG&UCTXIFG));
while(UCB0STAT&UCBUSY)
__delay_cycles(120);
P6OUT |= BIT1;
}

 

/*main*/
uint8_t x = 0;
void main(void)
{
WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD; // stop watchdog timer

//Inicializaciones
init_PWR();
init_Clk();
init_PX();
init_Timer();
init_SPI();

 

//TA0CCTL4 = TIMER_A_CCTLN_OUTMOD_0; //desactivar PWM
//TA0CCTL4 = TIMER_A_CCTLN_OUTMOD_7; //activar PWM

 

//Configuración del AD9833

TA0CCTL4 = TIMER_A_CCTLN_OUTMOD_0;

for(x=0; x<elements; x++){
//__delay_cycles(100);
send_2Bytes_SPI(Data1[x]);
__delay_cycles(200);
}
TA0CCTL4 = TIMER_A_CCTLN_OUTMOD_7;

 

 

while(1){

 

}
}

Outcomes