/************************ * Willaim Jones * * 525.446 * * Lab 2 source code * * DSP_DDS.c * ************************/ #include "DSK6713_AIC23.h" #include //using printfs for debug #include //used for sin() Uint32 fs=DSK6713_AIC23_FREQ_48KHZ; //set sampling freq to 48 kHz #define DSK6713_AIC23_INPUT_MIC 0x0015 #define DSK6713_AIC23_INPUT_LINE 0x0011 Uint32 inputsource=DSK6713_AIC23_INPUT_LINE; //default input line /******************************************************* Phase increment determined by: (2^N)*f0/f_s where N=32, f_s is sampling freq., and f0 is desired freq. out (rounded to integer) *******************************************************/ #define phase_inc0 9847849 //phase increment for 100 Hz #define phase_inc1 268435456 //phase increment for 3000 Hz #define phase_inc2 39370534 //phase increment for 440 Hz #define phase_inc3 39415273 //phase increment for 330.5 Hz Uint32 phase_acc=4275271597; //register for phase accumulator #define LUT_length 512 //sine LUT size = 2^9 Uint32 LUT_index=0; //index for LUT short sine_LUT[LUT_length]; //sine look-up-table short sine_LUTtest[8]={0,707,1000,707,0,-707,-1000,-707}; //sine look-up-table test short loopindex=0; short gain=10; //gain to codec short temp_sample=0; //temp variable for storing output sample #define pi 3.1415927 main() { // printf("sampling freq = %d\n", f_s); comm_poll(); //init DSK, codec, McBSP DSK6713_LED_init(); //init LEDs from BSL DSK6713_DIP_init(); //init DIPs from BSL while(1) { if(DSK6713_DIP_get(0) == 1 && DSK6713_DIP_get(1) == 1) //neither DIPs are pressed { //freq. out = 100 Hz; phase_acc+=phase_inc0; LUT_index=((phase_acc & 0xFF800000)/(2^(32-9))); //round and bit-shift for LUT index if(DSK6713_DIP_get(3) == 1) //DIP 3 not pressed, use LUT { temp_sample=0; } else //use sine function { output_sample(gain*sine_LUTtest[loopindex++]); if(loopindex>=8) loopindex=0; } // output_left_sample(temp_sample); //set LEDs DSK6713_LED_on(0); DSK6713_LED_off(1); DSK6713_LED_off(2); DSK6713_LED_off(3); } //end if else if(DSK6713_DIP_get(0) == 0 && DSK6713_DIP_get(1) == 1) //DIP 0 pressed { //freq. out = 3000 Hz phase_acc+=phase_inc1; //set LEDs DSK6713_LED_off(0); DSK6713_LED_on(1); DSK6713_LED_off(2); DSK6713_LED_off(3); } //end if else if(DSK6713_DIP_get(0) == 1 && DSK6713_DIP_get(1) == 0) //DIP 1 pressed { //freq. out = 440 Hz phase_acc+=phase_inc2; //set LEDs DSK6713_LED_off(0); DSK6713_LED_off(1); DSK6713_LED_on(2); DSK6713_LED_off(3); } //end if else if(DSK6713_DIP_get(0) == 0 && DSK6713_DIP_get(1) == 0) //DIP 0 and 1 pressed { //freq. out = 440.5 Hz phase_acc+=phase_inc3; //set LEDs DSK6713_LED_off(0); DSK6713_LED_off(1); DSK6713_LED_on(2); DSK6713_LED_off(3); } //end if // output_left_sample(temp_sample); } //end while } //end main