Monday, November 17, 2008

Simple RF Sweep generator and plotter

Having recently manually plotted SWR for a couple of antennas I got thinking about how this might be automated.

As a proof of concept I hooked an Arduino up to a DDS, fed the RF through a little tuned circuit into an RF probe. The DC voltage from the RF probe goes back into an analog to digital port of the Arduino.

The program sends the current frequency and the A/D value out the serial port where I capture it and then plot with gnuplot. The graph looks like this:

graph.png

And it's pretty consistent from run to run.

Here's the lashed up prototype:

DSC01359.JPG


The Arduino sketch is:


// Control a AD9851 DDS based on the good work of others including:
// Mike Bowthorpe, http://www.ladyada.net/rant/2007/02/cotw-ltc6903/ and
// http://www.geocities.com/leon_heller/dds.html
// This code by Peter Marks http://marxy.org

#define DDS_CLOCK 180000000

byte LOAD = 8;
byte CLOCK = 9;
byte DATA = 10;
byte LED = 13;

#define MHZ 1000000

void setup()
{
pinMode (DATA, OUTPUT); // sets pin 10 as OUPUT
pinMode (CLOCK, OUTPUT); // sets pin 9 as OUTPUT
pinMode (LOAD, OUTPUT); // sets pin 8 as OUTPUT
pinMode (LED, OUTPUT);

Serial.begin(9600);
}

void loop()
{
// Do a frequency sweep in Hz
for(unsigned long freq = 1 * MHZ; freq < 10 * MHZ; freq += 1 * MHZ / 4)
{
sendFrequency(freq);
delay(200);
Serial.print(freq / MHZ, DEC);
Serial.print(".");
Serial.print(freq - ((freq / MHZ) * MHZ), DEC);
Serial.print("\t");
int value = analogRead(0);
Serial.println(value, DEC);
}
Serial.println("----------");
}

void sendFrequency(unsigned long frequency)
{
unsigned long tuning_word = (frequency * pow(2, 32)) / DDS_CLOCK;
digitalWrite (LOAD, LOW); // take load pin low

for(int i = 0; i < 32; i++)
{
if ((tuning_word & 1) == 1)
outOne();
else
outZero();
tuning_word = tuning_word >> 1;
}
byte_out(0x09);

digitalWrite (LOAD, HIGH); // Take load pin high again
}

void byte_out(unsigned char byte)
{
int i;

for (i = 0; i < 8; i++)
{
if ((byte & 1) == 1)
outOne();
else
outZero();
byte = byte >> 1;
}
}

void outOne()
{
digitalWrite(CLOCK, LOW);
digitalWrite(DATA, HIGH);
digitalWrite(CLOCK, HIGH);
digitalWrite(DATA, LOW);
}

void outZero()
{
digitalWrite(CLOCK, LOW);
digitalWrite(DATA, LOW);
digitalWrite(CLOCK, HIGH);
}


It's just a start and I'm thinking you could make a simple antenna analyser by building a little SWR bridge. Looks like the miniVNA is something like this.

2 comments:

  1. Anonymous6:30 PM

    This is excellent Peter, all you need now is to use it with a return-loss bridge and you have a nice little scalar network analyser.

    How much RF does the DDS board generate? If it is enough to drive a simple diode probe in this lash-up it is probably OK for a resistive RLB. Otherwise teaming it up with a log power detector would be ideal, it could be calibrated directly in dB.

    I've got a heap of 100R chip resistors if you want to build a small RLB that should be flat to the 60 MHz that the DDS covers. Even just built with leaded components it would probably be OK.

    ReplyDelete
  2. The board puts out about 4V peak to peak low impedance so yes I think it could drive an antenna.

    I have one of those logarithmic chips so that's a natural fit of course.

    Thanks.

    ReplyDelete