Skip to content

Commit

Permalink
First version
Browse files Browse the repository at this point in the history
Simple Scalar Network Analyzer code for Arduino and Python UI
  • Loading branch information
rheslip committed Aug 9, 2015
1 parent 9bd1982 commit ff525cd
Show file tree
Hide file tree
Showing 6 changed files with 1,387 additions and 0 deletions.
214 changes: 214 additions & 0 deletions Arduino_sketch/AH_AD9850_Master/AH_AD8950.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@

/***************************************************
** **
** Controller Library for AD9850 Module/Shield **
** **
** Downloaded from: **
** www.arduino-projekte.de **
** **
***************************************************/

#include "AH_AD9850.h"

#include "Arduino.h"


//***************************************************************************

AH_AD9850::AH_AD9850(int CLK, int FQUP, int BitData, int RESET)
{

_CLK = CLK;
_FQUP= FQUP;
_RST= RESET;
_BitData = BitData;

pinMode(_RST, OUTPUT);
pinMode(_FQUP, OUTPUT);
pinMode(_CLK , OUTPUT);
pinMode(_BitData, OUTPUT);

digitalWrite(_RST, LOW);
digitalWrite(_FQUP, LOW);
digitalWrite(_CLK, LOW);
digitalWrite(_BitData, LOW);
}

//***************************************************************************

void AH_AD9850::reset()
{
digitalWrite(_CLK, LOW);
digitalWrite(_FQUP, LOW);

//Reset signal
digitalWrite(_RST, HIGH);

for(int i=0;i<5;i++)
{clock_CLK();}

digitalWrite(_RST, LOW);

for(int i=0;i<2;i++)
{clock_CLK();}

clock_FQUP();
}

//***************************************************************************

void AH_AD9850::set_frequency(boolean PowerDown, byte Phase, double Freq)
{
byte w,w0;
long int y;
double x;

byte ConrolBits = 0x00; //Bxxxxxx00 only allowed bits!!

w0= (Phase & B00011111)<<3 | (PowerDown & 0x01)<<2 | ConrolBits;

//Calculate the frequency of the HEX value
x=4294967295/125; //Suitable for 125M Crystal
Freq=Freq/1000000;
Freq=Freq*x;
y=Freq;

clock_FQUP();

//write w4
w=(y>>=0);
write(w);

//write w3
w=(y>>8);
write(w);

//write w2
w=(y>>16);
write(w);

//write w1
w=(y>>24);
write(w);

//write w0
// w=w0;
write(w0);

clock_FQUP();
}


//***************************************************************************

void AH_AD9850::set_frequency(double Freq)
{
byte w,w0;
long int y;
double x;

w0= 0x00; //Phase=0, PowerDown=LOW, ControlBits=00

x=4294967295/125; //Calculate the frequency of the HEX value, Suitable for 125M Crystal
Freq=Freq/1000000;
Freq=Freq*x;
y=Freq;

clock_FQUP();

w=(y>>=0);
write(w); //write w4

w=(y>>8);
write(w); //write w3

w=(y>>16);
write(w); //write w2

w=(y>>24);
write(w); //write w1

// w=w0;
write(w0); //write w0

clock_FQUP();
}


//***************************************************************************

void AH_AD9850::powerDown()
{
byte w,w0;
w = 0x0;
w0 = B00000100;

clock_FQUP();

//write w4
write(w);

//write w3
write(w);

//write w2
write(w);

//write w1
write(w);

//write w0
write(w0);

clock_FQUP();
}


//****************************************************************************


void AH_AD9850::write(byte word)
{
byte i;
for(i=0; i<8; i++)
{
digitalWrite(_BitData, (word>>i)&0x01);
clock_CLK();
}
}

//***************************************************************************

void AH_AD9850::clock_CLK()
{
digitalWrite(_CLK, HIGH);
digitalWrite(_CLK, LOW);
}

//***************************************************************************

void AH_AD9850::clock_FQUP()
{
digitalWrite(_FQUP, HIGH);
digitalWrite(_FQUP, LOW);
}

//***************************************************************************
void AH_AD9850::operator<<(double frequency)
{
set_frequency(frequency);
}














38 changes: 38 additions & 0 deletions Arduino_sketch/AH_AD9850_Master/AH_AD9850.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

/***************************************************
** **
** Controller Library for AD9850 Module/Shield **
** **
** Downloaded from: **
** www.arduino-projekte.de **
** **
***************************************************/

#ifndef __AH_AD9850_H__
#define __AH_AD9850_H__

#include "Arduino.h"


class AH_AD9850{
public:
AH_AD9850(int CLK, int FQUP, int BitData, int RESET);
void reset();
void set_frequency(boolean PowerDown, byte Phase, double Freq);
void set_frequency(double Freq);
void operator<<(double Freq);
void powerDown();

private:
int _CLK;
int _FQUP;
int _RST;
int _BitData;

void write(byte word);
void clock_CLK();
void clock_FQUP();

};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

/********************************************************
** Downloaded from: **
** http://www.arduino-projekte.de **
********************************************************/

#include <AH_AD9850.h>

//CLK - D6, FQUP - D7, BitData - D8, RESET - D9
//AH_AD9850(int CLK, int FQUP, int BitData, int RESET);
AH_AD9850 AD9850(8,10, 9, 11);

void setup()
{
//reset device
AD9850.reset(); //reset module
delay(1000);
AD9850.powerDown(); //set signal output to LOW

// initialize serial communication
Serial.begin(9600);
}

void loop(){

//set_frequency(boolean PowerDown, byte Phase, double Freq);
//AD9850.set_frequency(0,0,1000); //set power=UP, phase=0, 1kHz frequency
//delay(1000);
double freq;
if (Serial.available()) {
freq=Serial.parseFloat();
while(Serial.available()) Serial.read(); // eat extra characters
Serial.println(freq);
AD9850.set_frequency(freq); //set frequency
}

// AD9850 << 5000; //set 5kHz frequency in C++ style
// delay(1000);




}
5 changes: 5 additions & 0 deletions Arduino_sketch/AH_AD9850_Master/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
AH_AD9850 KEYWORD1

reset KEYWORD2
set_frequency KEYWORD2
powerDown KEYWORD2
Loading

0 comments on commit ff525cd

Please sign in to comment.