diff --git a/Projects/epwm_test_biss_c_cpu1/.cproject b/Projects/epwm_test_biss_c_cpu1/.cproject index e5223fd..3d17497 100644 --- a/Projects/epwm_test_biss_c_cpu1/.cproject +++ b/Projects/epwm_test_biss_c_cpu1/.cproject @@ -15,7 +15,7 @@ - + - @@ -104,11 +104,11 @@ - diff --git a/Projects/epwm_test_biss_c_cpu1/2838x_FLASH_lnk_cpu1.cmd b/Projects/epwm_test_biss_c_cpu1/2838x_FLASH_lnk_cpu1.cmd index 2f4652e..df0dac5 100644 --- a/Projects/epwm_test_biss_c_cpu1/2838x_FLASH_lnk_cpu1.cmd +++ b/Projects/epwm_test_biss_c_cpu1/2838x_FLASH_lnk_cpu1.cmd @@ -36,12 +36,12 @@ MEMORY // RAMGS15_RSVD : origin = 0x01CFF8, length = 0x000008 /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */ /* Flash sectors */ - FLASH0 : origin = 0x080002, length = 0x001FFE /* on-chip Flash */ - FLASH1 : origin = 0x082000, length = 0x002000 /* on-chip Flash */ - FLASH2 : origin = 0x084000, length = 0x002000 /* on-chip Flash */ - FLASH3 : origin = 0x086000, length = 0x002000 /* on-chip Flash */ - FLASH4 : origin = 0x088000, length = 0x008000 /* on-chip Flash */ - FLASH5 : origin = 0x090000, length = 0x008000 /* on-chip Flash */ + FLASH0 : origin = 0x080002, length = 0x001FFE, fill=0x0000 /* on-chip Flash */ + FLASH1 : origin = 0x082000, length = 0x002000, fill=0x0000 /* on-chip Flash */ + FLASH2 : origin = 0x084000, length = 0x002000, fill=0x0000 /* on-chip Flash */ + FLASH3 : origin = 0x086000, length = 0x002000, fill=0x0000 /* on-chip Flash */ + FLASH4 : origin = 0x088000, length = 0x008000, fill=0x0000 /* on-chip Flash */ + FLASH5 : origin = 0x090000, length = 0x008000, fill=0x0000 /* on-chip Flash */ FLASH6 : origin = 0x098000, length = 0x008000 /* on-chip Flash */ FLASH7 : origin = 0x0A0000, length = 0x008000 /* on-chip Flash */ FLASH8 : origin = 0x0A8000, length = 0x008000 /* on-chip Flash */ diff --git a/Projects/epwm_test_biss_c_cpu1/src/Peripherals/gpio_init.c b/Projects/epwm_test_biss_c_cpu1/src/Peripherals/gpio_init.c index 63c9c42..e5ddb09 100644 --- a/Projects/epwm_test_biss_c_cpu1/src/Peripherals/gpio_init.c +++ b/Projects/epwm_test_biss_c_cpu1/src/Peripherals/gpio_init.c @@ -92,6 +92,15 @@ void GpioInit(void) InputXbarRegs.INPUT4SELECT = GPIO_FaultPWMpin;//xint1 + GpioCtrlRegs.GPIO_Bttonclik_MUX.bit.GPIO_Bttonclik = 0;//Buttons Clik + GpioCtrlRegs.GPIO_Bttonclik_GMUX.bit.GPIO_Bttonclik = 0; + GpioCtrlRegs.GPIO_Bttonclik_DIR.bit.GPIO_Bttonclik = 0; + GpioDataRegs.GPIO_Bttonclik_DAT.bit.GPIO_Bttonclik = 0; + GpioCtrlRegs.GPIO_Bttonclik_SEL.bit.GPIO_Bttonclik = 2; + + InputXbarRegs.INPUT6SELECT = GPIO_Bttonclikpin;//xint3 + + GpioCtrlRegs.GPAMUX2.bit.GPIO20 = 1;//EQEP GpioCtrlRegs.GPAGMUX2.bit.GPIO20 = 0; GpioCtrlRegs.GPADIR.bit.GPIO20 = 0; @@ -122,9 +131,9 @@ void GpioInit(void) GpioCtrlRegs.GPDCSEL1.bit.GPIO103 = 2; #else GpioCtrlRegs.GPAMUX2.bit.GPIO21 = 0; - GpioCtrlRegs.GPAGMUX2.bit.GPIO21 = 0; + GpioCtrlRegs.GPAGMUX2.bit.GPIO21 = 0;//питание датчика bissc GpioCtrlRegs.GPADIR.bit.GPIO21 = 1; - GpioDataRegs.GPADAT.bit.GPIO21 = 1;//BISS-C_PWR_EN + GpioDataRegs.GPADAT.bit.GPIO21 = 0;//BISS-C_PWR_EN GpioCtrlRegs.GPACSEL3.bit.GPIO21 = 2; GpioCtrlRegs.GPDMUX1.bit.GPIO98 = 0; diff --git a/Projects/epwm_test_biss_c_cpu1/src/config.h b/Projects/epwm_test_biss_c_cpu1/src/config.h index 5fc602e..8b58ddb 100644 --- a/Projects/epwm_test_biss_c_cpu1/src/config.h +++ b/Projects/epwm_test_biss_c_cpu1/src/config.h @@ -37,6 +37,14 @@ #define GPIO_FaultPWM_MUX GPDMUX1 #define GPIO_FaultPWMpin 99 +#define GPIO_Bttonclik GPIO83 +#define GPIO_Bttonclik_SEL GPCCSEL3 +#define GPIO_Bttonclik_DIR GPCODR +#define GPIO_Bttonclik_DAT GPCDAT +#define GPIO_Bttonclik_GMUX GPCGMUX2 +#define GPIO_Bttonclik_MUX GPCMUX2 +#define GPIO_Bttonclikpin 83 + #define GPIO_RS485_DE 133 #define GPIO_RS485_RE 145 diff --git a/Projects/epwm_test_biss_c_cpu1/src/vector.c b/Projects/epwm_test_biss_c_cpu1/src/vector.c index 5d43f58..f2557e5 100644 --- a/Projects/epwm_test_biss_c_cpu1/src/vector.c +++ b/Projects/epwm_test_biss_c_cpu1/src/vector.c @@ -136,7 +136,6 @@ void vectorControl(int16_t CurrentA, int16_t CurrentB, int16_t CurrentC, int16_t BissStartSet(); FMSTREnableSet(); AdcStartSet(); - } void vectorInitCurrLoop(void) diff --git a/Projects/epwm_test_biss_c_cpu1/src/vector.h b/Projects/epwm_test_biss_c_cpu1/src/vector.h index 09bf202..3660a6a 100644 --- a/Projects/epwm_test_biss_c_cpu1/src/vector.h +++ b/Projects/epwm_test_biss_c_cpu1/src/vector.h @@ -1,7 +1,7 @@ /* * vector.h * - * Created on: 20 . 2023 . + * Created on: 20 ����. 2023 �. * Author: seklyuts */ @@ -76,7 +76,7 @@ typedef struct typedef enum { - OffMode, // + OffMode, //����� ���������� StepMode, // StayMode, CurrentRegTune, @@ -95,6 +95,7 @@ void vectorControl(int16_t CurrentA, int16_t CurrentB, int16_t CurrentC, int16_t void vectorFault(void); float my_sqrtf(float x); void vectorResCurrLoop(void); +void vectorRegKoeffRecalc(float Koeff); #endif /* SRC_VECTOR_H_ */ diff --git a/Projects/epwm_test_biss_c_cpu1/targetConfigs/TMS320F28388D.ccxml b/Projects/epwm_test_biss_c_cpu1/targetConfigs/TMS320F28388D.ccxml index 09ed29e..09ae94d 100644 --- a/Projects/epwm_test_biss_c_cpu1/targetConfigs/TMS320F28388D.ccxml +++ b/Projects/epwm_test_biss_c_cpu1/targetConfigs/TMS320F28388D.ccxml @@ -1,7 +1,6 @@ - - + diff --git a/Projects/epwm_test_biss_c_cpu2/.cproject b/Projects/epwm_test_biss_c_cpu2/.cproject index 25b0cf8..9a8e455 100644 --- a/Projects/epwm_test_biss_c_cpu2/.cproject +++ b/Projects/epwm_test_biss_c_cpu2/.cproject @@ -15,7 +15,7 @@ - + diff --git a/Projects/epwm_test_biss_c_cpu2/2838x_FLASH_lnk_cpu2.cmd b/Projects/epwm_test_biss_c_cpu2/2838x_FLASH_lnk_cpu2.cmd index ca191c3..dcb8b51 100644 --- a/Projects/epwm_test_biss_c_cpu2/2838x_FLASH_lnk_cpu2.cmd +++ b/Projects/epwm_test_biss_c_cpu2/2838x_FLASH_lnk_cpu2.cmd @@ -36,13 +36,13 @@ MEMORY // RAMGS15_RSVD : origin = 0x01CFF8, length = 0x000008 /* Reserve and do not use for code as per the errata advisory "Memory: Prefetching Beyond Valid Memory" */ /* Flash sectors */ - FLASH0 : origin = 0x080002, length = 0x001FFE /* on-chip Flash */ - FLASH1 : origin = 0x082000, length = 0x002000 /* on-chip Flash */ - FLASH2 : origin = 0x084000, length = 0x002000 /* on-chip Flash */ - FLASH3 : origin = 0x086000, length = 0x002000 /* on-chip Flash */ - FLASH4 : origin = 0x088000, length = 0x008000 /* on-chip Flash */ - FLASH5 : origin = 0x090000, length = 0x008000 /* on-chip Flash */ - FLASH6 : origin = 0x098000, length = 0x008000 /* on-chip Flash */ + FLASH0 : origin = 0x080002, length = 0x001FFE, fill=0x0000 /* on-chip Flash */ + FLASH1 : origin = 0x082000, length = 0x002000, fill=0x0000 /* on-chip Flash */ + FLASH2 : origin = 0x084000, length = 0x002000, fill=0x0000 /* on-chip Flash */ + FLASH3 : origin = 0x086000, length = 0x002000, fill=0x0000 /* on-chip Flash */ + FLASH4 : origin = 0x088000, length = 0x008000, fill=0x0000 /* on-chip Flash */ + FLASH5 : origin = 0x090000, length = 0x008000, fill=0x0000 /* on-chip Flash */ + FLASH6 : origin = 0x098000, length = 0x008000, fill=0x0000 /* on-chip Flash */ FLASH7 : origin = 0x0A0000, length = 0x008000 /* on-chip Flash */ FLASH8 : origin = 0x0A8000, length = 0x008000 /* on-chip Flash */ FLASH9 : origin = 0x0B0000, length = 0x008000 /* on-chip Flash */ @@ -74,7 +74,7 @@ SECTIONS #if defined(__TI_EABI__) .init_array : > FLASH1, ALIGN(8) - .bss : > RAMLS5 // instead of RAMLS5 + .bss : >> RAMLS5 | RAMLS6 // instead of RAMLS5 .bss:output : > RAMLS3 .bss:cio : > RAMLS5 .data : > RAMLS5 @@ -92,7 +92,7 @@ SECTIONS ramgs0 : > RAMGS0, type=NOINIT ramgs1 : > RAMGS1, type=NOINIT - + MSGRAM_CPU1_TO_CPU2 : > CPU1TOCPU2RAM, type=NOINIT MSGRAM_CPU2_TO_CPU1 : > CPU2TOCPU1RAM, type=NOINIT MSGRAM_CPU_TO_CM : > CPUTOCMRAM, type=NOINIT @@ -100,11 +100,13 @@ SECTIONS /* The following section definition are for SDFM examples */ Filter_RegsFile : > RAMGS10 - Filter1_RegsFile : > RAMLS1, fill=0x1111 - Filter2_RegsFile : > RAMLS2, fill=0x2222 - Filter3_RegsFile : > RAMLS3, fill=0x3333 - Filter4_RegsFile : > RAMLS4, fill=0x4444 - Difference_RegsFile : >RAMGS5, fill=0x3333 + Filter1_RegsFile : > RAMLS1 + Filter2_RegsFile : > RAMLS2 + Filter3_RegsFile : > RAMLS3 + Filter4_RegsFile : > RAMLS4 + Filter6_RegsFile : > RAMLS6 + Filter14_RegsFile : > RAMGS14 + Difference_RegsFile : >RAMGS5 #if defined(__TI_EABI__) .TI.ramfunc : {} LOAD = FLASH3, diff --git a/Projects/epwm_test_biss_c_cpu2/Freemaster/PE_freemaster_56F8xxx.c b/Projects/epwm_test_biss_c_cpu2/Freemaster/PE_freemaster_56F8xxx.c index 66d1246..06a2724 100644 --- a/Projects/epwm_test_biss_c_cpu2/Freemaster/PE_freemaster_56F8xxx.c +++ b/Projects/epwm_test_biss_c_cpu2/Freemaster/PE_freemaster_56F8xxx.c @@ -120,7 +120,7 @@ FMSTR_BPTR FMSTR_CopyToBuffer(FMSTR_BPTR pDestBuff, FMSTR_ADDR nSrcAddr, FMSTR_S while(nSize--) { *pd++ = *ps; - *pd++ = (*ps++) >> 8; //*pd++ = *ps++; + *pd++ = (*ps++) >> 8; //*pd++ = *ps++;изменения для TI } return (FMSTR_BPTR) pd; } @@ -158,7 +158,7 @@ FMSTR_BPTR FMSTR_CopyFromBuffer(FMSTR_ADDR nDestAddr, FMSTR_BPTR pSrcBuff, FMSTR while(nSize--) { *pd = *ps++; - *pd++ += (*ps++)<<8; // *pd++ = *ps++; + *pd++ += (*ps++)<<8; // *pd++ = *ps++; изменения для TI } return (FMSTR_BPTR) ps; } diff --git a/Projects/epwm_test_biss_c_cpu2/Freemaster/PE_freemaster_rec.c b/Projects/epwm_test_biss_c_cpu2/Freemaster/PE_freemaster_rec.c index d7c5302..c8a9d2a 100644 --- a/Projects/epwm_test_biss_c_cpu2/Freemaster/PE_freemaster_rec.c +++ b/Projects/epwm_test_biss_c_cpu2/Freemaster/PE_freemaster_rec.c @@ -185,7 +185,7 @@ FMSTR_BPTR FMSTR_SetUpRec(FMSTR_BPTR pMessageIO) #else /* size in native sizeof units (=bytes on most platforms) */ pcm_wRecBuffSize = (FMSTR_SIZE)FMSTR_REC_BUFF_SIZE; - FMSTR_ARR2ADDR(pcm_nRecBuffAddr, pcm_pOwnRecBuffer); // + FMSTR_ARR2ADDR(pcm_nRecBuffAddr, pcm_pOwnRecBuffer); // заполнение буфера #endif /* seek the setup data */ @@ -629,7 +629,7 @@ static void FMSTR_Recorder2(void) for (i=0U; iTZCTL.bit.TZA = 3; EPwmRegs[Num]->TZCTL.bit.TZB = 3; EPwmRegs[Num]->TZFRC.all = 4; - EDIS; // + EDIS; //Программно выставляем TZ-событие // // Set actions // diff --git a/Projects/epwm_test_biss_c_cpu2/src/Peripherals/pwm_init.h b/Projects/epwm_test_biss_c_cpu2/src/Peripherals/pwm_init.h index c299823..20a9cd7 100644 --- a/Projects/epwm_test_biss_c_cpu2/src/Peripherals/pwm_init.h +++ b/Projects/epwm_test_biss_c_cpu2/src/Peripherals/pwm_init.h @@ -21,7 +21,7 @@ #define PERIOD_FAN (SYS_PWM_FREQUENCY/2.0/FREQUENCY_FAN) #define PERIOD_BRAKE (SYS_PWM_FREQUENCY/2.0/FREQUENCY_BRAKE) //Tic -#define PERIOD_MOTOR (SYS_PWM_FREQUENCY/2.0/FREQUENCY_MOTOR) //Tic +#define PERIOD_MOTOR (SYS_PWM_FREQUENCY/2.0/FREQUENCY_MOTOR) //Tic = 5000 #define EPWM_DB (EPWM_DB_mkS*SYS_PWM_FREQUENCY/1000000) @@ -29,8 +29,8 @@ #define SDFM_DELAY (SDFM_DELAY_mkS*SYS_PWM_FREQUENCY/1000000) #define PERIOD_2 (PERIOD_MOTOR/2.0) -#define PWM_MAX (PERIOD_MOTOR - EPWM_DB) -#define PWM_MIN EPWM_DB*2 +//#define PWM_MAX (PERIOD_MOTOR - EPWM_DB) +//#define PWM_MIN EPWM_DB*2 #define INDEPENDED 1 #define COMPLIMENTARY 0 diff --git a/Projects/epwm_test_biss_c_cpu2/src/Peripherals/pwm_interrupts.c b/Projects/epwm_test_biss_c_cpu2/src/Peripherals/pwm_interrupts.c index 742a166..093bc05 100644 --- a/Projects/epwm_test_biss_c_cpu2/src/Peripherals/pwm_interrupts.c +++ b/Projects/epwm_test_biss_c_cpu2/src/Peripherals/pwm_interrupts.c @@ -12,7 +12,6 @@ #include "i2c_init.h" #include "timer_base.h" #include "vector.h" -#include "pwm_interrupts.h" #include "sdfm.h" #include "adc_init.h" #include @@ -20,6 +19,7 @@ #include "eqep.h" #include "temperature.h" #include "rele.h" +#include "pwm_interrupts.h" volatile uint16_t AutoChange = 0; volatile uint16_t PWM_out = 2500; @@ -37,18 +37,42 @@ typedef struct int16_t UC; }strPWMABC; + +volatile uint16_t PeriodPWM[2] = {PERIOD_MOTOR, PERIOD_MOTOR}; +volatile uint16_t PeriodPWM_2 = PERIOD_2; volatile strPWMABC PWM_motor = {PERIOD_2, PERIOD_2, PERIOD_2}; int16_t A_proc,B_proc,C_proc; uint16_t PWM_Vent = PERIOD_FAN; uint16_t PWM_Chop = 0; +uint16_t PWM_SDFM_delay = SDFM_DELAY; +uint16_t Timing_PWM[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; -void pwm_set_volt_3F(float phaseA, float phaseB, float phaseC, float Udc) +void pwm_set_volt_3F(float phaseA, float phaseB, float phaseC, float Udc, uint16_t Mode) { - A_proc = (int16_t)((phaseA/Udc)*PERIOD_2); - B_proc = (int16_t)((phaseB/Udc)*PERIOD_2); - C_proc = (int16_t)((phaseC/Udc)*PERIOD_2); + if(PeriodPWM[0] != PeriodPWM[1]) + { + if(Mode == OffMode) + { + if(PeriodPWM[0] < PERIOD_2) PeriodPWM[0]=PERIOD_2; + if(PeriodPWM[0] > PERIOD_MOTOR) PeriodPWM[0]=PERIOD_MOTOR; + PeriodPWM[1] = PeriodPWM[0]; + vectorRegKoeffRecalc(PeriodPWM[0]/PERIOD_MOTOR); + EPwmRegs[PWM_A]->TBPRD = EPwmRegs[PWM_B]->TBPRD = EPwmRegs[PWM_C]->TBPRD = PeriodPWM[0]; + PeriodPWM_2 = PeriodPWM[0]/2; + EPwmRegs[11]->TBPRD = PeriodPWM[0]*2-1; + PWM_SDFM_delay = 2*PeriodPWM[0] - 5000; + EPwm11Regs.CMPA.bit.CMPA = PWM_SDFM_delay; + } + else PeriodPWM[0] == PeriodPWM[1]; + } + + + + A_proc = (int16_t)((phaseA/Udc)*PeriodPWM_2); + B_proc = (int16_t)((phaseB/Udc)*PeriodPWM_2); + C_proc = (int16_t)((phaseC/Udc)*PeriodPWM_2); if(A_proc > 0) A_proc+= EPWM_DB/2; else if(A_proc < 0) A_proc-= EPWM_DB/2; @@ -57,12 +81,12 @@ void pwm_set_volt_3F(float phaseA, float phaseB, float phaseC, float Udc) if(C_proc > 0) C_proc+= EPWM_DB/2; else if(C_proc < 0) C_proc-= EPWM_DB/2; - PWM_motor.UA = PERIOD_2 + A_proc; - PWM_motor.UB = PERIOD_2 + B_proc; + PWM_motor.UA = PeriodPWM_2 + A_proc; + PWM_motor.UB = PeriodPWM_2 + B_proc; #ifdef REF0 - PWM_motor.UC = PERIOD_2 - C_proc; + PWM_motor.UC = PeriodPWM_2 - C_proc; #else - PWM_motor.UC = PERIOD_2 + C_proc; + PWM_motor.UC = PeriodPWM_2 + C_proc; #endif // FaultABC = FaultPWM; @@ -71,18 +95,16 @@ void pwm_set_volt_3F(float phaseA, float phaseB, float phaseC, float Udc) if((FaultABC)||(FaultABCFix)) { PWM_ABC_StopAllClose(); - PWM_motor.UA = PERIOD_2; - PWM_motor.UB = PERIOD_2; - PWM_motor.UC = PERIOD_2; + PWM_motor.UA = PeriodPWM_2; + PWM_motor.UB = PeriodPWM_2; + PWM_motor.UC = PeriodPWM_2; vectorFault(); } - EPwmRegs[PWM_A]->CMPA.bit.CMPA = PERIOD_MOTOR - PWM_motor.UA; - EPwmRegs[PWM_B]->CMPA.bit.CMPA = PERIOD_MOTOR - PWM_motor.UB; - EPwmRegs[PWM_C]->CMPA.bit.CMPA = PERIOD_MOTOR - PWM_motor.UC; + EPwmRegs[PWM_A]->CMPA.bit.CMPA = PeriodPWM[0] - PWM_motor.UA; + EPwmRegs[PWM_B]->CMPA.bit.CMPA = PeriodPWM[0] - PWM_motor.UB; + EPwmRegs[PWM_C]->CMPA.bit.CMPA = PeriodPWM[0] - PWM_motor.UC; -// EPwmRegs[PWM_FAN]->CMPA.bit.CMPA = PERIOD_FAN - PWM_Vent; -// EPwmRegs[3]->CMPB.bit.CMPB = PERIOD_MOTOR - PWM_Chop; } @@ -251,20 +273,23 @@ __interrupt void epwm6_isr(void) -uint16_t PWM_test = SDFM_DELAY; +void saveTimingNow(uint16_t N) +{ + Timing_PWM[N] = EPwm11Regs.TBCTR; +} __interrupt void epwm11_isr(void) { +// EPwm11Regs.CMPA.bit.CMPA = PWM_SDFM_delay; +// EPwm11Regs.CMPB.bit.CMPB = PWM_SDFM_delay; +// EPwm11Regs.CMPC = PWM_SDFM_delay; +// EPwm11Regs.CMPD = PWM_SDFM_delay; - EPwm11Regs.CMPA.bit.CMPA = PWM_test; - EPwm11Regs.CMPB.bit.CMPB = PWM_test; - EPwm11Regs.CMPC = PWM_test; - EPwm11Regs.CMPD = PWM_test; - + saveTimingNow(0); if(TestStopSync != 3) sdfm_start_conversion_current(); PwmFlagStartCurrentMeashure = 1; diff --git a/Projects/epwm_test_biss_c_cpu2/src/Peripherals/pwm_interrupts.h b/Projects/epwm_test_biss_c_cpu2/src/Peripherals/pwm_interrupts.h index 9ad797f..8208da8 100644 --- a/Projects/epwm_test_biss_c_cpu2/src/Peripherals/pwm_interrupts.h +++ b/Projects/epwm_test_biss_c_cpu2/src/Peripherals/pwm_interrupts.h @@ -1,7 +1,7 @@ /* * pwm_interrupts.h * - * Created on: 21 . 2023 . + * Created on: 21 ���. 2023 �. * Author: seklyuts */ @@ -17,9 +17,9 @@ __interrupt void epwm4_isr(void); __interrupt void epwm8_isr(void); __interrupt void epwm6_isr(void); __interrupt void epwm11_isr(void); -void pwm_set_volt_3F(float phaseA, float phaseB, float phaseC, float Udc); +void pwm_set_volt_3F(float phaseA, float phaseB, float phaseC, float Udc, uint16_t Mode); void pwm_clr_PwmFlagStartADC(void); - +void saveTimingNow(uint16_t); #endif /* SRC_PWM_INTERRUPTS_H_ */ diff --git a/Projects/epwm_test_biss_c_cpu2/src/Peripherals/sdfm.c b/Projects/epwm_test_biss_c_cpu2/src/Peripherals/sdfm.c index 98c87d9..c039016 100644 --- a/Projects/epwm_test_biss_c_cpu2/src/Peripherals/sdfm.c +++ b/Projects/epwm_test_biss_c_cpu2/src/Peripherals/sdfm.c @@ -12,6 +12,7 @@ #include "sdfm.h" #include "vector.h" #include "frm_uart.h" + // // Defines // @@ -104,8 +105,8 @@ uint16_t loopCounter[8] = {0,0,0,0,0,0,0,0}; __interrupt void Sdfm1_ISR(void); __interrupt void Sdfm2_ISR(void); -volatile float CurrentFactorBrake = FACTOR_CURRENT_BRAKE*32767.0; -volatile float CurrentFactorMotor = FACTOR_CURRENT_MOTOR*32767.0; +volatile float CurrentFactorBrake = FACTOR_CURRENT_BRAKE*32768.0; +volatile float CurrentFactorMotor = FACTOR_CURRENT_MOTOR*32768.0; diff --git a/Projects/epwm_test_biss_c_cpu2/src/Peripherals/sdfm.h b/Projects/epwm_test_biss_c_cpu2/src/Peripherals/sdfm.h index a58cbf4..83967c9 100644 --- a/Projects/epwm_test_biss_c_cpu2/src/Peripherals/sdfm.h +++ b/Projects/epwm_test_biss_c_cpu2/src/Peripherals/sdfm.h @@ -64,6 +64,7 @@ #define FACTOR_CURRENT_BRAKE (FACTOR_CURRENT_BRAKE_A/BIT_MAX) #define FACTOR_CURRENT_MOTOR (FACTOR_CURRENT_MOTOR_A/BIT_MAX) +#define DIV_FACTOR_CURRENT_MOTOR (1/FACTOR_CURRENT_MOTOR) void SdfmGpioInit(void); void SdfmInitEnable(void); diff --git a/Projects/epwm_test_biss_c_cpu2/src/fault.c b/Projects/epwm_test_biss_c_cpu2/src/fault.c index 3177749..814a08d 100644 --- a/Projects/epwm_test_biss_c_cpu2/src/fault.c +++ b/Projects/epwm_test_biss_c_cpu2/src/fault.c @@ -25,6 +25,8 @@ __interrupt void fault_isr(void) vectorResCurrLoop(); } + + uint16_t fault_read_check(void) { return fault_read; @@ -51,9 +53,11 @@ uint16_t Err1, Err2; void faultInit(void) { - uint16_t Fault_Bytes; uint16_t Conf0 = 0xFE; uint16_t Conf1 = 0xFF; + + uint16_t Fault_Bytes; + Err1 = I2CWrite(I2C_FAULT_SLAVE_ADDRESS, 6, 1, true, &Conf0); Err2 = I2CWrite(I2C_FAULT_SLAVE_ADDRESS, 7, 1, true, &Conf1); diff --git a/Projects/epwm_test_biss_c_cpu2/src/frmmstr_run.c b/Projects/epwm_test_biss_c_cpu2/src/frmmstr_run.c index 49a97da..d94a211 100644 --- a/Projects/epwm_test_biss_c_cpu2/src/frmmstr_run.c +++ b/Projects/epwm_test_biss_c_cpu2/src/frmmstr_run.c @@ -9,6 +9,9 @@ #include "frm_uart.h" #include "gpio_init.h" #include "fault.h" +#include "i2c_oled.h" +#include "buttons.h" +#include "eqep.h" volatile uint16_t counter=0 ; volatile uint16_t counter1=0 ; @@ -16,7 +19,7 @@ volatile uint16_t counter2=0 ; volatile uint16_t testMode = 0; -//uint16_t PWM_Vent1; +uint16_t BisscPwrOn = 1; void frmmstr_run(void) { @@ -60,6 +63,14 @@ static uint16_t diod = 0; } else { + if(BisscPwrOn) + { + GpioDataRegs.GPADAT.bit.GPIO21 = 1; + } + else + { + GpioDataRegs.GPADAT.bit.GPIO21 = 0; + } //Gpio95out(Rele); //if(vectorReleOn()) GpioTurnOnRele; //else GpioTurnOffRele; @@ -68,10 +79,11 @@ static uint16_t diod = 0; { fault_read_clr(); fault_read_ports(); - } - else { - + }else{ +// buttonsDisp(); +// ScreenDisp(); } } + } diff --git a/Projects/epwm_test_biss_c_cpu2/src/init_perif.c b/Projects/epwm_test_biss_c_cpu2/src/init_perif.c index 6b51068..e972757 100644 --- a/Projects/epwm_test_biss_c_cpu2/src/init_perif.c +++ b/Projects/epwm_test_biss_c_cpu2/src/init_perif.c @@ -9,6 +9,7 @@ #include "pwm_init.h" #include "f28x_project.h" +#include "f2838x_cputimervars.h" #include "pwm_interrupts.h" #include "sdfm.h" #include "f2838x_sdfm_drivers.h" @@ -23,6 +24,144 @@ #include "temperature.h" #include "eqep.h" #include "rele.h" +#include "rele.h" +#include "i2c_oled.h" + +extern uint16_t I2C_TXdata[]; +extern uint16_t I2C_RXdata[]; + +struct CPUTIMER_VARS CpuTimer0; +struct CPUTIMER_VARS CpuTimer1; +struct CPUTIMER_VARS CpuTimer2; + +unsigned long uptimeSeconds = 0; // + +__interrupt void cpuTimer0ISR(void) +{ + CpuTimer0.InterruptCount++; + uptimeSeconds++; + // + // Acknowledge this interrupt to receive more interrupts from group 1 + // + PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; +} +void InitCpuTimers(void) +{ + // + // CPU Timer 0 + // Initialize address pointers to respective timer registers: + // + CpuTimer0.RegsAddr = &CpuTimer0Regs; + + // + // Initialize timer period to maximum: + // + CpuTimer0Regs.PRD.all = 0xFFFFFFFF; + + // + // Initialize pre-scale counter to divide by 1 (SYSCLKOUT): + // + CpuTimer0Regs.TPR.all = 0; + CpuTimer0Regs.TPRH.all = 0; + + // + // Make sure timer is stopped: + // + CpuTimer0Regs.TCR.bit.TSS = 1; + + // + // Reload all counter register with period value: + // + CpuTimer0Regs.TCR.bit.TRB = 1; + + // + // Reset interrupt counters: + // + CpuTimer0.InterruptCount = 0; + + // + // Initialize address pointers to respective timer registers: + // + CpuTimer1.RegsAddr = &CpuTimer1Regs; + CpuTimer2.RegsAddr = &CpuTimer2Regs; + + // + // Initialize timer period to maximum: + // + CpuTimer1Regs.PRD.all = 0xFFFFFFFF; + CpuTimer2Regs.PRD.all = 0xFFFFFFFF; + + // + // Initialize pre-scale counter to divide by 1 (SYSCLKOUT): + // + CpuTimer1Regs.TPR.all = 0; + CpuTimer1Regs.TPRH.all = 0; + CpuTimer2Regs.TPR.all = 0; + CpuTimer2Regs.TPRH.all = 0; + + // + // Make sure timers are stopped: + // + CpuTimer1Regs.TCR.bit.TSS = 1; + CpuTimer2Regs.TCR.bit.TSS = 1; + + // + // Reload all counter register with period value: + // + CpuTimer1Regs.TCR.bit.TRB = 1; + CpuTimer2Regs.TCR.bit.TRB = 1; + + // + // Reset interrupt counters: + // + CpuTimer1.InterruptCount = 0; + CpuTimer2.InterruptCount = 0; +} + +// +// ConfigCpuTimer - This function initializes the selected timer to the period +// specified by the "Freq" and "Period" parameters. The "Freq" +// is entered as "MHz" and the period in "uSeconds". The timer +// is held in the stopped state after configuration. +// +void ConfigCpuTimer(struct CPUTIMER_VARS *Timer, float Freq, float Period) +{ + Uint32 temp; + + // + // Initialize timer period: + // + Timer->CPUFreqInMHz = Freq; + Timer->PeriodInUSec = Period; + temp = (long) (Freq * Period); + + // + // Counter decrements PRD+1 times each period + // + Timer->RegsAddr->PRD.all = temp - 1; + + // + // Set pre-scale counter to divide by 1 (SYSCLKOUT): + // + Timer->RegsAddr->TPR.all = 0; + Timer->RegsAddr->TPRH.all = 0; + + // + // Initialize timer control register: + // + Timer->RegsAddr->TCR.bit.TSS = 1; // 1 = Stop timer, 0 = Start/Restart + // Timer + Timer->RegsAddr->TCR.bit.TRB = 1; // 1 = reload timer + Timer->RegsAddr->TCR.bit.SOFT = 0; + Timer->RegsAddr->TCR.bit.FREE = 0; // Timer Free Run Disabled + Timer->RegsAddr->TCR.bit.TIE = 1; // 0 = Disable/ 1 = Enable Timer + // Interrupt + + // + // Reset interrupt counter: + // + Timer->InterruptCount = 0; +} void InitPerif(void) { @@ -87,19 +226,45 @@ void InitPerif(void) #else eqep_init(); #endif - - - + // Enable Timer0 + EALLOW; + PieVectTable.TIMER0_INT = &cpuTimer0ISR; + EDIS; + InitCpuTimers(); + // Configure CPU-Timer 0, 1, and 2 to interrupt every second: + // 200MHz CPU Freq, 1 second Period (in uSeconds) + // + ConfigCpuTimer(&CpuTimer0, 200, 1000000); + // + // To ensure precise timing, use write-only instructions to write to the + // entire register. Therefore, if any of the configuration bits are changed + // in ConfigCpuTimer and InitCpuTimers, the below settings must also be + // be updated. + // + CpuTimer0Regs.TCR.all = 0x4000; + // + // Enable CPU int1 which is connected to CPU-Timer 0, CPU int13 + // which is connected to CPU-Timer 1, and CPU int 14, which is connected + // to CPU-Timer 2 + // + IER |= M_INT1; + // + // Enable TINT0 in the PIE: Group 1 interrupt 7 + // + PieCtrlRegs.PIEIER1.bit.INTx7 = 1; // // Enable global Interrupts and higher priority real-time debug events: // + EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM - I2CMasterInit(I2C_OWN_ADDRESS,I2C_FAULT_SLAVE_ADDRESS); + I2CMasterInit(I2C_OWN_ADDRESS,0x3C); + /* Init LCD */ + SSD1306_Init(); + buttonsInit(); faultInit(); - - rele_initRele(); + } diff --git a/Projects/epwm_test_biss_c_cpu2/src/vector.c b/Projects/epwm_test_biss_c_cpu2/src/vector.c index 9973d6c..a583936 100644 --- a/Projects/epwm_test_biss_c_cpu2/src/vector.c +++ b/Projects/epwm_test_biss_c_cpu2/src/vector.c @@ -105,7 +105,7 @@ uint16_t Num = 0; void vectorControl(int16_t CurrentA, int16_t CurrentB, int16_t CurrentC, int16_t sdfmUdc) { - + saveTimingNow(1); pwm_clr_PwmFlagStartADC(); Ia = -CurrentA;//sdfm_get(6); Ib = -CurrentB;//sdfm_get(3); @@ -182,12 +182,14 @@ void vectorControl(int16_t CurrentA, int16_t CurrentB, int16_t CurrentC, int16_t } Udc = sdfmUdc * FACTOR_VDC; vector_klark_park(SectorCheckOn,Ia,Ib,Ic); + saveTimingNow(2); vector_inversion(); + saveTimingNow(3); BissStartSet(); FMSTREnableSet(); AdcStartSet(); sdfm_start_conversion_brake(); - + saveTimingNow(4); } void vectorInitCurrLoop(void) @@ -222,6 +224,15 @@ void vectorInitCurrLoop(void) CurrLoop.piIq.i1 = 0; // Data: integrator storage: ui(k-1) } + +void vectorRegKoeffRecalc(float Koeff) +{ + CurrLoop.piId.Kp = PI_REG_I_PROPOR*Koeff; + CurrLoop.piId.Ki = PI_REG_I_INTEGR*Koeff; + CurrLoop.piIq.Kp = PI_REG_I_PROPOR*Koeff; + CurrLoop.piIq.Ki = PI_REG_I_INTEGR*Koeff; +} + void vectorResCurrLoop(void) { CurrLoop.piId.Ref = 0; // Input: reference set-point @@ -290,27 +301,28 @@ void vector_inversion(void) vectorUabc.b=-temp3; vectorUabc.c=-(temp1+temp2); } - pwm_set_volt_3F(vectorUabc.a,vectorUabc.b,vectorUabc.c, UdcVolt); + pwm_set_volt_3F(vectorUabc.a,vectorUabc.b,vectorUabc.c, UdcVolt, Mode); } float Test1, Test2; float FRM_Ud, FRM_Uq; +volatile int16_t I_fbk_int, I_ref_int; void vector_klark_park(uint16_t SectorOn, int16_t CurrentA, int16_t CurrentB, int16_t CurrentC) { -/* if (Inputs->UpdateUdc) - { - //Запоминаем Udc для контура тока(ограничение Umax Рё Umin РІ РџР�-регуляторе) - Outputs->Udc = PmsmVect.UdcFilter.Output; - //Защита РѕС‚ деления РЅР° 0 Рё отрицательных чисел - if (Outputs->Udc <= 0.0f) - Outputs->Udc = VOLTAGE_UDC; - //Расчет коэффициента для расчета скважности РЁР�Рњ(РѕРґРёРЅ раз делим, потом каждый цикл РЁР�Рњ умножаем, это эффективнее) - PmsmVect.UdcPwmFactor = 1.0f/Outputs->Udc; - //РЎР±СЂРѕСЃ флага - Inputs->UpdateUdc = false; - }*/ + /* if (Inputs->UpdateUdc) + { + //Запоминаем Udc для контура тока(ограничение Umax и Umin в ПИ-регуляторе) + Outputs->Udc = PmsmVect.UdcFilter.Output; + //Защита от деления на 0 и отрицательных чисел + if (Outputs->Udc <= 0.0f) + Outputs->Udc = VOLTAGE_UDC; + //Расчет коэффициента для расчета скважности ШИМ(один раз делим, потом каждый цикл ШИМ умножаем, это эффективнее) + PmsmVect.UdcPwmFactor = 1.0f/Outputs->Udc; + //Сброс флага + Inputs->UpdateUdc = false; + }*/ if (SectorOn ) @@ -343,7 +355,7 @@ void vector_klark_park(uint16_t SectorOn, int16_t CurrentA, int16_t CurrentB, in vectorIabc.c = (float)CurrentC * FactorCurrent; } - // преобразование Кларк + // преобразование Кларк vectorI2ph.Alfa = vectorIabc.a; vectorI2ph.Beta = _IQmpy((vectorIabc.a +_IQmpy2(vectorIabc.b)),_IQ(ONEbySQRT3)); //vectorI2ph.Beta = _IQmpy((vectorIabc.b - vectorIabc.c),_IQ(ONEbySQRT3)); @@ -354,7 +366,7 @@ void vector_klark_park(uint16_t SectorOn, int16_t CurrentA, int16_t CurrentB, in vectorSinCos.sin = ((float)sin_int)/32768.0; vectorSinCos.cos = ((float)cos_int)/32768.0; - // преобразование Парка + // преобразование Парка vectorIdq.d = _IQmpy(vectorI2ph.Alfa,vectorSinCos.cos) + _IQmpy(vectorI2ph.Beta,vectorSinCos.sin); vectorIdq.q = _IQmpy(vectorI2ph.Beta,vectorSinCos.cos) - _IQmpy(vectorI2ph.Alfa,vectorSinCos.sin); @@ -363,7 +375,7 @@ void vector_klark_park(uint16_t SectorOn, int16_t CurrentA, int16_t CurrentB, in // AngleErr = Angle_test - vectorSinCos.Angle; -// CurrLoop.piIq.Ref = Inputs->IqRef;//Заданное +// CurrLoop.piIq.Ref = Inputs->IqRef;//Заданное if (FABS(CurrLoop.piIq.Ref) > CurrLoop.CurrentLimit) { @@ -399,7 +411,9 @@ void vector_klark_park(uint16_t SectorOn, int16_t CurrentA, int16_t CurrentB, in PI_MACRO(CurrLoop.piIq); PI_MACRO(CurrLoop.piId); - /*Пропорциональное ограничение напряжений Uq Рё Ud*/ + I_fbk_int = (int16_t) (CurrLoop.piId.Fbk*DIV_FACTOR_CURRENT_MOTOR); + I_ref_int = (int16_t) (CurrLoop.piId.Ref*DIV_FACTOR_CURRENT_MOTOR); + /*Пропорциональное ограничение напряжений Uq и Ud*/ // Test1 = my_sqrtf(Test2); @@ -407,7 +421,7 @@ void vector_klark_park(uint16_t SectorOn, int16_t CurrentA, int16_t CurrentB, in - if (Ulim > UmaxVolt)// максимальное напряжение РІ вольтах + if (Ulim > UmaxVolt)// максимальное напряжение в вольтах { if(Ulim > ZERO_LVL) { @@ -453,7 +467,7 @@ float my_sqrtf(float x) return x * x0; } -// Фильтр сигнала +// Фильтр сигнала int16_t Filter(int16_t inValue, Filtered *Struct) { (*Struct).Value16in = inValue; (*Struct).Value32+=(int32_t)((*Struct).Value16in)-(int32_t)((*Struct).Value16filtered); diff --git a/Projects/epwm_test_biss_c_cpu2/src/vector.h b/Projects/epwm_test_biss_c_cpu2/src/vector.h index bb2af7a..d679006 100644 --- a/Projects/epwm_test_biss_c_cpu2/src/vector.h +++ b/Projects/epwm_test_biss_c_cpu2/src/vector.h @@ -96,6 +96,7 @@ void vectorControl(int16_t CurrentA, int16_t CurrentB, int16_t CurrentC, int16_t void vectorFault(void); float my_sqrtf(float x); void vectorResCurrLoop(void); +void vectorRegKoeffRecalc(float Koeff); #endif /* SRC_VECTOR_H_ */ diff --git a/Projects/epwm_test_biss_c_cpu2/targetConfigs/TMS320F28388D.ccxml b/Projects/epwm_test_biss_c_cpu2/targetConfigs/TMS320F28388D.ccxml index 7cf40fd..09ed29e 100644 --- a/Projects/epwm_test_biss_c_cpu2/targetConfigs/TMS320F28388D.ccxml +++ b/Projects/epwm_test_biss_c_cpu2/targetConfigs/TMS320F28388D.ccxml @@ -1,81 +1,30 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Projects/epwm_test_biss_c_cpu2/Описание проекта freemaster.txt b/Projects/epwm_test_biss_c_cpu2/Описание проекта freemaster.txt index 7bea528..cb1e17a 100644 --- a/Projects/epwm_test_biss_c_cpu2/Описание проекта freemaster.txt +++ b/Projects/epwm_test_biss_c_cpu2/Описание проекта freemaster.txt @@ -76,11 +76,5 @@ ___________________________________________ нужно выбрать Mode = 3 и задать ток CurrentRegTuneAmpl в амперах слева выбрать график I с биноклем который после этого менять CurrLoop.piId.Kp и CurrLoop.piId.Ki чтобы изменить характеристику -___________________________________________ -Импульс тока -В переменную CurrentRegTuneAmplInpuls задать ток импульса -В переменную Impulse задать кол-во секунд (от 0.0001 с до 10 сек) - -после этого ток примет значение CurrentRegTuneAmplInpuls на Impulse секунд и после этого Impulse станет равен 0, а ток вернётся к значению CurrentRegTuneAmpl