Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

controlling dds with launchpad

$
0
0

Hi everyone, I'm new to launchpad and I want to control a DDS ad9850 module using launchpad.  I got this program to work so far. It compiles and uploads OK.  It will set the frequency I want and I have added serial input via USB and it works in that it answers back whatever I send via the serial monitor (using energia).  What I can't figure out, is how to take the data I send via the serial monitor to be put into the field at the bottom of the program ("sendFrequency"). It's now set to 7.255 Mhz If I change the number there, the DDS will change to that frequency, so the link to the serial data from the serial monitor is missing.  Can anyone help?   The program as it is now is shown below:  I'm using a launchpad MSP-EXP430G2 and 430G2553 micro.

 

 
#include <msp430g2553.h>
/* 
 *modified april 2 2015 by j. forkin to convert arduino to launchpad
 * A simple single freq AD9850 launchpad test script
 * Original AD9851 DDS sketch by Andrew Smallbone at www.rocketnumbernine.com
 * Modified for testing the inexpensive AD9850 ebay DDS modules
 * Pictures and pinouts at nr8o.dhlpilotcentral.com
 
 * Use freely
 */
 
#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); }
double freq2;
// 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) {
  int32_t freq = frequency * 4294967295/125000000;  // 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
}
//added this code to talk serially
void setup() {
  // configure launchpad data pins for output
  pinMode(FQ_UD, OUTPUT);
  pinMode(W_CLK, OUTPUT);
  pinMode(DATA, OUTPUT);
  pinMode(RESET, OUTPUT);
 
  pulseHigh(RESET);
  pulseHigh(W_CLK);
  pulseHigh(FQ_UD);  // this pulse enables serial mode - Datasheet page 12 figure 10
}
 
void loop() {
  
  
  sendFrequency(7255000);  // freq   THIS IS THE FIELD I NEED TO TIE TO THE SERIAL MONITOR INPUT //////////////////
  while(1);
}
 
 

 


Viewing all articles
Browse latest Browse all 2077

Trending Articles