Jump to content
43oh

Dual DDS control with launchpad & 430G2553 problem


Recommended Posts

I've written code to control a DDS for a transmitter project.  It works perfectly and generates the required local oscillator output.  I then wanted to add control for a second DDS module to generate two different frequencies for the BFO frequency.  Seems it should be simple, just duplicate the control for DDS1 for DDS2 however, it seems I can't get the second DDS to program.  I know the hardware is good as I can substitute one DDS for another with the same result.  I don't know if I'm chasing a launchpad problem or a software problem.  I'll attach my code and if anyone can suggest a solution, I would greatly appreciate it.  Also, if anyone can use this code, please feel free to do so.

 

code follows:



#include <msp430g2553.h>
/* transmit controller program
 * modified Dec 2016 to add functions to control second dds for BFO
 * modified april 2 2015 by WA3TFS to convert arduino to launchpad
 * DDS frequency set up and control program using launchpad and 430G2553
 * If using ver 1.4 or below board, jumper RXD and TXD diagonally
 * Original AD9851 DDS sketch by Andrew Smallbone at www.rocketnumbernine.com
 * Modified for programming the inexpensive AD9850 ebay DDS modules
 * WA3TFS Added serial function to load frequency and control of 5 low pass filters
  
 */
#define W_CLK 7        // Pin 7 - connect to AD9850 module word load clock pin (CLK)
#define FQ_UD 10       // Pin 10 - connect to freq update pin (FQ)
#define DATA 9         // Pin 9 - connect to serial data load pin (DATA)
#define RESET 8        // Pin 8 - connect to reset pin (RST).
#define pulseHigh(pin) {digitalWrite(pin, HIGH); digitalWrite(pin, LOW); }
#define ONESXTY 6      // select 160 meter band filter
#define EIGHTY 5       // select 80 meter band filter
#define FORTY 11       //select 40 meter band filter
#define TWENTY 15      //select 20 meter and above filter
#define THIRTY 18      //SELECT 15 meter and above filter
#define B_CLK 12       //clock BFO DDS
#define BQ_UD 13       //load BFO DDS
#define BATA 14        //BFO frequency
#define BESET 2        //BFO reset

long bfo;
long frequency;
long val;
long val2;
long val3;
long val4;
long bfreq;

// transfers a byte, a bit at a time, LSB first to the 9850 via serial DATA line
void tfr_bfobyte(byte data) 
{
  for (int f=0; f<8; f++, data>>=1) {
    digitalWrite(BATA, data & 0x01);
    pulseHigh(B_CLK);   //after each bit sent, CLK is pulsed high
  }
}

// transfers a byte, a bit at a time, LSB first to the 9850 via serial DATA line
void tfr_byte(byte data) 
{
  for (int i=0; i<8; i++, data>>=1) {
    digitalWrite(DATA, data & 0x01);
    pulseHigh(W_CLK);   //after each bit sent, CLK is pulsed high
  }
}

// frequency calc from datasheet page 8 = <sys clock> * <frequency tuning word>/2^32

void sendFrequency(double frequency) {
      //Serial.print(frequency);  //print actual value to monitor to debug **************added
  int32_t freq = frequency * 34.35973836;  // note 125 MHz clock on 9850
  for (int b=0; b<4; b++, freq>>=8) {
    tfr_byte(freq & 0xFF);
  }
  tfr_byte(0x000);   // Final control byte, all 0 for 9850 chip
  pulseHigh(FQ_UD);  // Done!  Should see output
  
}

// frequency calc from datasheet page 8 = <sys clock> * <BFO DDS frequency tuning word>/2^32
void sendBfo(double bfo) {
        //Serial.print(bfreq);  //print actual value to monitor to debug **************added

  int32_t bfreq = bfo * 34.35973836;  // note 125 MHz clock on 9850
  for (int e=0; e<4; e++, bfreq>>=8) {
    tfr_bfobyte(bfreq & 0xFF);
  }
  tfr_byte(0x000);   // Final control byte, all 0 for 9850 chip
  pulseHigh(BQ_UD);  // Done!  Should see BFO output
  }

//added this code to talk serially
void setup() {
  Serial.begin(9600);
  // configure launchpad data pins for output
  pinMode(FQ_UD, OUTPUT);
  pinMode(W_CLK, OUTPUT);
  pinMode(DATA, OUTPUT);
  pinMode(RESET, OUTPUT);
  pinMode(ONESXTY, OUTPUT);
  pinMode(EIGHTY, OUTPUT);
  pinMode(FORTY, OUTPUT);
  pinMode(TWENTY, OUTPUT);
  pinMode(THIRTY, OUTPUT);
  pinMode(B_CLK, OUTPUT);
  pinMode(BQ_UD, OUTPUT);
  pinMode(BATA, OUTPUT);
  pinMode(BESET, OUTPUT);
  digitalWrite(ONESXTY, LOW);  //SET UP INITIAL STATE OF CONTROL PINS
  digitalWrite(EIGHTY, LOW);
  digitalWrite(FORTY, LOW);
  digitalWrite(TWENTY, LOW);
  digitalWrite(THIRTY,HIGH);   //ON START UP ACTIVATE THIS FILTER
  pulseHigh(RESET);  //main dds reset
  pulseHigh(W_CLK);  //main dds clock
  pulseHigh(FQ_UD);  // this pulse enables updates main dds 
  pulseHigh(BESET);  //bfo dds reset
  pulseHigh(B_CLK);  //bfo dds clock
  pulseHigh(BQ_UD);  // this pulse updates bfo dds
  bfo = 899720;     //initial set of bfo freq on startup
}

//added this below to input required frequencies and offsets
//this also selects the proper low pass filter for the frequencies programmed
void loop()
{
  
  if (Serial.available()) {
    frequency = Serial.parseInt();

    Serial.println(frequency);
    if (frequency<1000) goto loop1;
      
    if (frequency>1500000)
    {
          digitalWrite(ONESXTY, HIGH);   //IF TRUE TURN OF THIS FILTER 
     if (frequency<(2100000)) 
          digitalWrite(ONESXTY, HIGH);   //IF TRUE TURN ON THIS FILTER
            else 
              digitalWrite(ONESXTY, LOW);  //TURN OFF OTHER LOW PASS FILTERS
              digitalWrite(EIGHTY, LOW);
              digitalWrite(FORTY, LOW);7100000
              7100000
              
              digitalWrite(TWENTY, LOW);
              digitalWrite(THIRTY, LOW);
                 bfo = (8997200);

    }
      if (frequency>2100001)
    {
          digitalWrite(EIGHTY, HIGH);   //IF TRUE TURN ON THIS FILTER 
     if (frequency<(4000000)) 
          digitalWrite(EIGHTY, HIGH);   //IF TRUE TURN ON THIS FILTER
            else 
              digitalWrite(EIGHTY, LOW);   //TURN OFF OTHER LOW PASS FILTERS
              digitalWrite(ONESXTY, LOW);
              digitalWrite(FORTY, LOW);
              digitalWrite(TWENTY, LOW);
              digitalWrite(THIRTY, LOW);
                 bfo = (899720);

    }
      if (frequency>4000001)
    {
          digitalWrite(FORTY, HIGH);   //IF TRUE TURN ON THIS FILTER 
     if (frequency<(7400000)) 
          digitalWrite(FORTY, HIGH);   //IF TRUE TURN ON THIS FILTE
            else
              digitalWrite(FORTY, LOW); //TURN OFF OTHER LOW PASS FILTERS
              digitalWrite(ONESXTY, LOW);
              digitalWrite(EIGHTY, LOW);
              digitalWrite(TWENTY, LOW);
              digitalWrite(THIRTY, LOW);
                 bfo = (899720);

    }
     if (frequency>7400001)
    {
          digitalWrite(TWENTY, HIGH);   //IF TRUE TURN ON THIS FILTER 
     if (frequency<(14400000)) 
          digitalWrite(TWENTY, HIGH);   //IF TRUE TURN ON THIS FILTE
            else 
              digitalWrite(TWENTY, LOW);   //TURN OFF OTHER LOW PASS FILTERS
              digitalWrite(ONESXTY, LOW);
              digitalWrite(EIGHTY, LOW);
              digitalWrite(FORTY, LOW);
              digitalWrite(THIRTY, LOW);
                 bfo = (900000);

    }
     if (frequency>14400001)
    {
          digitalWrite(THIRTY, HIGH);   //IF TRUE TURN ON THIS FILTER 
     if (frequency<(35000000)) 
          digitalWrite(THIRTY, HIGH);   //IF TRUE TURN ON THIS FILTER
            else 
              digitalWrite(THIRTY, LOW);  //TURN OFF OTHER LOW PASS FILTERS
              digitalWrite(ONESXTY, LOW);
              digitalWrite(EIGHTY, LOW);
              digitalWrite(FORTY, LOW);
              digitalWrite(TWENTY, LOW);
                 bfo = (900000);
    }
    
    
      frequency = (frequency + 8999825);// create local oscillator injection offset +/- from 9Mhz to correct osc. (freq 8999825)
      bfo = bfo;
    sendFrequency(frequency);  // send LO frequency to DDS ctrl.Offset 500 corrects frequency
      Serial.print(frequency);  //print actual value to monitor to debug offset not displayed
      Serial.print(bfo);  //print actual value to monitor to debug
    sendBfo(bfo);  // send BFO frequency to DDS ctrl.
      
      
loop1:;

  }
}



Link to post
Share on other sites

You have separate routines:

  void tfr_bfobyte(byte data) 
  void tfr_byte(byte data) 

And sendFrequency() calls tfr_byte(), but sendBfo() also calls tfr_byte() at one place.

 
I don't know if that's a problem or not.  My apologies for the noise if I'm off-base.
 
(Sometimes I have to print the code out on paper and spread it out in front of me, to see what's actually going on.)
Link to post
Share on other sites

Mike, 

You did point me in the right direction.  That statement was where the problem was.  I corrected it and now the second dds programs properly.  It's funny how you can look at the same code dozens of times and not see it!  I still have to fix a problem with a variable setting that passes the frequency for the second dds but I can fix that.

Thanks for your help.

Jim

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...