Arduino DDS Sinewave Generator

AWOL:

Can i generate a 40kHz senoidal signal?.

Do you mean "sinusoidal"?
With that software, no - you'd need to boost the clock to at least 80kHz, and I'm not sure the ISR would run at that frequency.

Do you really need a 40kHz sine wave?

I managed to do it. My current 8bit look up table dds has a 4us interrupt, I have been able to reach 80khz sampling rate but this reaches the limit of the Arduino.
44k is Ok, but without much CPU overhead for somerhing else. Im working on midi synth with 22k rate atm.

EDIT : With this code, I have been able to operate my DIY 8 BIT SPI DAC at a frequency of 330kHz. The output of the DAC was a saw signal (image of the counter...) at 1.35kHz / 256 samples per cycle.
So a 44kHz DDS using a Look up Table is highly feasible indeed.

//Pin connected to ST_CP of 74HC595
int latchPin = 10;
//Pin connected to SH_CP of 74HC595
int clockPin = 13;
////Pin connected to DS of 74HC595
int dataPin = 11;
////
unsigned char test_char=0;

//--- Used to setup SPI based on current pin setup
// this is called in the setup routine;
void setupSPI(){
byte clr;
SPCR |= ( (1<<SPE) | (1<<MSTR) ); // enable SPI as master
SPCR &= ~( (1<<SPR1) | (1<<SPR0) ); // clear prescaler bits
clr=SPSR; // clear SPI status reg
clr=SPDR; // clear SPI data reg
SPSR |= (1<<SPI2X); // set prescaler bits
delay(10);
}

//--- The really fast SPI version of shiftOut
byte spi_transfer(byte data)
{
SPDR = data; // Start the transmission
loop_until_bit_is_set(SPSR, SPIF);
return SPDR; // return the received byte, we don't need that
}

void setup() {
// put your setup code here, to run once:
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
digitalWrite(latchPin, HIGH);
digitalWrite(clockPin, LOW);
digitalWrite(dataPin, LOW);
byte clr;
SPCR |= ( (1<<SPE) | (1<<MSTR) ); // enable SPI as master
SPCR &= ~( (1<<SPR1) | (1<<SPR0) ); // clear prescaler bits
clr=SPSR; // clear SPI status reg
clr=SPDR; // clear SPI data reg
SPSR |= (1<<SPI2X); // set prescaler bits
delay(10);
Serial.begin(9600);
Serial.println("Init Ok");
}

void loop() {
// put your main code here, to run repeatedly:
//shiftOut(dataPin, clockPin, MSBFIRST, test_char);
spi_transfer(test_char);
PORTB &= ~(4); //digitalWrite(latchPin, LOW);
//Serial.println(test_char,DEC);
PORTB |= 4; //digitalWrite(latchPin, HIGH);
//delay(1000);
test_char += 1;
//delay(1000);
}