Skip to content

Commit

Permalink
Set Frequency logic implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
chiranthsiddappa committed Apr 18, 2014
1 parent dddd07d commit b2b277f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 48 deletions.
13 changes: 12 additions & 1 deletion AD9912_sketch/AD9912.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
#include <inttypes.h>
#include <SPI.h>

void AD9912::init(uint SPICS, uint SPISCK, uint SPIMOSI, uint SPIMISO, uint IO_update) {
void AD9912::init(uint SPICS, uint SPISCK, uint SPIMOSI, uint SPIMISO, uint IO_update, uint64_t fs) {
_SPICS = SPICS;
_SPISCK = SPISCK;
_SPIMOSI = SPIMOSI;
_SPIMISO = SPIMISO;
_IO_update = IO_update;
_fs = fs;
}

uint16_t AD9912::read_PartID() {
Expand Down Expand Up @@ -79,3 +80,13 @@ uint64_t AD9912::FTW_read() {
void AD9912::FTW_write(uint64_t FTW) {
AD9912::instruction(0x0, 0x1AB, 6, FTW);
}

void AD9912::setFrequency(uint64_t fDDS) {
uint64_t FTW;
FTW = (uint64_t) (281474976710656 * (fDDS / (double) _fs));
AD9912::FTW_write(FTW);
}

void AD9912::updateClkFreq(uint64_t fs) {
_fs = fs;
}
5 changes: 4 additions & 1 deletion AD9912_sketch/AD9912.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,22 @@

class AD9912 {
public:
void init(uint SPICS, uint SPISCK, uint SPIMOSI, uint SPIMISO, uint IO_update );
void init(uint SPICS, uint SPISCK, uint SPIMOSI, uint SPIMISO, uint IO_update, uint64_t clkFreq);
uint16_t read_PartID();
uint64_t instruction(short command, uint16_t address, char bytes, uint64_t data);
uint16_t DAC_read();
void DAC_write(uint16_t DAC_val);
uint64_t FTW_read();
void FTW_write(uint64_t FTW);
void setFrequency(uint64_t frequency);
void updateClkFreq(uint64_t clkFreq);
private:
// global type variables
uint _SPISCK;
uint _SPIMISO;
uint _SPIMOSI;
uint _SPICS;
uint _IO_update;
uint64_t _fs;
};
#endif
49 changes: 3 additions & 46 deletions AD9912_sketch/AD9912_sketch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void setup()
digitalWrite(SPICS, HIGH);
digitalWrite(SPISCK, LOW);
digitalWrite(SPIMOSI, LOW);
ad9912.init(SPICS, SPISCK, SPIMOSI, SPIMISO, IO_update);
ad9912.init(SPICS, SPISCK, SPIMOSI, SPIMISO, IO_update, 1000000000);
//push buttons
pinMode(PUSH2, INPUT_PULLUP);
if(ad9912.read_PartID() == 0x1902)
Expand All @@ -58,8 +58,8 @@ void loop()
{
// put your main code here, to run repeatedly:
if(digitalRead(PUSH2) == LOW) {
delay(150);
ad9912_frequency_sweep();
ad9912.setFrequency(19440000);
//ad9912_frequency_sweep();
}
delay(100);
}
Expand All @@ -80,34 +80,6 @@ void flash_red() {
digitalWrite(RED_LED, LOW);
}

unsigned long long ad9912_read_PartID() {
uint16_t id;
unsigned long long instruction = 0x8003;
digitalWrite(SPICS, HIGH);
pinMode(SPIMOSI, OUTPUT);
digitalWrite(SPICS, LOW);
shiftOut(SPIMOSI, SPISCK, MSBFIRST, instruction >> 8);
shiftOut(SPIMOSI, SPISCK, MSBFIRST, instruction);
digitalWrite(SPIMOSI, LOW);
pinMode(SPIMOSI, INPUT);
id |= shiftIn(SPIMOSI, SPISCK, MSBFIRST) << 8;
digitalWrite(SPICS, HIGH);
delay(0.5);
instruction = 0x8002;
pinMode(SPIMOSI, OUTPUT);
digitalWrite(SPIMOSI, LOW);
digitalWrite(SPICS, LOW);
shiftOut(SPIMOSI, SPISCK, MSBFIRST, instruction >> 8);
shiftOut(SPIMOSI, SPISCK, MSBFIRST, instruction);
digitalWrite(SPIMOSI, LOW);
pinMode(SPIMOSI, INPUT);
id |= shiftIn(SPIMOSI, SPISCK, MSBFIRST);
digitalWrite(SPICS, HIGH);
pinMode(SPIMOSI, OUTPUT);
delay(2);
return id;
}

uint16_t ad9912_DAC_read () {
uint16_t instruction = 0x0;
uint16_t data = 0x0;
Expand Down Expand Up @@ -169,21 +141,6 @@ uint64_t ad9912_FTW_read() {
return FTW;
}

uint64_t ad9912_instruction(short command, uint16_t address, byte bytes, uint64_t data) {
uint16_t instruction = 0x0;
uint64_t return_data;
instruction |= command << 16;
if(bytes > 2) {

}
if(command) {
return return_data;
}
else {
return 0;
}
}

void ad9912_FTW_write(uint64_t FTW) {
uint16_t instruction = 0x0;
instruction |= 0x3 << 13;
Expand Down

0 comments on commit b2b277f

Please sign in to comment.