//More info http://zissisprojects.wordpress.com/arduino-sdr-ad9850 #include uint32_t frequency = 694000; //The desired frequency must be divided by 50 ex. 34,7MHz/50 = 694000 uint32_t tword = frequency * 3436 / 100; //tuning word calculation byte W[5] = {0,0,0,0,0}; const unsigned char PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); //these are the prescalers for the ADC sampling rate. const unsigned char PS_32 = (1 << ADPS2) | (1 << ADPS0); const unsigned char PS_16 = (1 << ADPS2); int mic = 512; void setup() { DDRB = B01100000; //portb has outputs, PB5(may be used for reset) PB6(FU_UD pin) PORTB = 0x00; // Serial.begin(115200); // everything can be controlled by serial comm pinMode (A0,INPUT); // here comes the audio frequency in SPI.setDataMode(SPI_MODE0); // mode 0 seems to be the right one SPI.setClockDivider(SPI_CLOCK_DIV2); // this is pretty fast SPI.setBitOrder(LSBFIRST); // AD9850 wants LSB first SPI.begin(); // set up the ADC ADCSRA &= ~PS_128; // remove bits set by Arduino library ADCSRA |= PS_32; // setting the sampling rate at 16MHz/32 this makes the analogRead() complete in around 40μs } void loop() { mic = analogRead(A0); //reading the AF signal frequency = 694000 + 3*mic-1536; //this is the Frequency Modulation. Desired frequency is divided by 50 and then around 75khz deviation is calculated depending on the input amplitude tword = frequency * 1718; //calculating the tuning word for AD9850 W[0] = (byte) tword; W[1] = (byte) (tword >> 8); W[2] = (byte) (tword >> 16); //converting it to bytes W[3] = (byte) (tword >> 24); W[4] = 0; //phase zero //start sending with spi interface PORTB = B01000000; PORTB = 0x00; //pulse FU_UD for (int j = 0; j<5;j++) { SPI.transfer(W[j]); //send the word } PORTB = B01000000; PORTB = 0x00; //pulse FU_UD }