Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8592603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:47:24+00:00 2026-06-11T23:47:24+00:00

I am trying to generate sine wave using programmable waveform generator AD9833 with ATmega32-A

  • 0

I am trying to generate sine wave using programmable waveform generator AD9833 with ATmega32-A micro controller.(MCLK =8MHz clock frequency). I am using USART communication and so if i change frequency in hyper terminal then the waveform frequency has to change.
I wrote small code for this as shown below.

but from the above code I am generating sine wave but if I want to change frequency of signal to 125KHz then I have to enter 499.9KHz at hyperteminal.If i enter 125 KHz then it is showing 31.2KHz. I don’t know why it is generating like that and what mistake I did? and also it is changing the waveform until 500KHz frequency suppose if i enter frequency of wave form around 1000KHz but there is no change in the frequency of the signal it is showing only 125KHz.

finally i want to generate waveform with different frequency’s. If I change frequency at hyper terminal or putty then what ever frequency I enter it has to generate waveform with that frequency.

This is my first post so if any grammatical mistakes are there then please excuse me.

Thanks in advance.

     void unicom(void){

         switch(Command){


                case(WGF):
            if(Param < 500)
                SetWGFreq(Param);   
                Command = 0;
            break; 

               case....
               case....
               default:
             }

  void main(void){
  SetWGFreq(125);
  -----------
   --------
   }

Hi Once Again,

This time i am trying programming AD9833 with SM470R1B1M-HT microcontroller via SPI. I am fallowing the same principle as explained by the “ross” below.
It seems i am not able to change sinewave frequency.
Below is the code i am trying, I set the same configuration with clocks as before.

void SetupSPI(void);
unsigned char spi(unsigned char data);
void SetWGFreq(unsigned int);
void setFrequencyA(unsigned long fdata);
void WG_CS_Status(int status);

int main(void)
{
GCR &= ~ZPLL_MULT4; 
GCR &= ~ZPLL_CLK_DIV_PRE1; 
GCR &= ~ZPLL_CLK_DIV_PRE2;
GCR &= ~ZPLL_CLK_DIV_PRE3;   

PCR = CLKDIV_1;                         // ICLK = SYSCLK 
PCR |= PENABLE;                         // Enable peripherals

GIODIRA |= X7;

CLKCNTL |= CLKDIR | CLKSR_ICLK;

SetupSPI();

for(;;)
{
  //SetWGFreq(25);
  setFrequencyA(1045200);
}                             // Wait in endless loop
}

void SetupSPI(void)
{
int data = 0;

 SPI2CTRL1 = CHARLEN_8 + PRESCALE_4;                // 8 bits per xfer
 SPI2CTRL2 |= CLKMOD + MASTER + POLARITY;             // We are the master
 SPI2PC6 |= SOMI_FUN | SIMO_FUN | CLK_FUN;
 // SPI2PC6 |=   0x0E;
 // enable
 SPI2CTRL2 |= SPIEN;

 data = SPI2BUF;
}

unsigned char spi(unsigned char data)
 {
    SPI2DAT1 = data;             
    while(!(SPI2CTRL3 & 0x01)){}        // Wait for RxFlag to get set    
    return (SPI2BUF & 0x000000FF);      // Read SPIBUF 
 } 

void setFrequencyA(unsigned long fdata)
 {
 WG_CS_Status(0);
 while(GIODOUTA&X7);   // Delay
 spi(0x20);      // Initiate loading of frequence register 0 by 28 bits.
 spi(0x00);
 spi(( 0x40 | (0x3F & (fdata >> 8))));   // load bit 8-13 + 0x40.
 spi(fdata);                             // load bit 0-7
 spi(( 0x40 | (0x3F & (fdata >> 22))));  // load bit 22-27 + 0x40.
 spi(fdata >> 14);                       // load bit 14-21
 spi(0);   // dummy write
 WG_CS_Status(1);
}
void WG_CS_Status(int status)
 {    
 if(status == 0)
  {
     // Make Chip Select low
     GIODOUTA &= ~X7;
  }
 else
  {
     // Make Chip select high
     GIODOUTA |= X7; 
   }
 }

I am attaching the SPI guide i fallowed for this controller and AD9833 programming not.SPI guide AD9833

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:47:25+00:00Added an answer on June 11, 2026 at 11:47 pm

    When you’re converting the frequency to the two blocks of 14-bit numbers the AD9833 needs, you’re OR’ing in the D14 and D15 of the frequency register. There are two problems there.

    The first problem is that you’re losing 4 bits (2 bits of a time) of your freg value.

    76543210 76543210 76543210 76543210
    LL000000 00000000 LL000000 00000000 //The L's are lost because they're overwritten by the addressing.
    

    The second problem is that you need the bits 15 and 14 to be exactly 0x40. Right now with OR’ing in the data the result could be 0xC0 if data had already been there based on your frequency.

    As a minor note I see no reason to use masks when assigning to fByte0-3, as you’re using as assignment.

    So, combining the two fixes and simplifying the masks gives:

    fByte0 = (char)freg;
    fByte1 = (char)(freg>>8);
    fByte1 = (fByte1 & 0x3F) | 0x40; //clears bits 15 and 14, then sets for FREQ0
    fByte2 = (char)(freg>>14);  //byte1 only has 6 bits, so move over by 8+6
    fByte3 = (char)(freg>>22);  //byte1 only has 6 bits, so move over by 8+8+6
    fByte3 = (fByte3 & 0x3F) | 0x40; //clears bits 15 and 14, then sets for FREQ0
    

    I think that’ll get you where you want to be.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to generate C code from a Matlab-Simulink simple model (eg.: sine wave
Im trying to generate a color gradient using ColdFusion. My current code below works
I'm trying to generate the following html code using cl-who: <html> <body> <div id=cnt_1></div>
Im am trying to generate interfaces of HP Quality Center OTACLien.dll using com4j. I
I'm trying to generate a pdf file from data in a database using JasperReports
I'm trying to generate a request token using oauth2 in a Pyramid application for
While trying to generate a pdf using ExpertPdf.HtmlToPdf, it's using a lot of memory.
I'm trying to generate a ParameterizedType using Guice's Types library. Butler is an inner
Im trying to generate a week view calendar using codeigniter's calendar library.. something like
I'm trying to generate a Java Client with the axis using wsdl2java (wrapped by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.