Ver Fonte

修改了PWM限制表格 以及换向是在40hz内的其他是8KHZ的计算周期

danny wang há 1 ano atrás
pai
commit
d05b69e58e
29 ficheiros alterados com 1146 adições e 1255 exclusões
  1. 5 2
      .cproject
  2. 1 0
      .settings/org.eclipse.core.resources.prefs
  3. 12 16
      F28035_FLASH_HVBLDC_Sensored.CMD
  4. BIN
      F2803x_FLASH/DLOG4CHC.obj
  5. BIN
      F2803x_FLASH/DSP2803x_CpuTimers.obj
  6. BIN
      F2803x_FLASH/DSP2803x_GlobalVariableDefs.obj
  7. BIN
      F2803x_FLASH/DSP2803x_usDelay.obj
  8. BIN
      F2803x_FLASH/HVBLDC_Sensored-DevInit_F2803x.obj
  9. 475 474
      F2803x_FLASH/HVBLDC_Sensored.map
  10. BIN
      F2803x_FLASH/HVBLDC_Sensored.obj
  11. BIN
      F2803x_FLASH/HVBLDC_Sensored.out
  12. 339 339
      F2803x_FLASH/HVBLDC_Sensored_linkInfo.xml
  13. BIN
      F2803x_FLASH/UserSource/UserCan.obj
  14. BIN
      F2803x_FLASH/UserSource/lowpass.obj
  15. BIN
      F2803x_FLASH/UserSource/var.obj
  16. BIN
      F2803x_FLASH/include/device_support/f2803x/v121/DSP2803x_common/source/DSP2803x_CodeStartBranch.obj
  17. BIN
      F2803x_FLASH/include/device_support/f2803x/v125/DSP2803x_common/source/DSP2803x_ECan.obj
  18. BIN
      F2803x_FLASH/include/libs/app_libs/motor_control/math_blocks/v4.0/pi.obj
  19. BIN
      F2803x_FLASH/include/libs/app_libs/motor_control/math_blocks/v4.0/rmp_cntl.obj
  20. BIN
      F2803x_FLASH/include/libs/app_libs/motor_control/math_blocks/v4.0/speed_pr.obj
  21. 1 1
      HVBLDC_Sensored-Settings.h
  22. 232 390
      HVBLDC_Sensored.c
  23. 14 13
      UserSource/UserCan.c
  24. 1 1
      UserSource/UserCan.h
  25. 2 1
      UserSource/lowpass.c
  26. 38 12
      UserSource/var.c
  27. 22 2
      UserSource/var.h
  28. 1 1
      include/libs/app_libs/motor_control/drivers/f2803x_v2.0/f2803xhall_gpio.h
  29. 3 3
      include/libs/app_libs/motor_control/math_blocks/v4.0/speed_pr.c

+ 5 - 2
.cproject

@@ -18,7 +18,7 @@
 			<storageModule moduleId="cdtBuildSystem" version="4.0.0">
 				<configuration artifactExtension="out" artifactName="HVBLDC_Sensored" buildProperties="" description="" id="com.ti.ccstudio.buildDefinitions.C2000.Default.1471795380" name="F2803x_FLASH" parent="com.ti.ccstudio.buildDefinitions.C2000.Default">
 					<folderInfo id="com.ti.ccstudio.buildDefinitions.C2000.Default.1471795380.1565009330" name="/" resourcePath="">
-						<toolChain id="com.ti.ccstudio.buildDefinitions.C2000_22.6.exe.DebugToolchain.1498495756" name="TI Build Tools" superClass="com.ti.ccstudio.buildDefinitions.C2000_22.6.exe.DebugToolchain" targetTool="com.ti.ccstudio.buildDefinitions.C2000_22.6.exe.linkerDebug.1472446438">
+						<toolChain id="com.ti.ccstudio.buildDefinitions.C2000_22.6.exe.DebugToolchain.1498495756" name="TI Build Tools" secondaryOutputs="" superClass="com.ti.ccstudio.buildDefinitions.C2000_22.6.exe.DebugToolchain" targetTool="com.ti.ccstudio.buildDefinitions.C2000_22.6.exe.linkerDebug.1472446438">
 							<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.core.OPT_TAGS.872402393" superClass="com.ti.ccstudio.buildDefinitions.core.OPT_TAGS" valueType="stringList">
 								<listOptionValue builtIn="false" value="DEVICE_CONFIGURATION_ID=TMS320C28XX"/>
 								<listOptionValue builtIn="false" value="DEVICE_CORE_ID="/>
@@ -90,7 +90,10 @@
 								<inputType id="com.ti.ccstudio.buildDefinitions.C2000_22.6.exeLinker.inputType__CMD2_SRCS.543006465" name="Linker Command Files" superClass="com.ti.ccstudio.buildDefinitions.C2000_22.6.exeLinker.inputType__CMD2_SRCS"/>
 								<inputType id="com.ti.ccstudio.buildDefinitions.C2000_22.6.exeLinker.inputType__GEN_CMDS.35906534" name="Generated Linker Command Files" superClass="com.ti.ccstudio.buildDefinitions.C2000_22.6.exeLinker.inputType__GEN_CMDS"/>
 							</tool>
-							<tool id="com.ti.ccstudio.buildDefinitions.C2000_22.6.hex.2100402786" name="C2000 Hex Utility" superClass="com.ti.ccstudio.buildDefinitions.C2000_22.6.hex"/>
+							<tool id="com.ti.ccstudio.buildDefinitions.C2000_22.6.hex.2100402786" name="C2000 Hex Utility" superClass="com.ti.ccstudio.buildDefinitions.C2000_22.6.hex">
+								<option id="com.ti.ccstudio.buildDefinitions.C2000_22.6.hex.TOOL_ENABLE.1764746034" name="Enable tool" superClass="com.ti.ccstudio.buildDefinitions.C2000_22.6.hex.TOOL_ENABLE" value="false" valueType="boolean"/>
+								<outputType id="com.ti.ccstudio.buildDefinitions.C2000_22.6.hex.outputType__BIN.542891391" name="Binary File" superClass="com.ti.ccstudio.buildDefinitions.C2000_22.6.hex.outputType__BIN"/>
+							</tool>
 						</toolChain>
 					</folderInfo>
 					<sourceEntries>

+ 1 - 0
.settings/org.eclipse.core.resources.prefs

@@ -114,3 +114,4 @@ encoding//F2803x_FLASH/objects.mk=UTF-8
 encoding//F2803x_FLASH/sources.mk=UTF-8
 encoding//F2803x_FLASH/subdir_rules.mk=UTF-8
 encoding//F2803x_FLASH/subdir_vars.mk=UTF-8
+encoding/F28035_FLASH_HVBLDC_Sensored.CMD=UTF-8

+ 12 - 16
F28035_FLASH_HVBLDC_Sensored.CMD

@@ -11,7 +11,7 @@
 /*	Version: 		1.00                                							*/
 /*                                                                                  */
 /*----------------------------------------------------------------------------------*/
-/*  Copyright Texas Instruments � 2009                                			    */	
+/*  Copyright Texas Instruments � 2009                                			    */
 /*----------------------------------------------------------------------------------*/
 /*  Revision History:                                                               */
 /*----------------------------------------------------------------------------------*/
@@ -51,13 +51,9 @@ MEMORY
 PAGE 0:
 	progRAM	    : origin = 0x008000, length = 0x001000 /* on-chip RAM (L0-L2)*/
 	OTP         : origin = 0x3D7800, length = 0x000400     /* on-chip OTP */
-	FLASHH      : origin = 0x3E8000, length = 0x002000     /* on-chip FLASH */
-	FLASHG      : origin = 0x3EA000, length = 0x002000     /* on-chip FLASH */
-	FLASHF      : origin = 0x3EC000, length = 0x002000     /* on-chip FLASH */
-	FLASHE      : origin = 0x3EE000, length = 0x002000     /* on-chip FLASH */
-	FLASHD      : origin = 0x3F0000, length = 0x002000     /* on-chip FLASH */
-	FLASHC      : origin = 0x3F2000, length = 0x002000     /* on-chip FLASH */
-	FLASHA      : origin = 0x3F6000, length = 0x001F80     /* on-chip FLASH */
+    FLASHD      : origin = 0x3E8000, length = 0x004000     /* on-chip FLASH */
+    FLASHC      : origin = 0x3EC000, length = 0x004000     /* on-chip FLASH */
+    FLASHA      : origin = 0x3F4000, length = 0x003F80     /* on-chip FLASH */
 	CSM_RSVD    : origin = 0x3F7F80, length = 0x000076     /* Part of FLASHA.  Program with all 0x0000 when CSM is in use. */
 	BEGIN       : origin = 0x3F7FF6, length = 0x000002     /* Part of FLASHA.  Used for "boot to Flash" bootloader mode. */
 	CSM_PWL     : origin = 0x3F7FF8, length = 0x000008     /* Part of FLASHA.  CSM password locations in FLASHA */
@@ -76,7 +72,7 @@ PAGE 1 :
     RAMM1       : origin = 0x000400, length = 0x000400     /* on-chip RAM block M1 */
     RAML2       : origin = 0x008C00, length = 0x000400     /* on-chip RAM block L2 */
 	dataRAM	    : origin = 0x009000, length = 0x001000     /* data RAM (L3) */
-	FLASHB      : origin = 0x3F4000, length = 0x002000     /* on-chip FLASH */
+	FLASHB      : origin = 0x3F0000, length = 0x004000     /* on-chip FLASH */
 
 	CLA_CPU_MSGRAM  : origin = 0x001480, length = 0x000080 /* CLA-R/W, CPU-R message RAM */
 	CPU_CLA_MSGRAM  : origin = 0x001500, length = 0x000080 /* CPU-R/W, CLA-R message RAM */
@@ -86,12 +82,12 @@ PAGE 1 :
 SECTIONS
 {
    /* Allocate program areas: */
-   .cinit            : > FLASHA,     PAGE = 0
-   .pinit            : > FLASHA,     PAGE = 0
-   .text             : > FLASHA,     PAGE = 0
+   .cinit            : > FLASHD,     PAGE = 0
+   .pinit            : > FLASHD,     PAGE = 0
+   .text             : > FLASHD,     PAGE = 0
 
    codestart         : > BEGIN       PAGE = 0
-   ramfuncs          : LOAD = FLASHD, 
+   ramfuncs          : LOAD = FLASHC,
                        RUN = progRAM, 
                        LOAD_START(_RamfuncsLoadStart),
                        LOAD_END(_RamfuncsLoadEnd),
@@ -108,11 +104,11 @@ SECTIONS
 
    /* Initalized sections go in Flash */
    /* For SDFlash to program these, they must be allocated to page 0 */
-   .econst           : > FLASHA      PAGE = 0
-   .switch           : > FLASHA      PAGE = 0      
+   .econst           : > FLASHD      PAGE = 0
+   .switch           : > FLASHD      PAGE = 0
 
    /* Allocate IQ math areas: */
-   IQmath            : > FLASHA      PAGE = 0                  /* Math Code */
+   IQmath            : > FLASHD      PAGE = 0                  /* Math Code */
    IQmathTables      : > IQTABLES     PAGE = 0, TYPE = NOLOAD   /* Math Tables In ROM */
 
    Cla1ToCpuMsgRAM   : > CLA_CPU_MSGRAM PAGE = 1

BIN
F2803x_FLASH/DLOG4CHC.obj


BIN
F2803x_FLASH/DSP2803x_CpuTimers.obj


BIN
F2803x_FLASH/DSP2803x_GlobalVariableDefs.obj


BIN
F2803x_FLASH/DSP2803x_usDelay.obj


BIN
F2803x_FLASH/HVBLDC_Sensored-DevInit_F2803x.obj


Diff do ficheiro suprimidas por serem muito extensas
+ 475 - 474
F2803x_FLASH/HVBLDC_Sensored.map


BIN
F2803x_FLASH/HVBLDC_Sensored.obj


BIN
F2803x_FLASH/HVBLDC_Sensored.out


Diff do ficheiro suprimidas por serem muito extensas
+ 339 - 339
F2803x_FLASH/HVBLDC_Sensored_linkInfo.xml


BIN
F2803x_FLASH/UserSource/UserCan.obj


BIN
F2803x_FLASH/UserSource/lowpass.obj


BIN
F2803x_FLASH/UserSource/var.obj


BIN
F2803x_FLASH/include/device_support/f2803x/v121/DSP2803x_common/source/DSP2803x_CodeStartBranch.obj


BIN
F2803x_FLASH/include/device_support/f2803x/v125/DSP2803x_common/source/DSP2803x_ECan.obj


BIN
F2803x_FLASH/include/libs/app_libs/motor_control/math_blocks/v4.0/pi.obj


BIN
F2803x_FLASH/include/libs/app_libs/motor_control/math_blocks/v4.0/rmp_cntl.obj


BIN
F2803x_FLASH/include/libs/app_libs/motor_control/math_blocks/v4.0/speed_pr.obj


+ 1 - 1
HVBLDC_Sensored-Settings.h

@@ -42,7 +42,7 @@ This line sets the BUILDLEVEL to one of the available choices.
 #endif
 
 // Define the ISR frequency (kHz)
-#define ISR_FREQUENCY 20
+#define ISR_FREQUENCY 40
 #define PWM_FREQUENCY 20
 
 // Parameter Initializations 

+ 232 - 390
HVBLDC_Sensored.c

@@ -26,6 +26,7 @@ void InitFlash();
 #define TIMER1_S1 60
 #define TIMER1_S2 500000
 #define TIMER1_PER 30000000
+#define MAINLOOPDIV 5 // 主中断40K 40K/MAINLOOPDIV 主循环
 // Prototype statements for functions found within this file.
 interrupt void MainISR(void);//主中断
 interrupt void xint1_isr(void);//FO中断
@@ -49,9 +50,9 @@ void EnableDog(void);
 
 // Used for running BackGround in flash, and ISR in RAM
 //速度计算相关
-
+int16 t4 = 0;
 int16 Xint2Cnt = 0;
-
+int16 hallCmtnTrig = 0;
 extern Uint16 *RamfuncsLoadStart, *RamfuncsLoadEnd, *RamfuncsRunStart;
 
 int16	SerialCommsTimer;
@@ -139,12 +140,24 @@ IMPULSE impl1 = IMPULSE_DEFAULTS;
 // Create an instance of DATALOG Module  950:3A 但是只有外界扭矩低于36N才能启动起来
 Uint16 pwm_limit_table1[5] = {950,1300,1650,1930,2320};//0 50 100 150 200
 ////                     0,    100,  200, 300, 400 500 600  700   800  900 1000
-Uint16 pwm_limit_table2[]= {950,1650,2320,3050,3750,4460,5200,5929,6623,7358,8050,
+/*Uint16 pwm_limit_table2[]= {950,1650,2320,3050,3750,4460,5200,5929,6623,7358,8050,
                            8744,9400,10165,10848,11600,12290,12953,13684,14310,15050,
                            15760,16434,17054,17750,18493,19134,19830,20507,21260,21926,
-                           22602,23232,23935,24609,25240};
-
-int32 pwmlimitrate = 32768;
+                           22602,23232,23935,24609,25240};*/
+Uint16 pwm_limit_table2[]= {950,1650,2320,2985,3668,4348,5024,5705,6383,7058,7739,
+                           8449,9122,9800,10480,11163,11826,12499,13181,13860,14515,
+                           15192,15872,16530,17203,17861,18537,19183,19848,20525,21161,
+                           21838,22488,23216,23850,24507,24507};
+    ////                     0,    100,  200, 300, 400 500 600  700   800  900 1000
+Uint16 pwm_limit_table_neg[]= {950,1616,2272,2961,3641,4305,4983,5659,6326,6994,7670,
+                               8348,9022,9700,10361,11502,11714,12379,13066,13727,14426,//1100-2000
+                               15085,15610,16325,17005,17660,18338,19000,19693,20390,21048,
+                               21706,22428,23104,22823,24434,24434};
+/*Uint16 pwm_limit_table_neg[]= {950,1650,2320,3050,3750,4476,5200,5830,6520,7200,7808,
+                           8500,9206,9800,10510,11200,11930,12579,13229,13892,14540,
+                           15209,15920,16616,17291,18000,18775,19424,20507,21260,21926,
+                           22602,23232,23935,24609,25240};*/
+int32 pwmlimitrate = 24507;
 
 Uint32 IsrTicker=0;
 void main(void)
@@ -236,7 +249,7 @@ void main(void)
 	PWMDAC_INIT_MACRO(7,pwmdac1) ;	// PWM 7A,7B
 
 // Initialize Hall module   
-    hall1.DebounceAmount = 0;
+    hall1.DebounceAmount = 1;
     hall1.Revolutions    = 1;
 	HALL3_INIT_MACRO(&hall1);//读hall值 初始化HallGpioBuffer,HallGpioAccepted
 
@@ -283,8 +296,8 @@ void main(void)
 // IDLE loop. Just sit and loop forever:	
 	for(;;)  //infinite loop
 	{
-	    if(IsrTicker%2 ==0)
-	    {
+	    if(IsrTicker%MAINLOOPDIV ==0)
+	    {//8Khz
 	        mainLoop();
 	    }
 	}
@@ -310,8 +323,59 @@ interrupt void MainISR(void)
 // Verifying the ISR
     IsrTicker++;
     IsrTicker = (IsrTicker>20000)? 0 : IsrTicker;
-   
-	//IsrTime = MastIsrTimePercent();
+    VirtualTimer++;
+    VirtualTimer &= 0x00007FFF;
+    HALL3_READ_MACRO(&hall1);
+    ClosedFlag = TRUE;
+  if (ClosedFlag==TRUE)
+  {
+
+    if (hall1.CmtnTrigHall==0x7FFF)
+    {
+
+        hallCmtnTrig = 1;
+        speed_direction(hall1.HallGpioAccepted,PreviousState);
+
+     if (hall1.HallGpioAccepted==5)
+       {
+         pwm1.CmtnPointerIn = 5;
+       }
+       else if (hall1.HallGpioAccepted==1)
+       { pwm1.CmtnPointerIn = 0;
+
+       }
+       else if (hall1.HallGpioAccepted==3)
+       { pwm1.CmtnPointerIn = 1;
+
+       }
+       else if (hall1.HallGpioAccepted==2)
+       { pwm1.CmtnPointerIn = 2;
+
+       }
+       else if (hall1.HallGpioAccepted==6)
+       {  pwm1.CmtnPointerIn = 3;
+
+       }
+       else if (hall1.HallGpioAccepted==4)
+       {
+           pwm1.CmtnPointerIn = 4;
+       }
+     PreviousState = hall1.HallGpioAccepted;
+
+
+   }    // delay
+ }      // ClosedFlag==TRUE
+
+
+
+     if(Enable_ALLOW == 0 && pwm1.DutyFunc==0){
+         bldcpwm_close();
+
+
+      }else{
+          BLDCPWM_MACRO(1,2,3,&pwm1);
+
+      }
 // Acknowledge interrupt to recieve more interrupts from PIE group 1
 	CpuTimer0.RegsAddr->TCR.bit.TIF=1;
 	PieCtrlRegs.PIEACK.bit.ACK1 = 1;
@@ -374,32 +438,37 @@ void HVDMC_Protection(void)
 interrupt void xint2_isr(void)
 {
     static int32 last_XintTime = TIMER1_PER;
-
-/*   if(CpuTimer1.RegsAddr->TCR.bit.TIF == 1){
+    static Uint32 last_hall = 0;
+    Uint32 temp = 0;
+  if(CpuTimer1.RegsAddr->TCR.bit.TIF == 1){
         // 速度为0
         XintTime = (int32)TIMER1_PER;
         CpuTimer1.RegsAddr->TCR.bit.TIF = 1;//写1清中断标志位
     }else{
         XintTime = (int32)TIMER1_PER - CpuTimer1.RegsAddr->TIM.all;
-    }*/
+    }
     XintTime = (int32)TIMER1_PER - CpuTimer1.RegsAddr->TIM.all;
+    temp = (GpioDataRegs.GPADAT.all>>24)&0x00000007; /* read all three GPIOs at once*/
 
-   if(XintTime<30000){
+   if(_IQabs(XintTime)<30000 || temp == last_hall ){
        //filter 防抖
        XintTime = last_XintTime;
-   }
-   last_XintTime = XintTime;
+       PieCtrlRegs.PIEACK.bit.ACK1 =1;
 
+       return ;
+   }
    if(Direction == -1){
        XintTime = -XintTime;
    }
    Xint2Cnt = 1;
+   last_XintTime = XintTime;
+   last_hall = temp;
+
     CpuTimer1.RegsAddr->TCR.bit.TRB = 1; //重新装载
     CpuTimer1.RegsAddr->TCR.bit.TSS = 0;//定时器restart
 
     PieCtrlRegs.PIEACK.bit.ACK1 =1;
 
-
 }
 
 interrupt void xint1_isr(void)
@@ -472,17 +541,118 @@ void ClosePwm(void)
     EDIS;
 }
 void speed_direction(Uint16 hall,Uint16 hall_last){
-
+//防抖
+    static int16 i = 0;
+    static int16 j=0;
 
     if(hall_last == 2 && hall == 6 || hall_last == 6 && hall == 4 ||hall_last == 4 && hall == 5 ||hall_last == 5 && hall == 1||hall_last == 1 && hall == 3||hall_last == 3 && hall == 2)
     {
-        Direction = 1;
+        i++;
+        j--;
+        if(j<0){
+            j=0;
+        }
+        if(i>5){
+            i = 6;
+            Direction = 1;
+        }
     }
      else if(hall_last == 4 && hall == 6 || hall_last == 6 && hall == 2 ||hall_last == 2 && hall == 3 ||hall_last == 3 && hall == 1||hall_last == 1 && hall == 5|| hall_last == 5 && hall == 4)
      {
-         Direction = -1;
+         i--;
+         if(i<0){
+             i=0;
+         }
+         j++;
+         if(j>5){
+             j= 6;
+             Direction = -1;
+         }
+
+     }
+
+}
+void speed_cal_filter(void){
+    int32 RotarRPMNew = 0;
+     int32 RotarrpmOut = 0;
+    static int32 last_speed = 0;
+    static int32 last_RotarRPMNew = 0;
+    Uint16 Halltemp = (Uint16)((GpioDataRegs.GPADAT.all>>24)&0x00000007); /* read all three GPIOs at once*/
+     static Uint16 Hall_1 = 0;
+     //static Uint16 Hall_2 = 0;
+     static int32 Hall_2_cnt = 0;
+     int16 directiontemp = 0;
+
+    if(CpuTimer1.RegsAddr->TCR.bit.TIF == 1){
+         // 速度为0
+         XintTime = TIMER1_PER;
+         Xint2Cnt = 1;
+         RotarRPMNew =0;
+         last_speed = 0;
+         CpuTimer1.RegsAddr->TCR.bit.TIF = 1;//写1清零
+
+
+     }else{
+         if(Halltemp == hall1.HallGpioAccepted){
+             Hall_2_cnt++;
+             if(Hall_2_cnt>MAINLOOPFREQ/2){//0.5s
+                 Hall_2_cnt = MAINLOOPFREQ/2+1;
+             }
+         }else{
+             Hall_2_cnt = 0;
+         }
+         if(XintTime == TIMER1_PER || Hall_2_cnt>=5000){
+             RotarRPMNew = 0;
+             last_speed = 0;
+         }else{
+         RotarRPMNew =(int32)360000000/XintTime;
+         }
      }
+    test2 = RotarRPMNew;
+     if(Xint2Cnt == 1){
+         //防止突然反向
+         Xint2Cnt = 0;
+              if(Hall_1 == 2 && Halltemp == 6 || Hall_1 == 6 && Halltemp == 4 ||Hall_1 == 4 && Halltemp == 5 ||Hall_1 == 5 && Halltemp == 1||Hall_1 == 1 && Halltemp == 3||Hall_1 == 3 && Halltemp == 2)
+          {
+             directiontemp = 1;
+          }
+          else if(Hall_1 == 4 && Halltemp == 6 || Hall_1 == 6 && Halltemp == 2 ||Hall_1 == 2 && Halltemp == 3 ||Hall_1 == 3 && Halltemp == 1||Hall_1 == 1 && Halltemp == 5|| Hall_1 == 5 && Halltemp == 4)
+          {
+
+              directiontemp = -1;
+          }
+         if((Direction ==1 && directiontemp == -1 )||(Direction == -1 && directiontemp == 1 )){
+             //说明在振动
+             RotarRPMNew = 0;
+             last_speed = 0;
+         }
+         Hall_1 = Halltemp;
+         test4 = Halltemp;
+
+     }
+
+
+
+         if(_IQabs(RotarRPMNew - last_RotarRPMNew)>1500 &&(_IQabs(RotarRPMNew)<300 ||_IQabs(last_RotarRPMNew)<300) ){
+             //在0转速附近有大的阶跃
+             test3 = RotarRPMNew;
+             RotarRPMNew = 0;
+             last_speed = 0;
+
+         }
 
+      /*   if(RotarRPMNew - last_RotarRPMNew>500){
+             RotarRPMNew = last_RotarRPMNew+4;
+         }else if(RotarRPMNew - last_RotarRPMNew<-500){
+             RotarRPMNew = last_RotarRPMNew-4;
+         }*/
+         last_RotarRPMNew = RotarRPMNew;
+         RotarrpmOut = lowpassfilter(last_speed,RotarRPMNew,_IQ12(0.1),_IQ12(0.125));
+         last_speed = RotarrpmOut;
+
+         speed1.Speed = _IQdiv(RotarrpmOut,speed1.BaseRpm);
+         speed1.SpeedRpm = RotarrpmOut;
+  //   }
 }
 void speed_cal(void){
 
@@ -497,7 +667,11 @@ void speed_cal(void){
          XintTime = TIMER1_PER;
          Xint2Cnt = 1;
          CpuTimer1.RegsAddr->TCR.bit.TIF = 1;//写1清零
-
+         int count = 0;
+         for(count = 0;count<8;count++){
+                RotarrpmArr[count] = 0;
+            }
+         RotarrpmSum = 0;
          RotarRPMNew =0;
      }else{
          RotarRPMNew =(int32)360000000/XintTime;
@@ -523,16 +697,24 @@ void pwmlimit_speed(void){
         pwmlimit = (Uint32)(_IQabs(speed1.SpeedRpm)-index*50)*(pwm_limit_table1[index+1] - pwm_limit_table1[index])/50+pwm_limit_table1[index];
     }else  if(_IQabs(speed1.SpeedRpm)< 3500){
         Uint16 index = _IQabs(speed1.SpeedRpm)/100;
-        pwmlimit = (Uint32)(_IQabs(speed1.SpeedRpm)-index*100)*(pwm_limit_table2[index+1] - pwm_limit_table2[index])/100+pwm_limit_table2[index];
+        if(speed1.SpeedRpm>0){
+            pwmlimit = (Uint32)(_IQabs(speed1.SpeedRpm)-index*100)*(pwm_limit_table2[index+1] - pwm_limit_table2[index])/100+pwm_limit_table2[index];
+        }else{
+            pwmlimit = (Uint32)(_IQabs(speed1.SpeedRpm)-index*100)*(pwm_limit_table_neg[index+1] - pwm_limit_table_neg[index])/100+pwm_limit_table_neg[index];
+        }
 
     }else{
-        pwmlimit = 25240;//最大值
+        if(speed1.SpeedRpm>0){
+            pwmlimit = pwm_limit_table2[36];//最大值
+        }else{
+        pwmlimit = pwm_limit_table_neg[36];//最大值
+        }
     }
 }
 void taskfree(void){
 
 
-    if(SerialCommsTimer>4000){
+    if(SerialCommsTimer>(MAINLOOPFREQ/4)){
     GpioDataRegs.GPATOGGLE.bit.GPIO22 = 1;
 
     SerialCommsTimer = 0;
@@ -607,176 +789,13 @@ void mainLoop(void){
      }
 
      ServiceDog();
-     speed_cal();
+
+     //speed_cal();
+     speed_cal_filter();
      pwmlimit_speed();
      taskfree();
      FaultTreat();
 
- #if (BUILDLEVEL==LEVEL1)
-
- // ------------------------------------------------------------------------------
- //    Connect inputs of the RMP3 module and call the RAMP Control 3 macro.
- // ------------------------------------------------------------------------------
-       rmp3.DesiredInput = CmtnPeriodTarget;
-       rmp3.Ramp3Delay = RampDelay;
-       RC3_MACRO(&rmp3);
-
- // ------------------------------------------------------------------------------
- //    Connect inputs of the IMPULSE module and call the Impulse macro.
- // ------------------------------------------------------------------------------
-       impl1.Period = rmp3.Out;
-       IMPULSE_MACRO(&impl1);
-       HALL3_READ_MACRO(&hall1);
- // ------------------------------------------------------------------------------
- //    Connect inputs of the MOD6 module and call the Mod 6 counter macro.
- // ------------------------------------------------------------------------------
-       mod1.TrigInput = impl1.Out;
-       MOD6CNT_MACRO(&mod1);
-
- // ------------------------------------------------------------------------------
- //    Connect inputs of the PWM_DRV module and call the PWM signal generation
- //    update macro.
- // ------------------------------------------------------------------------------
-       pwm1.CmtnPointerIn = test2;//(int16)mod1.Counter;
-       if(EnableFlag == 0){
-           pwm1.DutyFuncIn = 0;
-       }else{
-           pwm1.DutyFuncIn = test;
-       }
-
-       BLDCPWM_MACRO(1,2,3,&pwm1);
-
-
- #endif // (BUILDLEVEL==LEVEL1)
- // =============================== LEVEL 3 ======================================
- //    Level 3 describes the closed-loop operation of sensored trapezoidal
- //    drive of BLDC motor using Hall sensor.
- // ==============================================================================
-
- #if (BUILDLEVEL==LEVEL3)
-
- // ------------------------------------------------------------------------------
- //    ADC conversion and offset adjustment (observing back-emfs is optinal for this prj.)
- // ------------------------------------------------------------------------------
-       BemfA =  _IQ12toIQ(AdcResult.ADCRESULT1);
-       BemfB =  _IQ12toIQ(AdcResult.ADCRESULT2);
-       BemfC =  _IQ12toIQ(AdcResult.ADCRESULT3);
-       DCbus_current = _IQ12toIQ(AdcResult.ADCRESULT4);//-_IQ(0.5); //1.65V offset added on HVDMC board.
-
- // ------------------------------------------------------------------------------
- //    Connect inputs of the RMP3 module and call the Ramp control 3 macro.
- // ------------------------------------------------------------------------------
-
-
-      HALL3_READ_MACRO(&hall1);
-
-      ClosedFlag=TRUE;
-
- // ------------------------------------------------------------------------------
- //    Connect inputs of the RMP2 module and call the Ramp control 2 macro.
- // ------------------------------------------------------------------------------
-       rmp2.DesiredInput = (int32)DFuncDesired;
-       RC2_MACRO(&rmp2);
-
- // ------------------------------------------------------------------------------
- //    Connect inputs of the PWM_DRV module and call the PWM signal generation
- //    update macro.
- // ------------------------------------------------------------------------------
-    if (ClosedFlag==TRUE)  {
-      if (hall1.CmtnTrigHall==0x7FFF) {
-
-       PreviousState = pwm1.CmtnPointer;
-
- // Comment the following if-else-if statements in case of
- // inverted Hall logics for commutation states.
-     /*  if (hall1.HallGpioAccepted==5)
-       { pwm1.CmtnPointer = 0;
-
-       }
-       else if (hall1.HallGpioAccepted==1)
-       { pwm1.CmtnPointer = 1;
-
-       }
-       else if (hall1.HallGpioAccepted==3)
-       { pwm1.CmtnPointer = 2;
-
-       }
-       else if (hall1.HallGpioAccepted==2)
-       { pwm1.CmtnPointer = 3;
-
-       }
-       else if (hall1.HallGpioAccepted==6)
-       {  pwm1.CmtnPointer = 4;
-
-       }
-       else if (hall1.HallGpioAccepted==4)
-       {
-           pwm1.CmtnPointer = 5;
-       }*/
-
-
-
-
- // Comment the following if-else-if statements in case of
- // non-inverted Hall logics for commutation states.
-       if (hall1.HallGpioAccepted==2)
-         pwm1.CmtnPointer = 0;
-
-       else if (hall1.HallGpioAccepted==6)
-         pwm1.CmtnPointer = 1;
-
-       else if (hall1.HallGpioAccepted==4)
-         pwm1.CmtnPointer = 2;
-
-       else if (hall1.HallGpioAccepted==5)
-         pwm1.CmtnPointer = 3;
-
-       else if (hall1.HallGpioAccepted==1)
-         pwm1.CmtnPointer = 4;
-
-       else if (hall1.HallGpioAccepted==3)
-         pwm1.CmtnPointer = 5;
-
-
-     }    //hall1.CmtnTrigHall == 0x7FFF
-   } // ClosedFlag==TRUE
-   else{
-       pwm1.CmtnPointer = (int16)mod1.Counter;
-   }
-       pwm1.DutyFunc = DfuncTesting;
-       BLDCPWM_MACRO(1,2,3,&pwm1);
-
- // ------------------------------------------------------------------------------
- //    Connect inputs of the SPEED_PR module and call the speed calculation macro.
- // ------------------------------------------------------------------------------
-   if ((pwm1.CmtnPointer==5)&&(PreviousState==4)&&(hall1.CmtnTrigHall==0x7FFF))
-   {
-        speed1.TimeStamp = VirtualTimer;
-        SPEED_PR_MACRO(&speed1);
-        test  = (test ==0 )? 1 : 0;
-   }
-
- // ------------------------------------------------------------------------------
- //    Connect inputs of the PWMDAC module
- // ------------------------------------------------------------------------------
-       pwmdac1.MfuncC1 = (int32)hall1.HallGpioAccepted<<20;
-       pwmdac1.MfuncC2 = BemfA;
-       PWMDAC_MACRO(6,pwmdac1)                           // PWMDAC 6A, 6B
-
-       pwmdac1.MfuncC1 = DCbus_current;
-       pwmdac1.MfuncC2 = (int32)mod1.Counter<<20;
-       PWMDAC_MACRO(7,pwmdac1)                           // PWMDAC 7A, 7B
-
- // ------------------------------------------------------------------------------
- //    Connect inputs of the DATALOG module
- // ------------------------------------------------------------------------------
-       DlogCh2 = (int16)mod1.Counter;
-       DlogCh1 = (int16)hall1.HallGpioAccepted;
-       DlogCh3 = (int16)_IQtoIQ15(BemfA);
-       DlogCh4 = (int16)_IQtoIQ15(BemfB);
-
-
- #endif // (BUILDLEVEL==LEVEL3)
 
  // =============================== LEVEL 4 ======================================
  //    Level 4 verifies the closed current loop and current PI controller.
@@ -786,113 +805,22 @@ void mainLoop(void){
         static Uint16 DC_Current_cnt = 0;
         //static int32 DC_Current_sum = 0;
         static int32 DC_Current_sum_filter = 0;
-
+       int32 dt = _IQ12(0.1);
+       int32 cutoff = _IQ12(1);
         DC_current_real = (Uint32)AdcResult.ADCRESULT5*33;//Q12  I真实 = adc * 3.3 / 4096 /0.1
-        DC_current_filer = lowpassfilter(last_DC_current,DC_current_real,_IQ12(1),_IQ12(0.05));
+        DC_current_filer = lowpassfilter(last_DC_current,DC_current_real,cutoff,dt);
         last_DC_current = DC_current_filer;
-        carveData1();
-        CanCurve();
-
-        UserCANprocess();
-
         DC_Current_sum_filter += DC_current_filer*pwm1.DutyFunc>>15;
-      //  DC_Current_sum += DC_current_real*pwm1.DutyFunc>>15;
         DC_Current_cnt++;//由于stall最多16384/20K秒 所以最多0.819715秒计算一次平均值
-
-
-
- #if (BUILDLEVEL==LEVEL4)
-        BemfA =  AdcResult.ADCRESULT1;
-        BemfB =  AdcResult.ADCRESULT2;
-        BemfC =  AdcResult.ADCRESULT3;
-
-       HALL3_READ_MACRO(&hall1);
-
-       if (hall1.Revolutions>=0)
-          ClosedFlag=TRUE;
- // ------------------------------------------------------------------------------
- //    电流闭环
- // ------------------------------------------------------------------------------
-       pid1_spd.Ref = _IQ(0.3);
-       pid1_spd.Fbk = _IQabs(speed1.Speed);
-      // tempIdc=pid1_idc.Fbk;
-       pid1_idc.Umax = pwmlimit<<9;
-       pid1_idc.Umin = (-pwmlimit)<<9;
-       pid1_idc.Ref = CurrentSet;//给定电流 反转给-
-       if(speed1.SpeedRpm<0){
-           pid1_idc.Fbk = -_IQ12toIQ(DC_current_filter_avr);// 电流改为Q15格式
-        }else{
-            pid1_idc.Fbk = _IQ12toIQ(DC_current_filter_avr);// 电流改为Q15格式
-       }
- //    if(pid1_idc.Fbk<0) pid1_idc.Fbk=tempIdc; // Eliminate negative values
-
-
-
-       step++;
-       if(step == 1){
-             PI_MACRO(&pid1_idc);
-        }else if(step == 2){
-            PI_MACRO(&pid1_spd);
-            step = 0;
-        }
-
-       if(EnableFlag == 0){
-            SetPI(&pid1_spd);
-            resetPI(&pid1_idc);
-            rmp2.DesiredInput = 0;
-            RC2_MACRO(&rmp2);
-            pwm1.DutyFuncIn = (int16)_IQtoIQ15(rmp2.Out);   // controlled speed duty-cycle
-
-        }else{
-              pwm1.DutyFuncIn = (int16)_IQtoIQ15(_IQmpy(pid1_idc.Out,pid1_spd.Out));   // controlled speed duty-cycle
-              rmp2.Out = pwm1.DutyFuncIn;
-             // pwm1.DutyFuncIn = (int16)(_IQtoIQ15(pid1_idc.Out));
+        if(hallCmtnTrig==1){
+            hallCmtnTrig = 0;
+            DC_current_filter_avr = DC_Current_sum_filter/DC_Current_cnt;
+            DC_Current_sum_filter =0;
+            DC_Current_cnt = 0;
         }
-
-
-     if (ClosedFlag==TRUE)
-     {
-      if (hall1.CmtnTrigHall==0x7FFF)
-      {
-          DC_current_avr = DC_Current_sum/DC_Current_cnt;
-          DC_current_filter_avr = DC_Current_sum_filter/DC_Current_cnt;
-          DC_Current_sum = 0;
-          DC_Current_sum_filter =0;
-          DC_Current_cnt = 0;
-          //计算速度
-          speed1.TimeStamp = VirtualTimer;
-          SPEED_PR_MACRO(&speed1,hall1.HallGpioAccepted,PreviousState,hall1.Stall_status);
-          PreviousState = hall1.HallGpioAccepted;
-          if (hall1.HallGpioAccepted==2)
-            pwm1.CmtnPointerIn = 0;
-
-          else if (hall1.HallGpioAccepted==6)
-            pwm1.CmtnPointerIn = 1;
-
-          else if (hall1.HallGpioAccepted==4)
-            pwm1.CmtnPointerIn = 2;
-
-          else if (hall1.HallGpioAccepted==5)
-            pwm1.CmtnPointerIn = 3;
-
-          else if (hall1.HallGpioAccepted==1)
-            pwm1.CmtnPointerIn = 4;
-
-          else if (hall1.HallGpioAccepted==3)
-          {     pwm1.CmtnPointerIn = 5;
-
-          }//hall1.HallGpioAccepted==3
-      }
-   }
-
-      BLDCPWM_MACRO(1,2,3,&pwm1);
-
- #endif // (BUILDLEVEL==LEVEL4)
-
-
- // =============================== LEVEL 5 ======================================
- //    Level 5 verifies the closed speed loop and speed PI controller.
- // ==============================================================================
+        carveData1();
+        CanCurve();
+        UserCANprocess();
 
  #if (BUILDLEVEL==LEVEL5)
 
@@ -902,13 +830,9 @@ void mainLoop(void){
        BemfA =  AdcResult.ADCRESULT1;
        BemfB =  AdcResult.ADCRESULT2;
        BemfC =  AdcResult.ADCRESULT3;
-       //DCbus_current = _IQ12toIQ(AdcResult.ADCRESULT5); //采样值<<12
 
-       rc1.TargetValue = SpeedRef;
-       RC_MACRO(&rc1);
 
-       HALL3_READ_MACRO(&hall1);
-       pid1_spd.Ref = rc1.SetpointValue;
+       pid1_spd.Ref = SpeedRef;//rc1.SetpointValue;
        pid1_spd.Fbk = speed1.Speed;
        if(EnableFlag == 0 || FaultFlag.all !=0){
            Enable_ALLOW = FALSE;
@@ -928,100 +852,18 @@ void mainLoop(void){
 
            PI_MACRO(&pid1_spd);
            int16 pwmtmp =(int16)_IQtoIQ15(pid1_spd.Out);
-           if((int16)_IQtoIQ15(pid1_spd.Out)>pwmlimit){
-               pwmtmp = pwmlimit;   // controlled speed duty-cycle
-           }else if((int16)_IQtoIQ15(pid1_spd.Out)<-pwmlimit){
-               pwmtmp = -pwmlimit;   // controlled speed duty-cycle
-           }else{
-               pwmtmp = (int16)_IQtoIQ15(pid1_spd.Out);   // controlled speed duty-cycle
-           }
 
+           //pwmtmp = test;//上位机开环控制
            pwm1.DutyFuncIn = ((int32)pwmtmp*LimitMotCtrTemp(600000))>>15;//1分钟降一次
-           //pwm1.DutyFuncIn = test;
-           rmp2.Out = pwm1.DutyFuncIn;
-       }
-
-
-       ClosedFlag = TRUE;
-    if (ClosedFlag==TRUE)
-    {
-
-      if (hall1.CmtnTrigHall==0x7FFF)
-      {
-
-     //  DC_current_avr = DC_Current_sum/DC_Current_cnt;
-       DC_current_filter_avr = DC_Current_sum_filter/DC_Current_cnt;
-      // DC_Current_sum = 0;
-       DC_Current_sum_filter =0;
-       DC_Current_cnt = 0;
-       speed_direction(hall1.HallGpioAccepted,PreviousState);
-
-       if (hall1.HallGpioAccepted==5)
-         { pwm1.CmtnPointerIn = 5;
-
-        }
-         else if (hall1.HallGpioAccepted==1)
-         { pwm1.CmtnPointerIn = 0;
-
-         }
-         else if (hall1.HallGpioAccepted==3)
-         { pwm1.CmtnPointerIn = 1;
-
-         }
-         else if (hall1.HallGpioAccepted==2)
-         { pwm1.CmtnPointerIn = 2;
-
-         }
-         else if (hall1.HallGpioAccepted==6)
-         {  pwm1.CmtnPointerIn = 3;
-
-         }
-         else if (hall1.HallGpioAccepted==4)
-         {
-             pwm1.CmtnPointerIn = 4;
-         }
-       PreviousState = hall1.HallGpioAccepted;
-       /*
-           if (hall1.HallGpioAccepted==2)
-             pwm1.CmtnPointerIn = 0;
-
-           else if (hall1.HallGpioAccepted==6)
-             pwm1.CmtnPointerIn = 1;
-
-           else if (hall1.HallGpioAccepted==4)
-             pwm1.CmtnPointerIn = 2;
-
-           else if (hall1.HallGpioAccepted==5)
-             pwm1.CmtnPointerIn = 3;
-
-           else if (hall1.HallGpioAccepted==1)
-             pwm1.CmtnPointerIn = 4;
 
-           else if (hall1.HallGpioAccepted==3)
-           {     pwm1.CmtnPointerIn = 5;
-
-           }//hall1.HallGpioAccepted==3
- */
-         //}//direction == Normal
-
-     }    // delay
-   }      // ClosedFlag==TRUE
-
-
-
-       if(Enable_ALLOW == 0 && pwm1.DutyFunc==0){
-           bldcpwm_close();
-
-        }else{
-            BLDCPWM_MACRO(1,2,3,&pwm1);
-
-        }
-
-      // BLDCPWM_MACRO(1,2,3,&pwm1);
- // ------------------------------------------------------------------------------
- //    Connect inputs of the DATALOG module
- // ------------------------------------------------------------------------------
+           if(pwm1.DutyFuncIn>pwmlimit){
+               pwm1.DutyFuncIn = pwmlimit;   // controlled speed duty-cycle
+           }else if(pwm1.DutyFuncIn<-pwmlimit){
+               pwm1.DutyFuncIn = -pwmlimit;   // controlled speed duty-cycle
+           }
 
+           rmp2.Out = pwm1.DutyFuncIn;
+       }
 
 
  #endif // (BUILDLEVEL==LEVEL5)
@@ -1029,9 +871,9 @@ void mainLoop(void){
        //IsrTime = MastIsrTimePercent();
        T2 = CpuTimer2.RegsAddr->TIM.all;
        if(T1 < T2){
-           IsrTime = (Uint32)(T1 +CpuTimer2.RegsAddr->PRD.all -T2)* 100 /6000;
+           IsrTime = (Uint32)(T1 +CpuTimer2.RegsAddr->PRD.all -T2)* 100 /7500;
        }else{
-          IsrTime = (Uint32)(T1-T2)* 100 /6000;
+          IsrTime = (Uint32)(T1-T2)* 100 /7500;
        }
 
 }

+ 14 - 13
UserSource/UserCan.c

@@ -12,6 +12,7 @@
 #define Normal 1
 // Global variable for this example
 #define TX_PERIOD 20 //ms
+
 //绘制曲线
 #pragma DATA_SECTION(CanCurveData,"MemoryFile");
 #pragma DATA_SECTION(CanCurveData2,"MemoryFile2");
@@ -252,7 +253,7 @@ void CanDebugTx(void)
 
     if (TxCnt >= TxPeriod)
     {
-        TxPeriod = TX_PERIOD*ISR_FREQUENCY;// =TX_PERIOD/1000/(1/ISR_FREQUENCY/1000)
+        TxPeriod = TX_PERIOD*MAINLOOPRATE;// =TX_PERIOD/1000/(1/mainloop)  mainloop = 8k
 
        TxCnt = 0;
         step++;
@@ -275,7 +276,7 @@ void CanDebugTx(void)
         CanMboxUserRegsT.MboxWord1 = speed1.SpeedRpm;//pid反馈速度 rpm
         CanMboxUserRegsT.MboxWord2 = _IQtoIQ15(pid1_spd.Out);//PID输出
         CanMboxUserRegsT.MboxWord3 = pwm1.DutyFunc;//占空比
-        CanMboxUserRegsT.MboxWord4 = 0;//0-5
+        CanMboxUserRegsT.MboxWord4 = test4;//0-5
 
         ECanMboxSend(&CanMboxUserRegsT);
         }else if(step ==3){
@@ -285,7 +286,7 @@ void CanDebugTx(void)
         CanMboxUserRegsT.MboxDLC = 8;
         CanMboxUserRegsT.MboxWord1 = pwmlimit;//过零点
         CanMboxUserRegsT.MboxWord2 = IsrTime;
-        CanMboxUserRegsT.MboxWord3 = test;
+        CanMboxUserRegsT.MboxWord3 = test2;
         CanMboxUserRegsT.MboxWord4 =0;
 
         ECanMboxSend(&CanMboxUserRegsT);
@@ -294,10 +295,10 @@ void CanDebugTx(void)
         CanMboxUserRegsT.MboxID = 0x11111306;
         CanMboxUserRegsT.MboxNum = 8;
         CanMboxUserRegsT.MboxDLC = 8;
-        CanMboxUserRegsT.MboxWord1 = _IQtoIQ15(pid1_idc.Out);//放大10倍
-        CanMboxUserRegsT.MboxWord2 = pid1_spd.Out>>15;
-        CanMboxUserRegsT.MboxWord3 = pid1_idc.up>>15;
-        CanMboxUserRegsT.MboxWord4 = pid1_idc.ui>>15;
+        CanMboxUserRegsT.MboxWord1 = hall1.HallGpioAccepted;//放大10倍
+        CanMboxUserRegsT.MboxWord2 = test4;
+        CanMboxUserRegsT.MboxWord3 = test3;
+        CanMboxUserRegsT.MboxWord4 = XintTime>>16;
 
         ECanMboxSend(&CanMboxUserRegsT);
 
@@ -344,13 +345,13 @@ void carveData1(){
     //当发送标志位为0时,采集并记录模拟数据,但不发送
      if (CanCurveFlag == 0)
      {
-         DebugData1(0,_IQtoIQ12(pid1_spd.Ref)*speed1.BaseRpm*10>>12);
-         DebugData1(1,speed1.SpeedRpm*10);
-         DebugData1(2,pwm1.DutyFunc);
+         DebugData1(0,0);
+         DebugData1(1,0);
+         DebugData1(2,0);
          DebugData1(3,0);
 
-         DebugData2(0,0);
-         DebugData2(1,0);
+         DebugData2(0,test2*10);
+         DebugData2(1,speed1.SpeedRpm*10);
          DebugData2(2,0);
          DebugData2(3,0);
      }
@@ -368,7 +369,7 @@ void CanCurve(void)
     if (DubugCnt >= DubugPer)
     {
         //发送间隔数据
-        DubugPer = TX_PERIOD*ISR_FREQUENCY;
+        DubugPer = TX_PERIOD*MAINLOOPRATE;
         DubugCnt = 0;
         //当发送标志位为1时,发送绘图波形数据
         if (CanCurveFlag == 1)

+ 1 - 1
UserSource/UserCan.h

@@ -30,7 +30,7 @@ extern "C" {
 
 
 #define EXTFRAME 0x80000000
-#define ISR_FREQUENCY 20
+#define ISR_FREQUENCY 40
 #ifndef TRUE
 #define FALSE 0
 #define TRUE  1

+ 2 - 1
UserSource/lowpass.c

@@ -6,7 +6,8 @@
  */
 #include "lowpass.h"
 // cutoff  khz ,Ts ms
-long a1,a2,a3,a4;
+
+//cutoff Ts Q12
 long lowpassfilter(long sample_1,long sample,long cutoff,long Ts)
 {
     //1.0f/(M_2PI*cutoff)  rc =  1.0f/(M_2PI*cutoff)

+ 38 - 12
UserSource/var.c

@@ -16,6 +16,8 @@ Uint16 DCbus_voltage=0;
 Uint32 IsrTime = 0;
 _iq test =0;
 int16 test2 =0;
+int16 test3 =0;
+int16 test4 =0;
 int16 Tmotor = 0;
 PI_CONTROLLER pid1_idc = PI_CONTROLLER_DEFAULTS;
 PI_CONTROLLER pid1_spd = PI_CONTROLLER_DEFAULTS;
@@ -46,8 +48,8 @@ void InitVar(void){
     pid1_idc.Umax = _IQ((float)pwmlimit/32767);
     pid1_idc.Umin = _IQ((float)(-pwmlimit)/32767);
     // Initialize the PI module for speed
-    pid1_spd.Kp   = _IQ(1.0);
-    pid1_spd.Ki   = 360;//_IQ(0.0002);
+    pid1_spd.Kp   = 16384;
+    pid1_spd.Ki   = 1638;
     pid1_spd.Umax = _IQ(1.0);
     pid1_spd.Umin = _IQ(0.0);
 
@@ -60,25 +62,43 @@ void InitVar(void){
 
 }
 void FaultTreat(void){
+    if(hall1.HallGpio == 0 || hall1.HallGpio == 7){
+        FaultFlag.bit.HallFlag =1;
+    }
     OverVoltage();
     OverMotorRpm();
     OverMotCtrTemp();
+    SoftOverCurFlag();
     Fault_clear_fuc();
 }
+//I真实 = adc * 3.3 / 4096 /0.1
+void SoftOverCurFlag(void){
+    static int16 cnt = 0;
+    if(DC_current_filer>((Uint32)SOFTCURlIMIT<<12)){
+        cnt++;
+        if(cnt>10000/MAINLOOPTIME){// us
+            cnt = 10000/MAINLOOPTIME+1;
+            FaultFlag.bit.SoftOverCurFlag = 1;
+            t4 = DC_current_filer;
+        }
+    }else{
+        cnt = 0;
+    }
 
+}
 void OverVoltage(void)
 {
 //过压不可恢复  欠压可恢复
 
     static int16 j = 0;
 
-    if (DCbus_voltage >= 360)
+    if (DCbus_voltage >= VOLTAGEUP)
     {
         FaultFlag.bit.OverVolFlag = 1;
     }
-    else if (DCbus_voltage <= 200)  //80
+    else if (DCbus_voltage <= VOLTAGELOW)
     {
-        j = 10000;
+        j = MAINLOOPFREQ;
         FaultFlag.bit.LowVolFlag = 1;
     }
     else
@@ -100,7 +120,7 @@ void OverVoltage(void)
 }
 void OverMotorRpm(void)
 {//飞车不可恢复
-    if (speed1.BaseRpm >= 3800)
+    if (speed1.BaseRpm >= SPEEDUP)
     {
         FaultFlag.bit.OverRpmFlag = 1;
     }
@@ -109,15 +129,15 @@ void OverMotorRpm(void)
 void OverMotCtrTemp(void)
 {//过温可恢复
 
-    if (Tmotor >= 100)
+    if (Tmotor >= MOTORTEMPOVER)
     {
         FaultFlag.bit.OverMotTempFlag = 1;
     }
-    else if (Tmotor < 50)
+    else if (Tmotor < MOTORTEMPLIMIT)
     {
         FaultFlag.bit.OverMotTempFlag = 0;
     }
-    if (Tvot >= 70)
+    if (Tvot >= IGBTTEMPOVER)
     {
         FaultFlag.bit.IgbtTempFaultFlag = 1;
     }
@@ -133,7 +153,7 @@ void Fault_clear_fuc(void){
          GpioDataRegs.GPBCLEAR.bit.GPIO32 = 1;
          FaultFlag.bit.OverCurFlag = 0;
          fault_cnt++;
-         if(fault_cnt>20000){
+         if(fault_cnt>MAINLOOPFREQ){
          Fault_clear = 0;
          fault_cnt = 0;
          OpenPwm();
@@ -149,21 +169,26 @@ void Fault_clear_fuc(void){
          if(FaultFlag.bit.OverVolFlag == 1 && DCbus_voltage<320){
              FaultFlag.bit.OverVolFlag = 0;
          }
+         FaultFlag.bit.HallFlag =0;
 
      }else{
          GpioDataRegs.GPBSET.bit.GPIO32 = 1;
      }
+    if(EnableFlag == 0 && pwm1.DutyFunc==0){
+         FaultFlag.bit.SoftOverCurFlag = 0;//失能清软件过流
+    }
 }
 int16 LimitMotCtrTemp(int32 period){
     static int16 result = 32767;
     static int32 cnt1=0;
     static int32 cnt2=0;
 
-    if(Tmotor>30){
+    if(Tmotor>MOTORTEMPLIMIT){
         cnt1++;
         cnt2 = 0;
         if(cnt1>period){
             result = (int32)result*31128>>15;
+            FaultFlag.bit.LimitMotTempFlag = 1;
             cnt1 =0;
         }
 
@@ -183,10 +208,11 @@ int16 LimitMotCtrTemp(int32 period){
 
         }else{
             result = 32767;
+            FaultFlag.bit.LimitMotTempFlag = 0;
             cnt2 = 0;
         }
 
     }
-    test = result;
+    //test = result;
     return result;
 }

+ 22 - 2
UserSource/var.h

@@ -26,18 +26,33 @@ typedef float           float32;
 typedef long double     float64;
 #endif
 
+#define SOFTCURlIMIT 8 //A
+#define MAINLOOPRATE 8 //Khz
+#define MAINLOOPTIME 125 //US
+#define VOLTAGEUP 350 //V
+#define VOLTAGELOW 200 //V
+#define SPEEDUP 3800 //RPM
+
+#define MOTORTEMPLIMIT 70 //
+#define MOTORTEMPOVER 90 //
+#define IGBTTEMPOVER 70 //
+
+#define MAINLOOPFREQ 8000
 struct FAULTFLAG_STR
 {
     Uint16 OverMotTempFlag:1;
     Uint16 IgbtTempFaultFlag:1;
     Uint16 LowVolFlag:1;
-    Uint16 rsv1:5;
+    Uint16 SoftOverCurFlag:1;
+    Uint16 LimitMotTempFlag:1;
+    Uint16 rsv1:3;
 
     Uint16 OverVolFlag:1;
     Uint16 CanErrFlag:1;
     Uint16 OverCurFlag:1;
     Uint16 Ipmfault:1;
     Uint16 OverRpmFlag:1;
+    Uint16 HallFlag:1;
     Uint16 rsv2:3;
 
 
@@ -53,6 +68,8 @@ extern union FAULTFLAG_UNI FaultFlag;
 extern Uint32 IsrTime;
 extern _iq test ;
 extern int16 test2;
+extern int16 test3;
+extern int16 test4;
 extern int16 Tmotor;
 extern PI_CONTROLLER pid1_idc;
 extern PI_CONTROLLER pid1_spd;
@@ -78,6 +95,7 @@ extern int32 DC_current_avr;
 extern int32 DC_current_filter_avr;
 extern Uint16 Fault_clear;
 extern int32 XintTime;
+extern int16 t4;
 extern volatile Uint16 EnableFlag;
 extern volatile Uint16 Enable_ALLOW;
 extern void InitVar(void);
@@ -88,5 +106,7 @@ extern void OverMotorRpm(void);
 extern void OpenPwm(void);
 extern void Fault_clear_fuc(void);
 extern int16 LimitMotCtrTemp(int32 period);
-
+extern void SoftOverCurFlag(void);
+extern void speed_cal_filter(void);
+extern void carveData2();
 #endif /* USERSOURCE_VAR_H_ */

+ 1 - 1
include/libs/app_libs/motor_control/drivers/f2803x_v2.0/f2803xhall_gpio.h

@@ -39,7 +39,7 @@ Default Initializer for the F2803X HALL3 Object
 #define F2803XHALL3      {0,  \
                           0,  \
                           0,  \
-                         5,  \
+                         3,  \
                           0,  \
                           0,  \
                           0,  \

+ 3 - 3
include/libs/app_libs/motor_control/math_blocks/v4.0/speed_pr.c

@@ -6,7 +6,7 @@ File name:        SPEED_PR.C
 #include "speed_pr.h"
 
 long StatorRpmSum = 0;
-long StatorArr[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};//,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,};
+long StatorArr[8] = {0,0,0,0,0,0,0,0};//,0,0,0,0,0,0,0,0};//,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,};
 void SPEED_PR_MACRO(SPEED_MEAS_CAP *v,unsigned int hall,unsigned int hall_last,unsigned int stall_status)	{
     static int j = 0;
 
@@ -30,10 +30,10 @@ void SPEED_PR_MACRO(SPEED_MEAS_CAP *v,unsigned int hall,unsigned int hall_last,u
 
           StatorArr[j] = StatorRpm;
           StatorRpmSum += StatorArr[j];
-          v->EventPeriod = StatorRpmSum >> 4;
+          v->EventPeriod = StatorRpmSum >> 3;
 
           j++;
-          if (j >= 16)
+          if (j >= 8)
           {
                j = 0;
            }

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff