/* * xp_write_xpwm_time.c * * Created on: 03 àïð. 2018 ã. * Author: stud */ #include "xp_write_xpwm_time.h" // #include "MemoryFunctions.h" // #include "Spartan2E_Adr.h" // #include "PWMTMSHandle.h" #include "def.h" // #pragma DATA_SECTION(xpwm_time,".fast_vars1"); XPWM_TIME xpwm_time = DEFAULT_XPWM_TIME; #define set_default_tclosed(k,b) {if (b) k = p->Tclosed_saw_direct_1; else k = p->Tclosed_saw_direct_0;} void initXpwmTimeStructure(XPWM_TIME *p) { p->Ta0_0 = p->Tclosed_0; p->Ta0_1 = p->Tclosed_1; p->Tb0_0 = p->Tclosed_0; p->Tb0_1 = p->Tclosed_1; p->Tc0_0 = p->Tclosed_0; p->Tc0_1 = p->Tclosed_1; p->Ta1_0 = p->Tclosed_0; p->Ta1_1 = p->Tclosed_1; p->Tb1_0 = p->Tclosed_0; p->Tb1_1 = p->Tclosed_1; p->Tc1_0 = p->Tclosed_0; p->Tc1_1 = p->Tclosed_1; p->Tbr0_0 = 0; p->Tbr0_1 = 0; p->Tbr1_0 = 0; p->Tbr1_1 = 0; } // Ôóíêöèè çàãëóøêè ÷òîáû êîìïèëèðîâàëîñü â ìàòëàáå void xpwm_write_1_2_winding_break_times_16_lines(XPWM_TIME *p) { } // void xpwm_write_1_2_winding_break_times_16_lines_split_eages(XPWM_TIME *p) { // } /* //#pragma CODE_SECTION(xpwm_write_1_2_winding_break_times_16_lines,".fast_run1"); void xpwm_write_1_2_winding_break_times_16_lines(XPWM_TIME *p) { if(!(ReadMemory(ADR_ERRORS_TOTAL_INFO))) { WriteMemory(ADR_PWM_KEY_NUMBER, 0); WriteMemory(ADR_PWM_TIMING, p->Ta0_0); WriteMemory(ADR_PWM_KEY_NUMBER, 1); WriteMemory(ADR_PWM_TIMING, p->Ta0_1); WriteMemory(ADR_PWM_KEY_NUMBER, 2); WriteMemory(ADR_PWM_TIMING, p->Tb0_0); WriteMemory(ADR_PWM_KEY_NUMBER, 3); WriteMemory(ADR_PWM_TIMING, p->Tb0_1); WriteMemory(ADR_PWM_KEY_NUMBER, 4); WriteMemory(ADR_PWM_TIMING, p->Tc0_0); WriteMemory(ADR_PWM_KEY_NUMBER, 5); WriteMemory(ADR_PWM_TIMING, p->Tc0_1); WriteMemory(ADR_PWM_KEY_NUMBER, 6); WriteMemory(ADR_PWM_TIMING, p->Ta1_0); WriteMemory(ADR_PWM_KEY_NUMBER, 7); WriteMemory(ADR_PWM_TIMING, p->Ta1_1); WriteMemory(ADR_PWM_KEY_NUMBER, 8); WriteMemory(ADR_PWM_TIMING, p->Tb1_0); WriteMemory(ADR_PWM_KEY_NUMBER, 9); WriteMemory(ADR_PWM_TIMING, p->Tb1_1); WriteMemory(ADR_PWM_KEY_NUMBER, 10); WriteMemory(ADR_PWM_TIMING, p->Tc1_0); WriteMemory(ADR_PWM_KEY_NUMBER, 11); WriteMemory(ADR_PWM_TIMING, p->Tc1_1); WriteMemory(ADR_PWM_KEY_NUMBER, 12); WriteMemory(ADR_PWM_TIMING, p->Tbr0_0); WriteMemory(ADR_PWM_KEY_NUMBER, 13); WriteMemory(ADR_PWM_TIMING, p->Tbr0_1); WriteMemory(ADR_PWM_KEY_NUMBER, 14); WriteMemory(ADR_PWM_TIMING, p->Tbr1_0); WriteMemory(ADR_PWM_KEY_NUMBER, 15); WriteMemory(ADR_PWM_TIMING, p->Tbr1_1); } else { WriteMemory(ADR_PWM_KEY_NUMBER, 0); WriteMemory(ADR_PWM_TIMING, p->Tclosed_0); WriteMemory(ADR_PWM_KEY_NUMBER, 1); WriteMemory(ADR_PWM_TIMING, p->Tclosed_1); WriteMemory(ADR_PWM_KEY_NUMBER, 2); WriteMemory(ADR_PWM_TIMING, p->Tclosed_0); WriteMemory(ADR_PWM_KEY_NUMBER, 3); WriteMemory(ADR_PWM_TIMING, p->Tclosed_1); WriteMemory(ADR_PWM_KEY_NUMBER, 4); WriteMemory(ADR_PWM_TIMING, p->Tclosed_0); WriteMemory(ADR_PWM_KEY_NUMBER, 5); WriteMemory(ADR_PWM_TIMING, p->Tclosed_1); WriteMemory(ADR_PWM_KEY_NUMBER, 6); WriteMemory(ADR_PWM_TIMING, p->Tclosed_0); WriteMemory(ADR_PWM_KEY_NUMBER, 7); WriteMemory(ADR_PWM_TIMING, p->Tclosed_1); WriteMemory(ADR_PWM_KEY_NUMBER, 8); WriteMemory(ADR_PWM_TIMING, p->Tclosed_0); WriteMemory(ADR_PWM_KEY_NUMBER, 9); WriteMemory(ADR_PWM_TIMING, p->Tclosed_1); WriteMemory(ADR_PWM_KEY_NUMBER, 10); WriteMemory(ADR_PWM_TIMING, p->Tclosed_0); WriteMemory(ADR_PWM_KEY_NUMBER, 11); WriteMemory(ADR_PWM_TIMING, p->Tclosed_1); WriteMemory(ADR_PWM_KEY_NUMBER, 12); WriteMemory(ADR_PWM_TIMING, 0); WriteMemory(ADR_PWM_KEY_NUMBER, 13); WriteMemory(ADR_PWM_TIMING, 0); WriteMemory(ADR_PWM_KEY_NUMBER, 14); WriteMemory(ADR_PWM_TIMING, 0); WriteMemory(ADR_PWM_KEY_NUMBER, 15); WriteMemory(ADR_PWM_TIMING, 0); } } */ // #pragma CODE_SECTION(xpwm_write_1_2_winding_break_times_16_lines_split_eages,".fast_run1"); void xpwm_write_1_2_winding_break_times_16_lines_split_eages(XPWM_TIME *p) { // if (!(i_ReadMemory(ADR_ERRORS_TOTAL_INFO))) { //a if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) || (p->saw_direct.bits.bit0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) || (p->saw_direct.bits.bit0==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) { // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A1_PLUS); // i_WriteMemory(ADR_PWM_TIMING, p->Ta0_0); EPwm2Regs.CMPA.half.CMPA = p->Ta0_0; } if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) || (p->saw_direct.bits.bit1 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) || (p->saw_direct.bits.bit1==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) { // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A1_MINUS); // i_WriteMemory(ADR_PWM_TIMING, p->Ta0_1); EPwm1Regs.CMPA.half.CMPA = p->Ta0_1; } if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) || (p->saw_direct.bits.bit2 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) || (p->saw_direct.bits.bit2==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) { // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B1_PLUS); // i_WriteMemory(ADR_PWM_TIMING, p->Tb0_0); EPwm4Regs.CMPA.half.CMPA = p->Tb0_0; } if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) || (p->saw_direct.bits.bit3 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) || (p->saw_direct.bits.bit3==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) { // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B1_MINUS); // i_WriteMemory(ADR_PWM_TIMING, p->Tb0_1); EPwm3Regs.CMPA.half.CMPA = p->Tb0_1; } if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) || (p->saw_direct.bits.bit4 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) || (p->saw_direct.bits.bit4==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) { // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C1_PLUS); // i_WriteMemory(ADR_PWM_TIMING, p->Tc0_0); EPwm6Regs.CMPA.half.CMPA = p->Tc0_0; } if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) || (p->saw_direct.bits.bit5 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) || (p->saw_direct.bits.bit5==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) { // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C1_MINUS); // i_WriteMemory(ADR_PWM_TIMING, p->Tc0_1); EPwm5Regs.CMPA.half.CMPA = p->Tc0_1; } //b if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) || (p->saw_direct.bits.bit6 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) || (p->saw_direct.bits.bit6==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) { // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A2_PLUS); // i_WriteMemory(ADR_PWM_TIMING, p->Ta1_0); EPwm8Regs.CMPA.half.CMPA = p->Ta1_0; } if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) || (p->saw_direct.bits.bit7 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) || (p->saw_direct.bits.bit7==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) { // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A2_MINUS); // i_WriteMemory(ADR_PWM_TIMING, p->Ta1_1); EPwm7Regs.CMPA.half.CMPA = p->Ta1_1; } if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) || (p->saw_direct.bits.bit8 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) || (p->saw_direct.bits.bit8==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) { // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B2_PLUS); // i_WriteMemory(ADR_PWM_TIMING, p->Tb1_0); EPwm10Regs.CMPA.half.CMPA = p->Tb1_0; } if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) || (p->saw_direct.bits.bit9 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) || (p->saw_direct.bits.bit9==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) { // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B2_MINUS); // i_WriteMemory(ADR_PWM_TIMING, p->Tb1_1); EPwm9Regs.CMPA.half.CMPA = p->Tb1_1; } if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) || (p->saw_direct.bits.bit10 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) || (p->saw_direct.bits.bit10==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) { // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C2_PLUS); // i_WriteMemory(ADR_PWM_TIMING, p->Tc1_0); EPwm12Regs.CMPA.half.CMPA = p->Tc1_0; } if ((p->mode_reload==PWM_MODE_RELOAD_FORCE) || (p->saw_direct.bits.bit11 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH) || (p->saw_direct.bits.bit11==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) ) { // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C2_MINUS); // i_WriteMemory(ADR_PWM_TIMING, p->Tc1_1); EPwm11Regs.CMPA.half.CMPA = p->Tc1_1; } //br1 br2 // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR1_PLUS); // i_WriteMemory(ADR_PWM_TIMING, p->Tbr0_0); // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR1_MINUS); // i_WriteMemory(ADR_PWM_TIMING, p->Tbr0_1); // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR2_PLUS); // i_WriteMemory(ADR_PWM_TIMING, p->Tbr1_0); // i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR2_MINUS); // i_WriteMemory(ADR_PWM_TIMING, p->Tbr1_1); } // else // { // // hard_stop_x24_pwm_all(); // // stop_pwm(); // xpwm_write_zero_winding_break_times_16_lines_split_eages(p); // } } /* // #pragma CODE_SECTION(xpwm_write_zero_1,".fast_run2"); void xpwm_write_zero_1(XPWM_TIME *p) { unsigned int tclose; //a set_default_tclosed(tclose, p->saw_direct.bits.bit0); i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A1_PLUS); i_WriteMemory(ADR_PWM_TIMING, tclose); p->Ta0_0 = tclose; set_default_tclosed(tclose, p->saw_direct.bits.bit1); i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A1_MINUS); i_WriteMemory(ADR_PWM_TIMING, tclose); p->Ta0_1 = tclose; set_default_tclosed(tclose, p->saw_direct.bits.bit2); i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B1_PLUS); i_WriteMemory(ADR_PWM_TIMING, tclose); p->Tb0_0 = tclose; set_default_tclosed(tclose, p->saw_direct.bits.bit3); i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B1_MINUS); i_WriteMemory(ADR_PWM_TIMING, tclose); p->Tb0_1 = tclose; set_default_tclosed(tclose, p->saw_direct.bits.bit4); i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C1_PLUS); i_WriteMemory(ADR_PWM_TIMING, tclose); p->Tc0_0 = tclose; set_default_tclosed(tclose, p->saw_direct.bits.bit5); i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C1_MINUS); i_WriteMemory(ADR_PWM_TIMING, tclose); p->Tc0_1 = tclose; } // #pragma CODE_SECTION(xpwm_write_zero_2,".fast_run1"); void xpwm_write_zero_2(XPWM_TIME *p) { unsigned int tclose; //b set_default_tclosed(tclose, p->saw_direct.bits.bit6); i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A2_PLUS); i_WriteMemory(ADR_PWM_TIMING, tclose); p->Ta1_0 = tclose; set_default_tclosed(tclose, p->saw_direct.bits.bit7); i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A2_MINUS); i_WriteMemory(ADR_PWM_TIMING, tclose); p->Ta1_1 = tclose; set_default_tclosed(tclose, p->saw_direct.bits.bit8); i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B2_PLUS); i_WriteMemory(ADR_PWM_TIMING, tclose); p->Tb1_0 = tclose; set_default_tclosed(tclose, p->saw_direct.bits.bit9); i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B2_MINUS); i_WriteMemory(ADR_PWM_TIMING, tclose); p->Tb1_1 = tclose; set_default_tclosed(tclose, p->saw_direct.bits.bit10); i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C2_PLUS); i_WriteMemory(ADR_PWM_TIMING, tclose); p->Tc1_0 = tclose; set_default_tclosed(tclose, p->saw_direct.bits.bit11); i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C2_MINUS); i_WriteMemory(ADR_PWM_TIMING, tclose); p->Tc1_1 = tclose; } // #pragma CODE_SECTION(xpwm_write_zero_break_1,".fast_run2"); void xpwm_write_zero_break_1(XPWM_TIME *p) { i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR1_PLUS); i_WriteMemory(ADR_PWM_TIMING, 0); i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR1_MINUS); i_WriteMemory(ADR_PWM_TIMING, 0); p->Tbr0_0 = 0; p->Tbr0_1 = 0; } // #pragma CODE_SECTION(xpwm_write_zero_break_2,".fast_run2"); void xpwm_write_zero_break_2(XPWM_TIME *p) { i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR2_PLUS); i_WriteMemory(ADR_PWM_TIMING, 0); i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR2_MINUS); i_WriteMemory(ADR_PWM_TIMING, 0); p->Tbr1_0 = 0; p->Tbr1_1 = 0; } // #pragma CODE_SECTION(xpwm_write_zero_winding_break_times_16_lines_split_eages,".fast_run2"); void xpwm_write_zero_winding_break_times_16_lines_split_eages(XPWM_TIME *p) { xpwm_write_zero_1(p); xpwm_write_zero_2(p); xpwm_write_zero_break_1(p); xpwm_write_zero_break_2(p); } */