//Patrick Jacks //12.1.08 //This program is designed for showing the extra credit project for 3 phase voltage generation at 60hz //timer counters 0 & 1/3 are used // //HARDWARE SETUP //0C0 - PB4 //OC1A - PB5 //OC1B - PB6 //OC1C - PB7 //OC3A - PE3 //OC3B - PE4 //OC3C - PE5 // #define F_CPU 16000000UL //16Mhz clock #define shoot_thru = 1 //Delay factor to prevent shoot thru #include #include #include volatile uint16_t sin_index = 0; const uint16_t sin_lookup[192*3] = {//SINE LOOKUP TABLE 0,0,346, 13,0,353, 26,0,359, 39,0,364, 52,0,370, 65,0,374, 78,0,379, 91,0,383, 104,0,386, 116,0,390, 129,0,392, 141,0,395, 153,0,397, 165,0,398, 177,0,399, 189,0,400, 200,0,400, 211,0,400, 222,0,399, 233,0,398, 244,0,397, 254,0,395, 264,0,392, 273,0,390, 283,0,386, 292,0,383, 301,0,379, 309,0,374, 317,0,370, 325,0,364, 333,0,359, 340,0,353, 346,0,346, 353,0,340, 359,0,333, 364,0,325, 370,0,317, 374,0,309, 379,0,301, 383,0,292, 386,0,283, 390,0,273, 392,0,264, 395,0,254, 397,0,244, 398,0,233, 399,0,222, 400,0,211, 400,0,200, 400,0,189, 399,0,177, 398,0,165, 397,0,153, 395,0,141, 392,0,129, 390,0,116, 386,0,104, 383,0,91, 379,0,78, 374,0,65, 370,0,52, 364,0,39, 359,0,26, 353,0,13, 346,0,0, 353,13,0, 359,26,0, 364,39,0, 370,52,0, 374,65,0, 379,78,0, 383,91,0, 386,104,0, 390,116,0, 392,129,0, 395,141,0, 397,153,0, 398,165,0, 399,177,0, 400,189,0, 400,200,0, 400,211,0, 399,222,0, 398,233,0, 397,244,0, 395,254,0, 392,264,0, 390,273,0, 386,283,0, 383,292,0, 379,301,0, 374,309,0, 370,317,0, 364,325,0, 359,333,0, 353,340,0, 346,346,0, 340,353,0, 333,359,0, 325,364,0, 317,370,0, 309,374,0, 301,379,0, 292,383,0, 283,386,0, 273,390,0, 264,392,0, 254,395,0, 244,397,0, 233,398,0, 222,399,0, 211,400,0, 200,400,0, 189,400,0, 177,399,0, 165,398,0, 153,397,0, 141,395,0, 129,392,0, 116,390,0, 104,386,0, 91,383,0, 78,379,0, 65,374,0, 52,370,0, 39,364,0, 26,359,0, 13,353,0, 0,346,0, 0,353,13, 0,359,26, 0,364,39, 0,370,52, 0,374,65, 0,379,78, 0,383,91, 0,386,104, 0,390,116, 0,392,129, 0,395,141, 0,397,153, 0,398,165, 0,399,177, 0,400,189, 0,400,200, 0,400,211, 0,399,222, 0,398,233, 0,397,244, 0,395,254, 0,392,264, 0,390,273, 0,386,283, 0,383,292, 0,379,301, 0,374,309, 0,370,317, 0,364,325, 0,359,333, 0,353,340, 0,346,346, 0,340,353, 0,333,359, 0,325,364, 0,317,370, 0,309,374, 0,301,379, 0,292,383, 0,283,386, 0,273,390, 0,264,392, 0,254,395, 0,244,397, 0,233,398, 0,222,399, 0,211,400, 0,200,400, 0,189,400, 0,177,399, 0,165,398, 0,153,397, 0,141,395, 0,129,392, 0,116,390, 0,104,386, 0,91,383, 0,78,379, 0,65,374, 0,52,370, 0,39,364, 0,26,359, 0,13,353, }; ISR(TIMER2_COMP_vect){ sin_index += 3; //add three on interrupt sin_index %= 576; //make sure index does not exceed the array OCR1A = sin_lookup[sin_index]; OCR1B = sin_lookup[(sin_index+1)]; OCR1C = sin_lookup[(sin_index+2)]; OCR3A = sin_lookup[sin_index]; OCR3B = sin_lookup[(sin_index+1)]; OCR3C = sin_lookup[(sin_index+2)]; } int main() { //Timer Counter Setup // //Timer/Counter 1 TCCR1A = (1<