// DDS output thru PWM on timer0 OC0A (pin B.3) // Mega644 version // Produces a 15 mSec sine wave burst every 50 mSec. #include #include #include #include // for sine //I like these definitions #define begin { #define end } #define countMS 62 //ticks/mSec // The DDS variables volatile unsigned long accumulator ; unsigned char highbyte ; unsigned long increment; char sineTable[256] ; // Time variables // the volitile is needed because the time is only set in the ISR volatile unsigned int time ; char count; // index for sine table build unsigned int i; ISR (TIMER0_OVF_vect) begin //the actual DDR accumulator = accumulator + increment ; highbyte = accumulator >> 24 ; OCR0A = 128 + sineTable[highbyte] ; // generate time base for MAIN // 62 counts is about 1 mSec count--; if (0 == count ) begin count=countMS; time++; //in mSec end end int main(void) begin // make B.3 an output DDRB = (1<