Wednesday 22 January 2014

Frequency generator AD9850

Thanks to various amateur radio enthusiasts for the code that makes this work.

I intend to expand it soon to include a tuning input (maybe push buttons, may be a knob...?) and a display of the frequency (that should be easy).

The module I used was just $3.5 on eBay!! And it is on sale from numerous suppliers in China - plus on in UK for £103!!! Clown.

Here's the setup

2014 01 22 14 24 36

It is extremely easy to use the module, just four connections if in the serial communications mode set by pulsing FQ high.

This is the code
// DDS-9850 module programmer
 
#define W_CLK 8       // Pin 8  CLK
#define FQ_UD 9       // Pin 9  FQ
#define DATA 10       // Pin 10 DATA
#define RESET 11      // Pin 11 RST
 
#define pulseHigh(pin) {digitalWrite(pin, HIGH); digitalWrite(pin, LOW); }

void setup()
{
  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
}

void loop() 
{
  sendFrequency(14.23e6);  // freq MHz e6
  while(1);
}

 // transfers a byte, a bit at a time, LSB first 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 =  * /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
  pulseHigh(FQ_UD);
}


I have so far only tested it by generating the 14.230MHz signal you can see it is programmed for and listening on an experimental SSTV receiver that I have nearly completed - more news soon.

No comments: