diff --git a/Projects/epwm_test_biss_c_cpu2/src/Peripherals/gpio_init.c b/Projects/epwm_test_biss_c_cpu2/src/Peripherals/gpio_init.c index 7cb9bbc..504903c 100644 --- a/Projects/epwm_test_biss_c_cpu2/src/Peripherals/gpio_init.c +++ b/Projects/epwm_test_biss_c_cpu2/src/Peripherals/gpio_init.c @@ -110,3 +110,15 @@ void Gpio95out(uint16_t out_bit) { GpioDataRegs.GPCDAT.bit.GPIO95 = out_bit; } + +void GpioTurnOnRele(void) +{ + GpioDataRegs.GPCDAT.bit.GPIO95 = 1; +} + +void GpioTurnOffRele(void) +{ + GpioDataRegs.GPCDAT.bit.GPIO95 = 0; +} + + diff --git a/Projects/epwm_test_biss_c_cpu2/src/Peripherals/gpio_init.h b/Projects/epwm_test_biss_c_cpu2/src/Peripherals/gpio_init.h index 621135b..14e1da4 100644 --- a/Projects/epwm_test_biss_c_cpu2/src/Peripherals/gpio_init.h +++ b/Projects/epwm_test_biss_c_cpu2/src/Peripherals/gpio_init.h @@ -1,7 +1,7 @@ /* * gpio_init.h * - * Created on: 4 ñåíò. 2023 ã. + * Created on: 4 ����. 2023 �. * Author: seklyuts */ @@ -38,5 +38,7 @@ void Gpio56out(uint16_t out_bit); void Gpio57out(uint16_t out_bit); void Gpio95out(uint16_t out_bit); void Gpio_rainbow(uint16_t color); +void GpioTurnOnRele(void); +void GpioTurnOffRele(void); #endif /* SRC_GPIO_INIT_H_ */ 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 f493367..0c16a40 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 @@ -19,6 +19,7 @@ #include "biss.h" #include "eqep.h" #include "temperature.h" +#include "rele.h" volatile uint16_t AutoChange = 0; volatile uint16_t PWM_out = 2500; @@ -146,6 +147,8 @@ __interrupt void epwm2_isr(void) EPwmRegs[3]->CMPB.bit.CMPB = PERIOD_MOTOR - PWM_Chop; Test_ADC_PWM_Synch1++; if(TestStopSync == 2) TestStopSync = 3; + if(rele_isReleOn()) GpioTurnOnRele(); + else GpioTurnOffRele(); } else Test_ADC_PWM_Synch2++; // 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 b8b6930..3fb19d4 100644 --- a/Projects/epwm_test_biss_c_cpu2/src/Peripherals/sdfm.h +++ b/Projects/epwm_test_biss_c_cpu2/src/Peripherals/sdfm.h @@ -35,7 +35,7 @@ #define BIT_MAX 32768//4096 -#define FACTOR_VDC (SDFM_VOLTAGE_MAX/R_VDC*(R_DEL_VDC+R_VDC)/1000) +#define FACTOR_VDC (SDFM_VOLTAGE_MAX/R_VDC*(R_DEL_VDC+R_VDC)/1000) //= 320/806*(2000000+806)/1000 #define FACTOR_CURRENT_BRAKE_A (SDFM_VOLTAGE_MAX/R_BRAKE) //A #define FACTOR_CURRENT_MOTOR_A (SDFM_VOLTAGE_MAX/R_DRW) //A 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 11e120c..eb846e6 100644 --- a/Projects/epwm_test_biss_c_cpu2/src/frmmstr_run.c +++ b/Projects/epwm_test_biss_c_cpu2/src/frmmstr_run.c @@ -13,7 +13,7 @@ volatile uint16_t counter=0 ; volatile uint16_t counter1=0 ; volatile uint16_t counter2=0 ; -volatile uint16_t Rele=0; + volatile uint16_t testMode = 0; //uint16_t PWM_Vent1; @@ -60,7 +60,10 @@ static uint16_t diod = 0; } else { - Gpio95out(Rele); + //Gpio95out(Rele); + //if(vectorReleOn()) GpioTurnOnRele; + //else GpioTurnOffRele; + if(fault_read_check()) { fault_read_clr(); 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 e59621b..f236f54 100644 --- a/Projects/epwm_test_biss_c_cpu2/src/init_perif.c +++ b/Projects/epwm_test_biss_c_cpu2/src/init_perif.c @@ -22,6 +22,7 @@ #include "fault.h" #include "temperature.h" #include "eqep.h" +#include "rele.h" void InitPerif(void) { @@ -85,6 +86,9 @@ void InitPerif(void) temperatureInit(); #endif + faultInit(); + rele_initRele(); + // // Enable global Interrupts and higher priority real-time debug events: // @@ -93,7 +97,7 @@ void InitPerif(void) I2CMasterInit(I2C_OWN_ADDRESS,I2C_FAULT_SLAVE_ADDRESS); - faultInit(); + } diff --git a/Projects/epwm_test_biss_c_cpu2/src/rele.c b/Projects/epwm_test_biss_c_cpu2/src/rele.c new file mode 100644 index 0000000..25698ef --- /dev/null +++ b/Projects/epwm_test_biss_c_cpu2/src/rele.c @@ -0,0 +1,53 @@ +/* + * rele.c + * + * Created on: 3 июл. 2024 г. + * Author: seklyuts + */ +#include "f28x_project.h" +#include "sdfm.h" +#include "vector.h" +#include "rele.h" + + +TRele Rele; + +uint16_t rele_isReleOn(void) +{ + return Rele.State; +} + + +void rele_initRele(void) +{ + Rele.State = 0; + Rele.ReleCounter = 0; + Rele.CounterMax = RELE_COUNTER_MAX; + Rele.UdcDiff = RELE_UDC_DIFF; + Rele.Error = 0; +} + + +void rele_run(int16_t UdcFiltered) +{ + Gpio95out(Rele.State); + if(!Rele.State) + { + vectorFault(); + Rele.ReleCounter = 0; + Rele.Error = 0; + } + else { + if(Rele.ReleCounter == 0) Rele.Udc = UdcFiltered; + if(Rele.ReleCounter < Rele.CounterMax) {Rele.ReleCounter++; vectorFault();} + else + { + if((UdcFiltered - Rele.Udc ) < Rele.UdcDiff) + { + vectorFault(); + Rele.Error = 1; + } + } + } + +} diff --git a/Projects/epwm_test_biss_c_cpu2/src/rele.h b/Projects/epwm_test_biss_c_cpu2/src/rele.h new file mode 100644 index 0000000..ed88ce0 --- /dev/null +++ b/Projects/epwm_test_biss_c_cpu2/src/rele.h @@ -0,0 +1,29 @@ +/* + * rele.h + * + * Created on: 3 июл. 2024 г. + * Author: seklyuts + */ + +#ifndef SRC_RELE_H_ +#define SRC_RELE_H_ + +#define RELE_COUNTER_MAX 30 +#define RELE_UDC_DIFF_VOLT 5.0 +#define RELE_UDC_DIFF (RELE_UDC_DIFF_VOLT*BIT_MAX/FACTOR_VDC) + +uint16_t rele_isReleOn(void); +void rele_initRele(void); +void rele_run(int16_t UdcFiltered); + +typedef struct +{ + uint16_t State; + uint16_t ReleCounter; + uint16_t CounterMax; + int16_t Udc; + int16_t UdcDiff; + uint16_t Error; +}TRele; + +#endif /* SRC_RELE_H_ */ diff --git a/Projects/epwm_test_biss_c_cpu2/src/vector.c b/Projects/epwm_test_biss_c_cpu2/src/vector.c index df9c9fb..a0e8db5 100644 --- a/Projects/epwm_test_biss_c_cpu2/src/vector.c +++ b/Projects/epwm_test_biss_c_cpu2/src/vector.c @@ -19,14 +19,15 @@ #include "adc_init.h" #include "biss.h" #include "temperature.h" +#include "rele.h" #define IMAX_A 35.0 //A #define IMAX (IMAX_A*BIT_MAX/FACTOR_CURRENT_MOTOR_A) typedef struct { - int16_t Value16in; // Нефильрованное значение - int16_t Value16filtered; // Фильрованное значение - int32_t Value32; // Конечное напрСÐжение тренировки + int16_t Value16in; // + int16_t Value16filtered; // + int32_t Value32; // int16_t ShiftFilter; // Filters } Filtered; @@ -78,11 +79,17 @@ int16_t Angle_test=0,sin_int,cos_int, AngleErr; float Udc; uint16_t SectorCheckOn=1; volatile int16_t UdcFiltered = 0; +volatile int16_t Udc_rele = 0; float UdcVolt = 0; volatile float VdcFactor = FACTOR_VDC; volatile uint16_t VoltProcImit = 0; + + + + + void vectorFault(void) { Mode = OffMode; @@ -103,12 +110,14 @@ void vectorControl(int16_t CurrentA, int16_t CurrentB, int16_t CurrentC, int16_t UdcFiltered = Filter(sdfmUdc, &UdcFilter); if(UdcFiltered < 0) UdcFiltered = 0; if(VoltProcImit) UdcVolt = VoltProcImit; - else UdcVolt = (float)UdcFiltered*VdcFactor/32768; + else UdcVolt = (float)UdcFiltered*VdcFactor/BIT_MAX; Step = Step + Nstep; CurrLoop.piId.Ref = 0; + rele_run(UdcFiltered); + if(Mode) {XintRegs.XINT2CR.bit.ENABLE = 0; temperature_deInit();} switch(Mode)