Saturday, 2 August 2014

DDS AD9850 Serial I/O

This is a simple sketch to use the AD9850 DDS with input from the keyboard (frequency in Hz) and display of the output frequency on the IDE Monitor.

// DDS AD9850, keyboard frequency input, use DDS library
// set Monitor for "Newline" 9600 baud

#include "DDS.h"

// pin connections
#define RST  4     // Pin  RST
#define DATA 5     // Pin  DATA
#define FQ   6     // Pin  FQ
#define CLK  7     // Pin  CLK

// DDS object
DDS dds(CLK, FQ, DATA, RST);

// start frequency
double newfreq = 7100000L; // 7.1MHz

void setup()
{

  Serial.begin(9600);
  while(!Serial);
  
  dds.init();
  dds.setFrequency(newfreq);
}

void loop()
{
  double freq;

  freq = newfreq;
  
  Serial.print("Frequency = ");
  Serial.print(freq);
  Serial.println(" Hz");

  newfreq = (double)get();

  if(newfreq != freq)
    dds.setFrequency(newfreq);
}

// get input as a float
float get()
{
  float n;

  while(Serial.available() > 0)
    Serial.read();
  while(Serial.available()  == 0) 
    n = Serial.parseFloat();
  return n;
}



No comments: