AnsweredAssumed Answered

AD9833 Frequency Not getting updated

Question asked by shri.bhairavkar on Dec 12, 2016
Latest reply on Dec 13, 2016 by musach

Hi I am Shrikant Bhairavkar. I am using AD9833 function generator IC to generate 100KHz sine wave. I have interfaced AD9833 to PIC16705 in SPI mode 2 i.e. CPOL=1, CPHA=0. My MCLK is 25MHz through oscillator. When I run program I am able to see the update on the SPI lines as per the mode and it seems data gets transferred. But the frequency registers are not getting updated.

 

Also some noise observed at output. When registers not updated some default frequency is observed around 800Hz.

Please help for the issue.

 

Please find the attached code for same:

/*
 * File:   Main.c
 * Author: E0404062
 *
 * Created on December 12, 2016, 2:32 AM
 */

#include <stdio.h>
#include <stdlib.h>

#include "Main.h"

/*   local macros  */
#define set_value 1
#define clear_value 0
#define ENABLE 1
#define DISABLE 0
#define input_tri 1
#define output_tri 0

 

/*  Local functions  */
void initialization_ssp(void);
void SSP_module_Enable(int status);
void send_value(char data);
void go(void);


int main(int argc, char** argv) {


      int i=0;
    initialization_ssp();

    go();
 
    while(1)
    {
     
     
    }


    return (EXIT_SUCCESS);
}

void go(void)
{
    int i=0;
   
      RC2 = clear_value;//make FSYNC low
 send_value(0x21);
 send_value(0x00);
       RC2 = set_value;//make FSYNC HIgh

      
       RC2 = clear_value;//make FSYNC low
 send_value(0x7F);
 send_value(0xFF);

      RC2 = set_value;//make FSYNC HIgh

      

       RC2 = clear_value;//make FSYNC low

 send_value(0x40);
 send_value(0xA0);
       RC2 = set_value ;

       RC2 = clear_value;//make FSYNC low
 send_value(0xC0);
 send_value(0x00);

       RC2 = set_value;//make FSYNC HIgh
     

      RC2 = clear_value;//make FSYNC low
 send_value(0x20);
 send_value(0x00);
       RC2 = set_value;//make FSYNC HIgh
      for(i=0;i<30;i++);

}

void initialization_ssp()
{
   /* set clock frequency to internal 16Mhz oscilator and pll is on */
    OSCCON = 0x7B;

    // disable the module
    //SSP_module_Enable(DISABLE);


    /*    peripheral pin configuration  */

    //mssp:sck->RC0
    TRISC0 = output_tri; // RC0 as output
 
    RC0PPS = 0x10;
   // SSPCLKPPS = 0x10;


    //mssp:SDA -> RC1

    TRISC1 = output_tri; // RC1 as output
 

    RC1PPS = 0x12;

   // SSPDATPPS = 0b10000;


    //RC2->ss
    TRISC2  = output_tri; // RC2 as output which will connect to FSYNC og AD9833

     /* SSP moidule configuration */

   // CKP = 1; // idle high ,falling edge detect
    CKE = 0;

    SMP = 0; // data is sampled at the middle of data transmission

  //  SSPOV = 0; //no obverflow

   // SSPM0 = 0; //fosc/4
  //  SSPM1 = 0;
  //  SSPM2 = 0;
   // SSPM3 = 0;
   // SSP1ADD = 0x00;

    SSP1CON1 = 0x30;


 //SSP_module_Enable(ENABLE);


}

void SSP_module_Enable(int status)
{
    SSPEN = status;
}


void send_value(char data)
{
    int i=0;
    //while((BF == 1));
   // for(i=0;i<50;i++);
    SSP1BUF = data;
   // while(!(SSP1IF));
   // SSP1IF = clear_value;
    for(i=0;i<10;i++);

}

 

SPI waveforms

Attachments

Outcomes