Thank you very much for the response.!!
Well, I am trying to go on with the SPI Library.
This is my code so far but it doesn't output any frequency
pins connected as:
from ICSP
MOSI == Serial Data
SCK == W_CLK
RESET == RESET
D2 = FQ_UD (used digitalWrite at first to see if it is working)
#include <SPI.h>
#define TIMECTL_MAXTICKS 4294967295
#define DDS_CLOCK 125000000
// Define ADC prescaler
const unsigned char PS_16 = (1 << ADPS2);
const unsigned char PS_32 = (1 << ADPS2) | (1 << ADPS0);
const unsigned char PS_64 = (1 << ADPS2) | (1 << ADPS1);
const unsigned char PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);
long int tword; //the tuning word for the module
long int freq = 0; //a value for frequency
int mic = 0; //a valur for the input signal to use for modulation
void setup(){
SPI.begin();
SPI.setDataMode(SPI_MODE1);
pinMode (2,OUTPUT);
pinMode (A0,INPUT); //here comes the audio frequency in
// set up the ADC
ADCSRA &= ~PS_128; // remove bits set by Arduino library
ADCSRA |= PS_32; // setting the ADC sampling frequency to 16mHz/32
}
void loop(){
//---------This has to be inside an interrupt to keep the audio sampling rate constant-----------
mic = analogRead(A0); // this analog read takes about 20?s to complete
if (mic<512) //the microphone preamplifier bias is set with offset for ~2.5V idle output
{freq = 27115000+70*mic;}
else //this can frequency modulate our carrier at about 35khz back and forth
{freq = 27115000-70*mic;}
//----------------------------------------------------------------------------------------------
//freq = 27115000;
tword = (freq * TIMECTL_MAXTICKS) / DDS_CLOCK; //tuning word calculation
digitalWrite(2,LOW); //fq_ud low
SPI.setBitOrder(LSBFIRST);
SPI.transfer(tword);
SPI.transfer(tword >> 8);
SPI.transfer(tword >> 16);
SPI.transfer(tword >> 24);
SPI.transfer(0x00);
digitalWrite(2,HIGH);
}
What I was using for simple serial communication before, was this function:
void SetFrequency(unsigned long frequency)
{
unsigned long tuning_word = (frequency * pow(2, 32)) / DDS_CLOCK;
digitalWrite (LOAD, LOW);
shiftOut(DATA, CLOCK, LSBFIRST, tuning_word);
shiftOut(DATA, CLOCK, LSBFIRST, tuning_word >> 8);
shiftOut(DATA, CLOCK, LSBFIRST, tuning_word >> 16);
shiftOut(DATA, CLOCK, LSBFIRST, tuning_word >> 24);
shiftOut(DATA, CLOCK, LSBFIRST, 0x00);
digitalWrite (LOAD, HIGH);
}
Is my code right?? I doubt that I send the tuning word correctly...
AD9850 datasheet: http://www.analog.com/static/imported-files/data_sheets/AD9850.pdf