Forráskód Böngészése

Merge remote-tracking branch 'remotes/origin/city_riding' into VR7500

# Conflicts:
#	Core/Src/can.c
#	Core/Src/main.c
#	MDK-ARM/JLinkLog.txt
#	MDK-ARM/bin/QD007A_CTL_APP.bin
#	User/Inc/speed_sensor.h
#	User/Src/motor_control.c
#	User/Src/var.c
#	修改说明.txt
V5.2.0_20200917
1、基于V5.1.0_20200615,结合V2.1.5_20200904版本进行改动;
2、相对于V2.1.5_20200904版本,该版本的差异如下:
  a) 速度的计算,除了根据传感器和踏频两种方式外,增加了根据通信获取车轮转速的方式及骑行里程的统计,0x55-车轮触发,0x-AA踏频计算,0xEE-通讯获取车轮旋转周期;
  b) CAN的接收处理中,屏蔽PBU/OBC的指令,打开ECU指令,并增加车轮转速信息的获取;
  c) 检测PBU/OBC/ECU通信超时的时间由1s改为30s
  d) 版本号V5.2.0_20200917
dail.zhou 4 éve
szülő
commit
6c1faedd05
38 módosított fájl, 641 hozzáadás és 797 törlés
  1. 23 3
      Core/Src/adc.c
  2. 1 1
      Core/Src/can.c
  3. 15 7
      Core/Src/main.c
  4. 10 13
      J-scope.jscope
  5. 110 0
      MDK-ARM/JLinkLog.txt
  6. 5 0
      MDK-ARM/QD007A_CTL_APP.uvprojx
  7. BIN
      MDK-ARM/bin/MC_VOLANS_V2r0r2_20200426.bin
  8. BIN
      MDK-ARM/bin/MC_VOLANS_V2r0r2_20200427.bin
  9. BIN
      MDK-ARM/bin/MC_VOLANS_V2r0r3_20200427.bin
  10. BIN
      MDK-ARM/bin/MC_VOLANS_V2r0r4_20200603_SendToArno.bin
  11. BIN
      MDK-ARM/bin/MC_VOLANS_V2r0r4_20200615.bin
  12. BIN
      MDK-ARM/bin/MC_VOLANS_V2r1r0_20200717.bin
  13. BIN
      MDK-ARM/bin/MC_VOLANS_V2r1r1_20200720.bin
  14. BIN
      MDK-ARM/bin/MC_VOLANS_V2r1r2_20200812.bin
  15. BIN
      MDK-ARM/bin/MC_VOLANS_V2r1r3_20200814.bin
  16. BIN
      MDK-ARM/bin/MC_VOLANS_V2r1r3_20200821.bin
  17. BIN
      MDK-ARM/bin/MC_VOLANS_V2r1r3_20200821_1.bin
  18. BIN
      MDK-ARM/bin/MC_VOLANS_V2r1r5_20200904.bin
  19. BIN
      MDK-ARM/bin/MC_VR7500_V5r2r0_20200917.bin
  20. BIN
      MDK-ARM/bin/QD007A_CTL_APP.bin
  21. 69 30
      SelfTestUser/src_middlewares/stm32f1xx_STUperipheralRegisters.c
  22. 0 3
      User/Inc/battery_info.h
  23. 1 0
      User/Inc/cadence_sensor.h
  24. 0 10
      User/Inc/motor_control.h
  25. 1 1
      User/Inc/remain_distance.h
  26. 4 2
      User/Inc/var.h
  27. 16 16
      User/Src/MC_PID_regulators.c
  28. 87 10
      User/Src/cadence_sensor.c
  29. 13 6
      User/Src/math_tools.c
  30. 82 595
      User/Src/motor_control.c
  31. 17 10
      User/Src/protect_check.c
  32. 18 14
      User/Src/remain_distance.c
  33. 1 1
      User/Src/speed_sensor.c
  34. 16 0
      User/Src/stm32f10x_svpwm_3shunt.c
  35. 2 2
      User/Src/tasks.c
  36. 1 1
      User/Src/tim.c
  37. 75 72
      User/Src/var.c
  38. 74 0
      修改说明.txt

+ 23 - 3
Core/Src/adc.c

@@ -435,8 +435,9 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
 	}
 	
 	//更新母线电压 
-	BusVoltageFltSum += ((ADC1_Result[ADC1_RANK_VIN] << 10) - BusVoltageFltSum) >> 8;
-	MC_RunInfo.BusVoltage = (uint32_t)((BusVoltageFltSum >> 10) * 18507) >> 10;//3300 * 1256 / (4095 * 56)
+	BusVoltageFltSum += ((ADC1_Result[ADC1_RANK_VIN] << 10) - BusVoltageFltSum) >> 9;
+	MC_RunInfo.BusVoltage = (uint32_t)((BusVoltageFltSum >> 10) * 18382) >> 10; //3300 * 1047 / (4095 * 47)
+	MC_RunInfo.BusVoltage += (MC_RunInfo.BusCurrent >> 7) * 26; //根据母线电流和估算的线阻进行补偿, 补偿电阻 0.2 * 128 = 25.6
 	
 	//更新绕组温度
 	T_Coil_Sum += ADC1_Result[ADC1_RANK_NTC_COIL];
@@ -458,7 +459,26 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
 	Temp_32 = (ADC1_Result[ADC1_RANK_TORQUE_SENSOR] - TorqueOffSetData.PresentData) * 100 / MC_TorqueCorrectParam.K;
 	Temp_32 = ((Temp_32 <= 0) ? 0 : Temp_32);
 	#if 1 //采用原始采集值
-	ADC_SensorData.TorqueSensor = Temp_32;
+		#if 1 //正常运行
+		ADC_SensorData.TorqueSensor = Temp_32;
+		#else //用于寿命测试,模拟输入力矩
+		if(HAL_GetTick() < 5000)
+		{
+			Temp_32 = 0;
+		}
+		else
+		{
+			static uint32_t WaveTime_Zero = 0;
+			static uint32_t Time_Enter = 0;
+			if((HAL_GetTick() - Time_Enter) > 10) // ??10ms???,??????????
+			{
+				WaveTime_Zero = HAL_GetTick();
+			}
+			Time_Enter = HAL_GetTick();
+			Temp_32  = TriangleWaveGenerate(WaveTime_Zero, 250, 500 ,1500);  
+		}
+		ADC_SensorData.TorqueSensor = Temp_32;		
+		#endif
 	#else  //采用滤波值
 	static int32_t TorqueFltSum = 0;
 	TorqueFltSum += ((Temp_32 << 10) - TorqueFltSum) >> 8;

+ 1 - 1
Core/Src/can.c

@@ -116,7 +116,7 @@ void HAL_CAN_MspInit(CAN_HandleTypeDef* canHandle)
     canHandle->pTxMsg = &CAN_TxMessaage;
 		canHandle->pRxMsg = &CAN_RxMessaage;
 		CANFilterConfig_Scale32_IdMask_StandardIdOnly();
-		__HAL_CAN_ENABLE_IT(&hcan, CAN_IT_FMP0);
+		__HAL_CAN_ENABLE_IT(&hcan, CAN_IT_FMP0);		
   /* USER CODE END CAN1_MspInit 1 */
   }
 }

+ 15 - 7
Core/Src/main.c

@@ -65,6 +65,7 @@
 #include "ICM20600.h"
 #include "ctf_process.h"
 #include "log_save.h"
+#include "flash_read_protection.h"
 
 /* USER CODE END Includes */
 
@@ -98,7 +99,7 @@ int main(void)
   IAP_Init();  //Bootloader 200ms
 	
   //Flash读保护设置
-  #if 0
+  #if 1
   Flash_ReadProtection();
   #endif
 		
@@ -181,9 +182,6 @@ int main(void)
 	
 	//MC控制初始化
 	MC_Init();//145ms
-
-	//续航里程计算变量初始化
-	RD_RemainDis_Init(MC_ConfigParam1.WheelSize + MC_ConfigParam1.WheelSizeAdj, (uint32_t)((ADC1_Result[ADC1_RANK_VIN] * 18507) >> 10) / 10, MC_MotorParam.Rate_Voltage);
 	
 	//检查电机是否授权
 	#if 0	
@@ -200,7 +198,7 @@ int main(void)
 		MC_DeviceCheck(&PBU_CheckInfo, &MC_ErrorCode);
 		#endif
 		
-		#if 1 //校验仪表
+		#if 1 //校验仪表
 		MC_DeviceCheck(&HMI_CheckInfo, &MC_ErrorCode);
 		#endif
 	#endif
@@ -269,8 +267,18 @@ int main(void)
 			LightDriver_Process(MC_ControlCode.LightSwitch);
 			
 			//续航里程计算
-			RD_CalculateRemainDis(MC_SpeedSensorData.WheelTurnCount, BMS_RunInfo.RC, BMS_RunInfo.SOC, MC_RunInfo.BusCurrent);
-			RD_SaveAndUpdateInfo(MC_ControlCode.GearSt, MC_CalParam.AssistRunMode);
+			if(HAL_GetTick() > 2000)
+			{
+				static uint8_t RD_RemainDis_InitFinished = 0x00;
+				if(RD_RemainDis_InitFinished == 0x00)
+				{
+					RD_RemainDis_InitFinished = 0x01;
+					//续航里程计算变量初始化
+					RD_RemainDis_Init(MC_ConfigParam1.WheelSize + MC_ConfigParam1.WheelSizeAdj, IsComOK_BMS.IsOK_Flag, MC_RunInfo.BusVoltage / 10, MC_MotorParam.Rate_Voltage, BMS_RunInfo.RC);	
+				}
+				RD_CalculateRemainDis(MC_SpeedSensorData.WheelTurnCount, BMS_RunInfo.RC, BMS_RunInfo.SOC, MC_RunInfo.BusCurrent);
+				RD_SaveAndUpdateInfo(MC_ControlCode.GearSt, MC_CalParam.AssistRunMode);
+			}
 			
 			//更新电机运行信息
 			MC_RunInfo_Update();

+ 10 - 13
J-scope.jscope

@@ -4,13 +4,13 @@
     <Project>
         <Configuration>
             <JLink>
-                <Options IsRTTSession="0" IsRTTWithTimeStamp="1" SamplingPeriod="100" Connection="1" SerialNo="0" IP="" TargetDevice="Cortex-M3" TargetInterface="SWD" InterfaceSpeed="4000" />
+                <Options IsRTTSession="0" IsRTTWithTimeStamp="1" SamplingPeriod="100" Connection="1" SerialNo="0" IP="" TargetDevice="STM32F103R8" TargetInterface="SWD" InterfaceSpeed="4000" />
             </JLink>
-            <ElfFile Name="D:\SoftDesign\20190311_QD007A_CTL\QD007E_CTRL_APP\QD007E_CTRL_APP\MDK-ARM\QD007A_CTL_APP\QD007A_CTL_APP.axf" />
+            <ElfFile Name="C:\Users\xuwei\Desktop\Motor\QD007E_20190711\QD007E_CTRL_APP\MDK-ARM\QD007A_CTL_APP\QD007A_CTL_APP.axf" />
             <DataFile Name="" />
             <RawFile Name="" />
             <Scope>
-                <Options TimeResolutionUs="200000" />
+                <Options TimeResolutionUs="100000" />
             </Scope>
         </Configuration>
         <Windows>
@@ -19,28 +19,25 @@
         </Windows>
         <SelectedSymbols>
             <Symbol>
-                <Options Name="TorqueRefEnd" Address="0x200000C6" Type="short" TypeID="11" Size="2" GraphColorRed="255" GraphColorGreen="215" GraphColorBlue="0" YMinSampled="0" YMaxSampled="485" YAvgSampled="99" Offset="4" ShowInGraph="1" YOffset="200" IsAutoConfig="1" YResolution="1000" MaxValue="2000" File="..\User\Src\motor_control.c" Scope="0" DrawStyle="0" />
+                <Options Name="ADC1_Result[0]" Address="0x20001400" Type="ushort" TypeID="11" Size="2" GraphColorRed="255" GraphColorGreen="215" GraphColorBlue="0" YMinSampled="-1" YMaxSampled="1681" YAvgSampled="1621" Offset="4" ShowInGraph="0" YOffset="0" IsAutoConfig="0" YResolution="1000" MaxValue="2000" File="..\Core\Src\adc.c" Scope="0" DrawStyle="0" />
             </Symbol>
             <Symbol>
-                <Options Name="torqueAppRatio" Address="0x20000124" Type="short" TypeID="11" Size="2" GraphColorRed="160" GraphColorGreen="32" GraphColorBlue="240" YMinSampled="0" YMaxSampled="485" YAvgSampled="484" Offset="6" ShowInGraph="1" YOffset="200" IsAutoConfig="1" YResolution="1000" MaxValue="2000" File="..\User\Src\motor_control.c" Scope="0" DrawStyle="0" />
+                <Options Name="ADC1_Result[1]" Address="0x20001402" Type="ushort" TypeID="11" Size="2" GraphColorRed="0" GraphColorGreen="255" GraphColorBlue="0" YMinSampled="-1" YMaxSampled="2058" YAvgSampled="1923" Offset="6" ShowInGraph="1" YOffset="200" IsAutoConfig="0" YResolution="500" MaxValue="2000" File="..\Core\Src\adc.c" Scope="0" DrawStyle="0" />
             </Symbol>
             <Symbol>
-                <Options Name="SensorDataDebug" Address="0x2000016C" Type="ushort" TypeID="7" Size="2" GraphColorRed="255" GraphColorGreen="0" GraphColorBlue="0" YMinSampled="0" YMaxSampled="1500" YAvgSampled="773" Offset="8" ShowInGraph="1" YOffset="200" IsAutoConfig="0" YResolution="500" MaxValue="100000" File="..\User\Src\motor_control.c" Scope="1" DrawStyle="0" />
+                <Options Name="ADC1_Result[2]" Address="0x20001404" Type="ushort" TypeID="11" Size="2" GraphColorRed="0" GraphColorGreen="0" GraphColorBlue="176" YMinSampled="-1" YMaxSampled="3148" YAvgSampled="1821" Offset="8" ShowInGraph="0" YOffset="0" IsAutoConfig="0" YResolution="1000" MaxValue="4000" File="..\Core\Src\adc.c" Scope="0" DrawStyle="0" />
             </Symbol>
             <Symbol>
-                <Options Name="torqueApp2" Address="0x2000011E" Type="short" TypeID="11" Size="2" GraphColorRed="0" GraphColorGreen="191" GraphColorBlue="255" YMinSampled="0" YMaxSampled="33" YAvgSampled="32" Offset="10" ShowInGraph="0" YOffset="200" IsAutoConfig="1" YResolution="50" MaxValue="100" File="..\User\Src\motor_control.c" Scope="0" DrawStyle="0" />
+                <Options Name="ADC1_Result[3]" Address="0x20001406" Type="ushort" TypeID="11" Size="2" GraphColorRed="255" GraphColorGreen="0" GraphColorBlue="0" YMinSampled="-1" YMaxSampled="2059" YAvgSampled="1987" Offset="10" ShowInGraph="0" YOffset="180" IsAutoConfig="0" YResolution="1000" MaxValue="2000" File="..\Core\Src\adc.c" Scope="0" DrawStyle="0" />
             </Symbol>
             <Symbol>
-                <Options Name="torqueRank" Address="0x20000110" Type="ushort" TypeID="7" Size="2" GraphColorRed="255" GraphColorGreen="215" GraphColorBlue="0" YMinSampled="0" YMaxSampled="33" YAvgSampled="29" Offset="12" ShowInGraph="1" YOffset="200" IsAutoConfig="0" YResolution="20" MaxValue="45" File="..\User\Src\motor_control.c" Scope="0" DrawStyle="0" />
+                <Options Name="ADC1_Result[4]" Address="0x20001408" Type="ushort" TypeID="11" Size="2" GraphColorRed="0" GraphColorGreen="255" GraphColorBlue="255" YMinSampled="-1" YMaxSampled="1063" YAvgSampled="1023" Offset="12" ShowInGraph="0" YOffset="190" IsAutoConfig="0" YResolution="200" MaxValue="1000" File="..\Core\Src\adc.c" Scope="0" DrawStyle="0" />
             </Symbol>
             <Symbol>
-                <Options Name="torqueRankLast" Address="0x20000112" Type="ushort" TypeID="7" Size="2" GraphColorRed="255" GraphColorGreen="215" GraphColorBlue="0" YMinSampled="0" YMaxSampled="33" YAvgSampled="29" Offset="14" ShowInGraph="1" YOffset="200" IsAutoConfig="0" YResolution="20" MaxValue="1" File="..\User\Src\motor_control.c" Scope="1" DrawStyle="0" />
+                <Options Name="SOC" Address="0x200006C3" Type="uchar" TypeID="6" Size="1" GraphColorRed="0" GraphColorGreen="191" GraphColorBlue="255" YMinSampled="0" YMaxSampled="255" YAvgSampled="32" Offset="14" ShowInGraph="1" YOffset="200" IsAutoConfig="0" YResolution="100" MaxValue="481" File="..\User\Src\var.c" Scope="0" DrawStyle="0" />
             </Symbol>
             <Symbol>
-                <Options Name="flagUpDown" Address="0x20000116" Type="uchar" TypeID="6" Size="1" GraphColorRed="0" GraphColorGreen="255" GraphColorBlue="0" YMinSampled="0" YMaxSampled="1" YAvgSampled="0" Offset="16" ShowInGraph="1" YOffset="200" IsAutoConfig="1" YResolution="1" MaxValue="4" File="..\User\Src\motor_control.c" Scope="1" DrawStyle="0" />
-            </Symbol>
-            <Symbol>
-                <Options Name="candenceCount" Address="0x2000010A" Type="ushort" TypeID="7" Size="2" GraphColorRed="0" GraphColorGreen="0" GraphColorBlue="176" YMinSampled="0" YMaxSampled="22" YAvgSampled="16" Offset="17" ShowInGraph="1" YOffset="200" IsAutoConfig="1" YResolution="10" MaxValue="45" File="..\User\Src\motor_control.c" Scope="0" DrawStyle="0" />
+                <Options Name="BusVoltage" Address="0x200006BA" Type="ushort" TypeID="7" Size="2" GraphColorRed="0" GraphColorGreen="0" GraphColorBlue="255" YMinSampled="0" YMaxSampled="65535" YAvgSampled="34055" Offset="15" ShowInGraph="1" YOffset="200" IsAutoConfig="1" YResolution="20000" MaxValue="93400" File="..\User\Src\var.c" Scope="0" DrawStyle="0" />
             </Symbol>
         </SelectedSymbols>
     </Project>

+ 110 - 0
MDK-ARM/JLinkLog.txt

@@ -1,4 +1,5 @@
 
+<<<<<<< HEAD
 T27A0 000:313 SEGGER J-Link V4.98e Log File (0002ms, 0292ms total)
 T27A0 000:313 DLL Compiled: May  5 2015 11:00:52 (0002ms, 0292ms total)
 T27A0 000:313 Logging started @ 2020-04-26 11:15 (0002ms, 0292ms total)
@@ -1945,3 +1946,112 @@ T27A0 144:062 JLINK_ReadMem (0x0801508E, 0x0002 Bytes, ...) -- Read from C cache
 T27A0 144:649 JLINK_Close() -- CPU_ReadMem(4 bytes @ 0xE0001000) >0x42 TIF> >0x28 TIF> >0x0D TIF> >0x21 TIF> (0009ms, 1234ms total)
 T27A0 144:649  (0009ms, 1234ms total)
 T27A0 144:649 Closed (0009ms, 1234ms total)
+=======
+T1864 000:306 SEGGER J-Link V5.12e Log File (0001ms, 0263ms total)
+T1864 000:306 DLL Compiled: Apr 29 2016 15:03:58 (0001ms, 0263ms total)
+T1864 000:306 Logging started @ 2020-09-03 10:59 (0001ms, 0263ms total)
+T1864 000:307 JLINK_SetWarnOutHandler(...) (0000ms, 0263ms total)
+T1864 000:307 JLINK_OpenEx(...)
+Firmware: J-Link V9 compiled Sep  1 2016 18:29:50
+Hardware: V9.70
+S/N: 59700618
+Feature(s): RDI, FlashBP, FlashDL, JFlash, GDB  returns O.K. (0264ms, 0527ms total)
+T1864 000:571 JLINK_SetErrorOutHandler(...) (0000ms, 0527ms total)
+T1864 000:571 JLINK_ExecCommand("ProjectFile = "C:\Users\xuwei\Desktop\Motor\QD007E_20190711\QD007E_CTRL_APP\MDK-ARM\JLinkSettings.ini"", ...)  returns 0x00 (0001ms, 0528ms total)
+T1864 000:572 JLINK_ExecCommand("Device = STM32F103RB", ...)Device "STM32F103RB" selected.  returns 0x00 (0000ms, 0528ms total)
+T1864 000:572 JLINK_ExecCommand("DisableConnectionTimeout", ...)  returns 0x01 (0000ms, 0528ms total)
+T1864 000:572 JLINK_GetHardwareVersion()  returns 0x17AE8 (0000ms, 0528ms total)
+T1864 000:572 JLINK_GetDLLVersion()  returns 51205 (0000ms, 0528ms total)
+T1864 000:572 JLINK_GetFirmwareString(...) (0000ms, 0528ms total)
+T1864 000:573 JLINK_GetDLLVersion()  returns 51205 (0000ms, 0528ms total)
+T1864 000:573 JLINK_GetCompileDateTime() (0000ms, 0528ms total)
+T1864 000:573 JLINK_GetFirmwareString(...) (0000ms, 0528ms total)
+T1864 000:573 JLINK_GetHardwareVersion()  returns 0x17AE8 (0000ms, 0528ms total)
+T1864 000:573 JLINK_TIF_Select(JLINKARM_TIF_SWD)  returns 0x00 (0001ms, 0529ms total)
+T1864 000:574 JLINK_SetSpeed(5000) (0000ms, 0529ms total)
+T1864 000:574 JLINK_GetId() >0x108 TIF>Found SWD-DP with ID 0x1BA01477 >0x0D TIF> >0x28 TIF> >0x0D TIF> >0x28 TIF> >0x0D TIF> >0x28 TIF> >0x0D TIF> >0x28 TIF> >0x0D TIF> >0x21 TIF> >0x0D TIF> >0x28 TIF> >0x0D TIF> >0x28 TIF> >0x0D TIF> >0x28 TIF> >0x0D TIF> >0x21 TIF> >0x0D TIF> >0x21 TIF> >0x0D TIF> >0x28 TIF> >0x0D TIF> >0x21 TIF> >0x0D TIF> >0x21 TIF> >0x0D TIF> >0x28 TIF> >0x0D TIF> >0x21 TIF> >0x0D TIF> >0x21 TIF> >0x0D TIF> >0x28 TIF> >0x0D TIF> >0x21 TIF> >0x0D TIF> >0x21 TIF> >0x0D TIF>
+ >0x28 TIF> >0x0D TIF> >0x21 TIF> >0x0D TIF> >0x21 TIF> >0x0D TIF> >0x28 TIF> >0x0D TIF> >0x21 TIF> >0x0D TIF> >0x21 TIF> >0x108 TIF>Found SWD-DP with ID 0x1BA01477 >0x0D TIF> >0x28 TIF> >0x0D TIF> >0x28 TIF> >0x0D TIF> >0x28 TIF> >0x0D TIF> >0x28 TIF> >0x0D TIF> >0x21 TIF> >0x0D TIF> >0x28 TIF> >0x0D TIF> >0x28 TIF> >0x0D TIF> >0x21 TIF> >0x0D TIF> >0x21 TIF> >0x0D TIF> >0x21 TIF> >0x0D TIF> >0x28 TIF> >0x0D TIF> >0x28 TIF> >0x0D TIF> >0x28 TIF> >0x0D TIF> >0x21 TIF> >0x0D TIF> >0x21 TIF> >0x0D TIF>
+ >0x28 TIF> >0x0D TIF> >0x21 TIF> >0x0D TIF> >0x21 TIF>Found Cortex-M3 r1p1, Little endian. -- CPU_ReadMem(4 bytes @ 0xE000EDF0) -- CPU_ReadMem(4 bytes @ 0xE0002000)FPUnit: 6 code (BP) slots and 2 literal slots -- CPU_ReadMem(4 bytes @ 0xE000EDFC) -- CPU_ReadMem(4 bytes @ 0xE0001000) -- CPU_WriteMem(4 bytes @ 0xE0001000) -- CPU_ReadMem(4 bytes @ 0xE000ED88) -- CPU_WriteMem(4 bytes @ 0xE000ED88) -- CPU_ReadMem(4 bytes @ 0xE000ED88) -- CPU_WriteMem(4 bytes @ 0xE000ED88)CoreSight components:
+ROMTbl 0 @ E00FF000 -- CPU_ReadMem(16 bytes @ 0xE00FF000) -- CPU_ReadMem(16 bytes @ 0xE000EFF0) -- CPU_ReadMem(16 bytes @ 0xE000EFE0)ROMTbl 0 [0]: FFF0F000, CID: B105E00D, PID: 001BB000 SCS -- CPU_ReadMem(16 bytes @ 0xE0001FF0) -- CPU_ReadMem(16 bytes @ 0xE0001FE0)ROMTbl 0 [1]: FFF02000, CID: B105E00D, PID: 001BB002 DWT -- CPU_ReadMem(16 bytes @ 0xE0002FF0) -- CPU_ReadMem(16 bytes @ 0xE0002FE0)ROMTbl 0 [2]: FFF03000, CID: B105E00D, PID: 000BB003 FPB -- CPU_ReadMem(16 bytes @ 0xE0000FF0)
+ -- CPU_ReadMem(16 bytes @ 0xE0000FE0)ROMTbl 0 [3]: FFF01000, CID: B105E00D, PID: 001BB001 ITM -- CPU_ReadMem(16 bytes @ 0xE00FF010) -- CPU_ReadMem(16 bytes @ 0xE0040FF0) -- CPU_ReadMem(16 bytes @ 0xE0040FE0)ROMTbl 0 [4]: FFF41000, CID: B105900D, PID: 001BB923 TPIU-Lite >0x0D TIF> >0x21 TIF>  returns 0x1BA01477 (0019ms, 0548ms total)
+T1864 000:593 JLINK_GetDLLVersion()  returns 51205 (0000ms, 0548ms total)
+T1864 000:593 JLINK_CORE_GetFound()  returns 0x30000FF (0000ms, 0548ms total)
+T1864 000:593 JLINK_GetDebugInfo(0x100) -- Value=0xE00FF000  returns 0x00 (0000ms, 0548ms total)
+T1864 000:593 JLINK_GetDebugInfo(0x100) -- Value=0xE00FF000  returns 0x00 (0000ms, 0548ms total)
+T1864 000:593 JLINK_GetDebugInfo(0x101) -- Value=0x00000000  returns 0x00 (0000ms, 0548ms total)
+T1864 000:593 JLINK_ReadMem (0xE0041FF0, 0x0010 Bytes, ...) -- CPU is running -- CPU_ReadMem(16 bytes @ 0xE0041FF0) - Data: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  returns 0x00 (0000ms, 0548ms total)
+T1864 000:593 JLINK_GetDebugInfo(0x102) -- Value=0x00000000  returns 0x00 (0000ms, 0548ms total)
+T1864 000:593 JLINK_GetDebugInfo(0x103) -- Value=0xE0040000  returns 0x00 (0000ms, 0548ms total)
+T1864 000:593 JLINK_GetDebugInfo(0x104) -- Value=0xE0000000  returns 0x00 (0000ms, 0548ms total)
+T1864 000:593 JLINK_GetDebugInfo(0x105) -- Value=0xE0001000  returns 0x00 (0000ms, 0548ms total)
+T1864 000:593 JLINK_GetDebugInfo(0x106) -- Value=0xE0002000  returns 0x00 (0000ms, 0548ms total)
+T1864 000:593 JLINK_GetDebugInfo(0x107) -- Value=0xE000E000  returns 0x00 (0000ms, 0548ms total)
+T1864 000:593 JLINK_GetDebugInfo(0x10C) -- Value=0xE000EDF0  returns 0x00 (0000ms, 0548ms total)
+T1864 000:593 JLINK_ReadMemU32(0xE000ED00, 0x0001 Items, ...) -- CPU is running -- CPU_ReadMem(4 bytes @ 0xE000ED00) - Data: 31 C2 1F 41  returns 0x01 (0001ms, 0549ms total)
+T1864 000:594 JLINK_SetResetType(JLINKARM_RESET_TYPE_NORMAL)  returns JLINKARM_RESET_TYPE_NORMAL (0000ms, 0549ms total)
+T1864 000:594 JLINK_Reset() -- CPU is running -- CPU_WriteMem(4 bytes @ 0xE000EDF0) -- CPU is running -- CPU_WriteMem(4 bytes @ 0xE000EDFC) >0x35 TIF> -- CPU is running -- CPU_WriteMem(4 bytes @ 0xE000ED0C) -- CPU is running -- CPU_ReadMem(4 bytes @ 0xE000EDF0) -- CPU is running -- CPU_ReadMem(4 bytes @ 0xE000EDF0) -- CPU is running -- CPU_WriteMem(4 bytes @ 0xE000EDF0) -- CPU is running -- CPU_WriteMem(4 bytes @ 0xE000EDFC) -- CPU is running -- CPU_ReadMem(4 bytes @ 0xE000EDF0)
+ -- CPU_WriteMem(4 bytes @ 0xE0002000) -- CPU_ReadMem(4 bytes @ 0xE000EDFC) -- CPU_ReadMem(4 bytes @ 0xE0001000) (0015ms, 0564ms total)
+T1864 000:609 JLINK_ReadReg(R15 (PC))  returns 0x08000100 (0000ms, 0564ms total)
+T1864 000:609 JLINK_ReadReg(XPSR)  returns 0x01000000 (0000ms, 0564ms total)
+T1864 000:609 JLINK_Halt()  returns 0x00 (0000ms, 0564ms total)
+T1864 000:609 JLINK_IsHalted()  returns TRUE (0000ms, 0564ms total)
+T1864 000:609 JLINK_ReadMemU32(0xE000EDF0, 0x0001 Items, ...) -- CPU_ReadMem(4 bytes @ 0xE000EDF0) - Data: 03 00 03 00  returns 0x01 (0001ms, 0565ms total)
+T1864 000:610 JLINK_WriteU32(0xE000EDF0, 0xA05F0003) -- CPU_WriteMem(4 bytes @ 0xE000EDF0)  returns 0x00 (0000ms, 0565ms total)
+T1864 000:610 JLINK_WriteU32(0xE000EDFC, 0x01000000) -- CPU_WriteMem(4 bytes @ 0xE000EDFC)  returns 0x00 (0000ms, 0565ms total)
+T1864 000:610 JLINK_GetHWStatus(...)  returns 0x00 (0000ms, 0565ms total)
+T1864 000:610 JLINK_GetNumBPUnits(Type = 0xFFFFFF00)  returns 0x06 (0000ms, 0565ms total)
+T1864 000:610 JLINK_GetNumBPUnits(Type = 0xF0)  returns 0x2000 (0000ms, 0565ms total)
+T1864 000:610 JLINK_GetNumWPUnits()  returns 0x04 (0000ms, 0565ms total)
+T1864 000:611 JLINK_GetSpeed()  returns 0xFA0 (0000ms, 0565ms total)
+T1864 000:611 JLINK_ReadMemU32(0xE000E004, 0x0001 Items, ...) -- CPU_ReadMem(4 bytes @ 0xE000E004) - Data: 01 00 00 00  returns 0x01 (0000ms, 0565ms total)
+T1864 000:611 JLINK_ReadMemU32(0xE000E004, 0x0001 Items, ...) -- CPU_ReadMem(4 bytes @ 0xE000E004) - Data: 01 00 00 00  returns 0x01 (0000ms, 0565ms total)
+T1864 000:611 JLINK_WriteMem(0xE0001000, 0x001C Bytes, ...) - Data: 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ... -- CPU_WriteMem(28 bytes @ 0xE0001000)  returns 0x1C (0001ms, 0566ms total)
+T1864 000:612 JLINK_ReadMem (0xE0001000, 0x001C Bytes, ...) -- CPU_ReadMem(28 bytes @ 0xE0001000) - Data: 01 00 00 40 00 00 00 00 00 00 00 00 00 00 00 00 ...  returns 0x00 (0000ms, 0566ms total)
+T1864 000:612 JLINK_ReadReg(R15 (PC))  returns 0x08000100 (0000ms, 0566ms total)
+T1864 000:612 JLINK_ReadReg(XPSR)  returns 0x01000000 (0000ms, 0566ms total)
+T1864 000:713 JLINK_SetResetType(JLINKARM_RESET_TYPE_NORMAL)  returns JLINKARM_RESET_TYPE_NORMAL (0000ms, 0566ms total)
+T1864 000:713 JLINK_Reset() -- CPU_WriteMem(4 bytes @ 0xE000EDF0) -- CPU_WriteMem(4 bytes @ 0xE000EDFC) >0x35 TIF> -- CPU_WriteMem(4 bytes @ 0xE000ED0C) -- CPU_ReadMem(4 bytes @ 0xE000EDF0) -- CPU_ReadMem(4 bytes @ 0xE000EDF0) -- CPU_WriteMem(4 bytes @ 0xE000EDF0) -- CPU_WriteMem(4 bytes @ 0xE000EDFC) -- CPU is running -- CPU_ReadMem(4 bytes @ 0xE000EDF0) -- CPU_WriteMem(4 bytes @ 0xE0002000) -- CPU_ReadMem(4 bytes @ 0xE000EDFC) -- CPU_ReadMem(4 bytes @ 0xE0001000) (0014ms, 0580ms total)
+T1864 000:727 JLINK_ReadReg(R15 (PC))  returns 0x08000100 (0000ms, 0580ms total)
+T1864 000:727 JLINK_ReadReg(XPSR)  returns 0x01000000 (0000ms, 0580ms total)
+T1864 000:728 JLINK_ReadMem (0x08000100, 0x003C Bytes, ...) -- CPU_ReadMem(64 bytes @ 0x08000100) -- Updating C cache (64 bytes @ 0x08000100) -- Read from C cache (60 bytes @ 0x08000100) - Data: 06 48 80 47 06 48 00 47 FE E7 FE E7 FE E7 FE E7 ...  returns 0x00 (0000ms, 0580ms total)
+T083C 002:108 JLINK_SetBPEx(Addr = 0x0800438C, Type = 0xFFFFFFF2)  returns 0x00000001 (0000ms, 0580ms total)
+T083C 002:108 JLINK_Go() -- CPU_WriteMem(4 bytes @ 0xE0002000) -- CPU_ReadMem(4 bytes @ 0xE0001000) -- CPU_WriteMem(4 bytes @ 0xE0002008) -- CPU_WriteMem(4 bytes @ 0xE000200C) -- CPU_WriteMem(4 bytes @ 0xE0002010) -- CPU_WriteMem(4 bytes @ 0xE0002014) -- CPU_WriteMem(4 bytes @ 0xE0002018) -- CPU_WriteMem(4 bytes @ 0xE000201C) -- CPU_WriteMem(4 bytes @ 0xE0001004) (0002ms, 0582ms total)
+T083C 002:211 JLINK_IsHalted()  returns FALSE (0000ms, 0582ms total)
+T083C 002:312 JLINK_IsHalted()  returns TRUE (0001ms, 0583ms total)
+T083C 002:313 JLINK_Halt()  returns 0x00 (0000ms, 0582ms total)
+T083C 002:313 JLINK_IsHalted()  returns TRUE (0000ms, 0582ms total)
+T083C 002:313 JLINK_IsHalted()  returns TRUE (0000ms, 0582ms total)
+T083C 002:313 JLINK_IsHalted()  returns TRUE (0000ms, 0582ms total)
+T083C 002:313 JLINK_ReadReg(R15 (PC))  returns 0x0800438C (0000ms, 0582ms total)
+T083C 002:313 JLINK_ReadReg(XPSR)  returns 0x61000000 (0000ms, 0582ms total)
+T083C 002:313 JLINK_ClrBPEx(BPHandle = 0x00000001)  returns 0x00 (0001ms, 0583ms total)
+T083C 002:314 JLINK_ReadMemU32(0xE000ED30, 0x0001 Items, ...) -- CPU_ReadMem(4 bytes @ 0xE000ED30) - Data: 02 00 00 00  returns 0x01 (0000ms, 0583ms total)
+T083C 002:314 JLINK_ReadMemU32(0xE0001028, 0x0001 Items, ...) -- CPU_ReadMem(4 bytes @ 0xE0001028) - Data: 00 00 00 00  returns 0x01 (0000ms, 0583ms total)
+T083C 002:314 JLINK_ReadMemU32(0xE0001038, 0x0001 Items, ...) -- CPU_ReadMem(4 bytes @ 0xE0001038) - Data: 00 02 00 00  returns 0x01 (0000ms, 0583ms total)
+T083C 002:314 JLINK_ReadMemU32(0xE0001048, 0x0001 Items, ...) -- CPU_ReadMem(4 bytes @ 0xE0001048) - Data: 00 00 00 00  returns 0x01 (0001ms, 0584ms total)
+T083C 002:315 JLINK_ReadMemU32(0xE0001058, 0x0001 Items, ...) -- CPU_ReadMem(4 bytes @ 0xE0001058) - Data: 00 00 00 00  returns 0x01 (0000ms, 0584ms total)
+T083C 002:315 JLINK_ReadReg(R0)  returns 0x0800438D (0000ms, 0584ms total)
+T083C 002:315 JLINK_ReadReg(R1)  returns 0x20002010 (0000ms, 0584ms total)
+T083C 002:315 JLINK_ReadReg(R2)  returns 0x00000000 (0000ms, 0584ms total)
+T083C 002:315 JLINK_ReadReg(R3)  returns 0x08014905 (0000ms, 0584ms total)
+T083C 002:315 JLINK_ReadReg(R4)  returns 0x0801788C (0000ms, 0584ms total)
+T083C 002:315 JLINK_ReadReg(R5)  returns 0x0801788C (0000ms, 0584ms total)
+T083C 002:315 JLINK_ReadReg(R6)  returns 0x00000000 (0000ms, 0584ms total)
+T083C 002:315 JLINK_ReadReg(R7)  returns 0x00000000 (0000ms, 0584ms total)
+T083C 002:315 JLINK_ReadReg(R8)  returns 0x00000000 (0000ms, 0584ms total)
+T083C 002:315 JLINK_ReadReg(R9)  returns 0x20000160 (0000ms, 0584ms total)
+T083C 002:315 JLINK_ReadReg(R10)  returns 0x00000000 (0000ms, 0584ms total)
+T083C 002:315 JLINK_ReadReg(R11)  returns 0x00000000 (0000ms, 0584ms total)
+T083C 002:315 JLINK_ReadReg(R12)  returns 0x40010000 (0000ms, 0584ms total)
+T083C 002:315 JLINK_ReadReg(R13 (SP))  returns 0x20002000 (0000ms, 0584ms total)
+T083C 002:315 JLINK_ReadReg(R14)  returns 0x080042D1 (0000ms, 0584ms total)
+T083C 002:315 JLINK_ReadReg(R15 (PC))  returns 0x0800438C (0000ms, 0584ms total)
+T083C 002:315 JLINK_ReadReg(XPSR)  returns 0x61000000 (0000ms, 0584ms total)
+T083C 002:315 JLINK_ReadReg(MSP)  returns 0x20002000 (0000ms, 0584ms total)
+T083C 002:315 JLINK_ReadReg(PSP)  returns 0x20001000 (0000ms, 0584ms total)
+T083C 002:315 JLINK_ReadReg(CFBP)  returns 0x00000000 (0000ms, 0584ms total)
+T1864 002:321 JLINK_ReadMem (0x0800438C, 0x003C Bytes, ...) -- CPU_ReadMem(128 bytes @ 0x08004380) -- Updating C cache (128 bytes @ 0x08004380) -- Read from C cache (60 bytes @ 0x0800438C) - Data: 10 B5 72 B6 06 48 00 79 AA 28 01 D0 0D F0 84 FC ...  returns 0x00 (0000ms, 0584ms total)
+T1864 003:294 JLINK_Close() -- CPU_WriteMem(4 bytes @ 0xE0002008) -- CPU_ReadMem(4 bytes @ 0xE0001000) >0x42 TIF> >0x28 TIF> >0x0D TIF> >0x21 TIF> (0002ms, 0586ms total)
+T1864 003:294  (0002ms, 0586ms total)
+T1864 003:294 Closed (0002ms, 0586ms total)
+>>>>>>> remotes/origin/city_riding

+ 5 - 0
MDK-ARM/QD007A_CTL_APP.uvprojx

@@ -637,6 +637,11 @@
               <FileType>1</FileType>
               <FilePath>..\User\Src\log_save.c</FilePath>
             </File>
+            <File>
+              <FileName>flash_read_protection.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\User\Src\flash_read_protection.c</FilePath>
+            </File>
           </Files>
         </Group>
         <Group>

BIN
MDK-ARM/bin/MC_VOLANS_V2r0r2_20200426.bin


BIN
MDK-ARM/bin/MC_VOLANS_V2r0r2_20200427.bin


BIN
MDK-ARM/bin/MC_VOLANS_V2r0r3_20200427.bin


BIN
MDK-ARM/bin/MC_VOLANS_V2r0r4_20200603_SendToArno.bin


BIN
MDK-ARM/bin/MC_VOLANS_V2r0r4_20200615.bin


BIN
MDK-ARM/bin/MC_VOLANS_V2r1r0_20200717.bin


BIN
MDK-ARM/bin/MC_VOLANS_V2r1r1_20200720.bin


BIN
MDK-ARM/bin/MC_VOLANS_V2r1r2_20200812.bin


BIN
MDK-ARM/bin/MC_VOLANS_V2r1r3_20200814.bin


BIN
MDK-ARM/bin/MC_VOLANS_V2r1r3_20200821.bin


BIN
MDK-ARM/bin/MC_VOLANS_V2r1r3_20200821_1.bin


BIN
MDK-ARM/bin/MC_VOLANS_V2r1r5_20200904.bin


BIN
MDK-ARM/bin/MC_VR7500_V5r2r0_20200917.bin


BIN
MDK-ARM/bin/QD007A_CTL_APP.bin


+ 69 - 30
SelfTestUser/src_middlewares/stm32f1xx_STUperipheralRegisters.c

@@ -13,6 +13,16 @@ uint8_t DMA_Channel_selftest(DMA_Channel_TypeDef* DMA);
 uint8_t ADC_register_selftest(ADC_TypeDef* ADCx);
 uint8_t TIM_register_selftest(TIM_TypeDef* TIMx);
 
+void STU_delay_us(uint16_t time)
+{    
+   uint16_t i=0;  
+   while(time--)
+   {
+      i=7;  //72MHZ主频,1us
+      while(i--) ;    
+   }
+}
+
 uint8_t STU_PeripheralRegistersTest(void)
 {
 	//uint8_t result;
@@ -104,38 +114,65 @@ uint8_t GPIO_register_selftest(GPIO_TypeDef* GPIOx)
 	//GPIO_tmp.BRR = GPIOx->BRR;      //write only
 	//GPIO_tmp.LCKR = GPIOx->LCKR;    //lock register,don't test
 	
-	//////////CRL //////////////	
-	GPIOx->CRL=TEST_DATA_32B_0X55;
-	//GPIOx->CRL=0x55555554;
-	val=GPIOx->CRL;
-	if(val!=TEST_DATA_32B_0X55)
+	if(GPIOx != GPIOD)
 	{
-		return  (0);
+		//////////CRL //////////////	
+		GPIOx->CRL=TEST_DATA_32B_0X55;
+		//GPIOx->CRL=0x55555554;
+		val=GPIOx->CRL;
+		if(val!=TEST_DATA_32B_0X55)
+		{
+			return  (0);
+		}
+					
+		GPIOx->CRL=TEST_DATA_32B_0XAA;
+		val=GPIOx->CRL;
+		if(val!=TEST_DATA_32B_0XAA)
+					return  (0);	
+	///////////CRH/////////////////////			
+		GPIOx->CRH=TEST_DATA_32B_0X55;
+		val=GPIOx->CRH;
+		if(val!=TEST_DATA_32B_0X55)
+					return  (0);
+		GPIOx->CRH=TEST_DATA_32B_0XAA;
+		val=GPIOx->CRH;
+		if(val!=TEST_DATA_32B_0XAA)
+					return  (0);
+	///////////ODR/////////////////////
+		GPIOx->ODR=0x00005555;
+		val=GPIOx->ODR;
+		if((val& 0x0000FFFF)!=0x00005555)
+					return  (0);
+		GPIOx->ODR=0x0000AAAA;
+		val=GPIOx->ODR;
+		if((val& 0x0000FFFF)!=0x0000AAAA)
+					return  (0);	
 	}
-				
-	GPIOx->CRL=TEST_DATA_32B_0XAA;
-	val=GPIOx->CRL;
-	if(val!=TEST_DATA_32B_0XAA)
-				return  (0);	
-///////////CRH/////////////////////			
-	GPIOx->CRH=TEST_DATA_32B_0X55;
-	val=GPIOx->CRH;
-	if(val!=TEST_DATA_32B_0X55)
-				return  (0);
-	GPIOx->CRH=TEST_DATA_32B_0XAA;
-	val=GPIOx->CRH;
-	if(val!=TEST_DATA_32B_0XAA)
-				return  (0);
-///////////ODR/////////////////////
-	GPIOx->ODR=0x00005555;
-	val=GPIOx->ODR;
-	if((val& 0x0000FFFF)!=0x00005555)
-				return  (0);
-	GPIOx->ODR=0x0000AAAA;
-	val=GPIOx->ODR;
-	if((val& 0x0000FFFF)!=0x0000AAAA)
-				return  (0);	
-
+	else//GPIOD寄存器测试
+	{
+		//////////CRL //////////////	
+		GPIOx->CRL=(GPIO_tmp.CRL&0xFFFFF000)|0x00000555;
+		val=GPIOx->CRL;
+		if( (val&0x00000FFF) !=0x00000555 )
+		{
+			return  (0);
+		}				
+		GPIOx->CRL=(GPIO_tmp.CRL&0xFFFFF000)|0x00000AAA;
+		val=GPIOx->CRL;
+		if( (val&0x00000FFF) !=0x00000AAA )
+					return  (0);	
+	///////////ODR/////////////////////
+		GPIOx->ODR=(GPIO_tmp.ODR&0xFFFFFFF8)|0x00000007;
+		val=GPIOx->ODR;
+		if((val& 0x00000007)!=0x00000007)
+					return  (0);
+		GPIOx->ODR=(GPIO_tmp.ODR&0xFFFFFFF8)|0x00000000;
+		val=GPIOx->ODR;
+		if((val& 0x00000007)!=0x00000000)
+					return  (0);	
+	}
+	
+	
 	/*恢复寄存器的复位默认值*/
 	GPIOx->CRL = GPIO_tmp.CRL;
 	GPIOx->CRH = GPIO_tmp.CRH;
@@ -310,10 +347,12 @@ uint8_t DMA_Channel_selftest(DMA_Channel_TypeDef* DMA_Channelx)
 	//////////CNDTR//////////////
 	DMA_Channelx->CCR = 0x00000000;
 	DMA_Channelx->CNDTR=0x00005555;
+	STU_delay_us(5);
 	val=DMA_Channelx->CNDTR;
 	if(val!=0x00005555)
 				return  (0);
 	DMA_Channelx->CNDTR=0x0000AAAA;
+	STU_delay_us(5);
 	val=DMA_Channelx->CNDTR;
 		if(val!=0x0000AAAA)
 				return  (0);

+ 0 - 3
User/Inc/battery_info.h

@@ -3,11 +3,8 @@
 
 #include "stm32f1xx_hal.h"
 
-#define RD_BATTERY_INFO_TABLE 1  // 0:不使用电池放电数据得到电量;1:使用电池放电数据查表获得电池电量;
 #define BATTERY_TATAL_Q_MAH 13000  //mAh
 
-//extern const uint16_t battery_VoltageQuantity[1054][2] ;
-
 extern const uint16_t battery_VoltageQuantity[1022][2] ;
 
 #endif

+ 1 - 0
User/Inc/cadence_sensor.h

@@ -23,6 +23,7 @@ typedef struct
 	MC_CadenceDir_Struct_t Cadence_Dir;    //踏频方向
 	TrueOrFalse_Flag_Struct_t IsStopFlag;  //踏频停止标志
 	uint32_t TrigCount;                    //正向踩踏信号计数
+	uint16_t torqueByCadence;              //经过踏频信号滤波处理的力矩值
 }MC_CadenceResult_Struct_t;
 
 //踏频传感器输出状态

+ 0 - 10
User/Inc/motor_control.h

@@ -77,16 +77,6 @@ extern MC_CalParam_Struct_t MC_CalParam;
 extern MC_CalParam_Struct_t MC_CalParam_Back;
 extern uint8_t MC_CadenceLimit_K;
 extern FlagStatus MC_StarFlag;
-extern MC_TorqueProcess_Param_Struct_t MC_TorqueProcess_Param;
-extern MC_WalkProcess_Param_Struct_t MC_WalkProcess_Param;
-
-extern uint8_t flagCandence;
-extern uint16_t candenceCount; 
-extern int16_t torqueDataFromCadence;
-extern uint16_t torque_NM;
-
-extern int32_t Taping_activeFlt;    //踏频实时值滤波中间量
-extern int32_t Taping_activeFlted;  //踏频实时值滤波值
 
 #define Update_MC_ControlCode_Back()    { MC_ControlCode_Back.GearSt = (MC_GearSt_Struct_t)~MC_ControlCode.GearSt;\
 		                                      MC_ControlCode_Back.LightSwitch = (MC_LightSwitch_Struct_t)~MC_ControlCode.LightSwitch; }

+ 1 - 1
User/Inc/remain_distance.h

@@ -49,7 +49,7 @@ typedef struct
 
 extern Remain_Dis_t RemainDis;
 
-extern void RD_RemainDis_Init(uint16_t uwWheelLength, uint16_t BusVoltage, uint8_t DesignVol);
+extern void RD_RemainDis_Init(uint16_t uwWheelLength, TrueOrFalse_Flag_Struct_t BMS_COM_OK, uint16_t BusVoltage, uint8_t DesignVol, uint16_t BMS_RC);
 extern void RD_CalculateRemainDis(uint32_t WheelTurnCnt, uint16_t RemainCap, uint8_t SOC, uint16_t BusCurrent) ;
 extern void RD_SaveAndUpdateInfo(MC_GearSt_Struct_t GearSt, MC_AssistRunMode_Struct_t MC_AssistRunMode);
 extern uint8_t Battery_SocCal(uint16_t Voltage, uint16_t Current);

+ 4 - 2
User/Inc/var.h

@@ -164,7 +164,9 @@ typedef struct
 	uint8_t CadenceStarNum;                      //踏频启动信号个数,地址偏移25
 	MC_SpeedSignal_Struct_t SpeedSignal;         //0x55-车轮触发,0x-AA踏频计算,0xEE-通讯获取车轮旋转周期,地址偏移26
 	int8_t WheelSizeAdj;                         //周长微调值,地址偏移27
-	uint8_t RS[4];//地址偏移28
+	uint16_t UV_Protect_TH;                      //低压保护值,地址偏移28
+	uint8_t WalkMode_SpeedLimit;                 //推行模式限速,地址偏移30
+	uint8_t WalkMode_MotorSpeedSet;              //推行模式电机转速设置,地址偏移31
 }MC_ConfigParam1_Struct_t;
 
 //用户配置参数2,占用空间32bytes
@@ -383,7 +385,7 @@ typedef enum _TO_TE_SENDSTEP
 typedef struct
 {
   uint16_t Gain_K;        //助力比系数,放大100倍,偏移地址 0
-	uint16_t i_Sport_TH;    //i-Sport档位力矩阈值,偏移地址 2
+	uint16_t TorqueApp_TH;    //i-Sport档位力矩阈值,偏移地址 2
   uint16_t Lower_Iq;      //助力输出下限值,偏移地址 4
 	uint16_t Upper_Iq;      //助力输出上限值,偏移地址 6
 	uint8_t  AccCnt;        //力矩控制ref加速斜率, 偏移地址 8

+ 16 - 16
User/Src/MC_PID_regulators.c

@@ -38,8 +38,8 @@ const PID_Struct_t PID_Torque_InitStructure_Volans =
   (int32_t)0,          //wPreviousError
   (int32_t)-32768,     //hLower_Limit_Output
   (int32_t)32767,      //hUpper_Limit_Output
-  (int32_t)-33554432,  //wLower_Limit_Integral
-  (int32_t)10240000,   //wUpper_Limit_Integral
+  (int32_t)(-32768 * 1024),  //wLower_Limit_Integral
+  (int32_t)(32767 * 1024),   //wUpper_Limit_Integral
   (int32_t)0           //wIntegral
 };
 
@@ -54,8 +54,8 @@ const PID_Struct_t PID_Flux_InitStructure_Volans =
   (int32_t)0,          //wPreviousError
   (int32_t)-32768,     //hLower_Limit_Output
   (int32_t)32767,      //hUpper_Limit_Output
-  (int32_t)-33554432,  //wLower_Limit_Integral
-  (int32_t)10240000,   //wUpper_Limit_Integral
+  (int32_t)(-32768 * 1024),  //wLower_Limit_Integral
+  (int32_t)(32767 * 1024),   //wUpper_Limit_Integral
   (int32_t)0           //wIntegral
 };
 
@@ -135,8 +135,8 @@ const PID_Struct_t PID_Torque_InitStructure_Volans_Plus =
   (int32_t)0,          //wPreviousError
   (int32_t)-32768,     //hLower_Limit_Output
   (int32_t)32767,      //hUpper_Limit_Output
-  (int32_t)-33554432,  //wLower_Limit_Integral
-  (int32_t)10240000,   //wUpper_Limit_Integral
+  (int32_t)(-32768 * 1024),  //wLower_Limit_Integral
+  (int32_t)(32767 * 1024),   //wUpper_Limit_Integral
   (int32_t)0           //wIntegral
 };
 
@@ -151,8 +151,8 @@ const PID_Struct_t PID_Flux_InitStructure_Volans_Plus =
   (int32_t)0,          //wPreviousError
   (int32_t)-32768,     //hLower_Limit_Output
   (int32_t)32767,      //hUpper_Limit_Output
-  (int32_t)-33554432,  //wLower_Limit_Integral
-  (int32_t)10240000,   //wUpper_Limit_Integral
+  (int32_t)(-32768 * 1024),  //wLower_Limit_Integral
+  (int32_t)(32767 * 1024),   //wUpper_Limit_Integral
   (int32_t)0           //wIntegral
 };
 
@@ -232,8 +232,8 @@ const PID_Struct_t PID_Torque_InitStructure_Pegasi =
   (int32_t)0,          //wPreviousError
   (int32_t)-32768,     //hLower_Limit_Output
   (int32_t)32767,      //hUpper_Limit_Output
-  (int32_t)-33554432,  //wLower_Limit_Integral
-  (int32_t)10240000,   //wUpper_Limit_Integral
+  (int32_t)(-32768 * 1024),  //wLower_Limit_Integral
+  (int32_t)(32767 * 1024),   //wUpper_Limit_Integral
   (int32_t)0           //wIntegral
 };
 
@@ -248,8 +248,8 @@ const PID_Struct_t PID_Flux_InitStructure_Pegasi =
   (int32_t)0,          //wPreviousError
   (int32_t)-32768,     //hLower_Limit_Output
   (int32_t)32767,      //hUpper_Limit_Output
-  (int32_t)-33554432,  //wLower_Limit_Integral
-  (int32_t)10240000,   //wUpper_Limit_Integral
+  (int32_t)(-32768 * 1024),  //wLower_Limit_Integral
+  (int32_t)(32767 * 1024),   //wUpper_Limit_Integral
   (int32_t)0           //wIntegral
 };
 
@@ -329,8 +329,8 @@ const PID_Struct_t PID_Torque_InitStructure_Pegasi_Plus =
   (int32_t)0,          //wPreviousError
   (int32_t)-32768,     //hLower_Limit_Output
   (int32_t)32767,      //hUpper_Limit_Output
-  (int32_t)-33554432,  //wLower_Limit_Integral
-  (int32_t)10240000,   //wUpper_Limit_Integral
+  (int32_t)(-32768 * 1024),  //wLower_Limit_Integral
+  (int32_t)(32767 * 1024),   //wUpper_Limit_Integral
   (int32_t)0           //wIntegral
 };
 
@@ -345,8 +345,8 @@ const PID_Struct_t PID_Flux_InitStructure_Pegasi_Plus =
   (int32_t)0,          //wPreviousError
   (int32_t)-32768,     //hLower_Limit_Output
   (int32_t)32767,      //hUpper_Limit_Output
-  (int32_t)-33554432,  //wLower_Limit_Integral
-  (int32_t)10240000,   //wUpper_Limit_Integral
+  (int32_t)(-32768 * 1024),  //wLower_Limit_Integral
+  (int32_t)(32767 * 1024),   //wUpper_Limit_Integral
   (int32_t)0           //wIntegral
 };
 

+ 87 - 10
User/Src/cadence_sensor.c

@@ -1,5 +1,5 @@
 #include "cadence_sensor.h"
-#include "motor_control.h"
+#include "adc.h"
 
 //局部变量定义
 const uint8_t ForwardDir_EncoderData[4] = {2,0,3,1};//判断正转用的编码顺序表,正转时信号为:2,0,1,3
@@ -10,6 +10,7 @@ MC_CadenceResult_Struct_t MC_CadenceResult = {0, MC_Cadence_Stop, TRUE, 0};
 uint16_t MC_Cadence_Array[10] = {0};
 
 /**************************局部函数定义*************************/
+uint16_t torqueFilteredThroughCadence(uint16_t torque_temp, uint8_t modeFlag);
 
 /**************************全局函数定义*************************/
 uint8_t Cadence_ReadHallState(void)
@@ -114,13 +115,6 @@ void CadenceSensor_Process(MC_CadenceResult_Struct_t* p_MC_CadenceResult, uint16
 		Cadence_ActiveFlt += (((int32_t)CadenceTemp << 8) - Cadence_ActiveFlt) >> 4;
 		p_MC_CadenceResult->Cadence_Data = (uint8_t)(Cadence_ActiveFlt >> 8);
 		
-		
-		/*带补偿力矩模式使用*/
-		Taping_activeFlted = p_MC_CadenceResult->Cadence_Data;
-		candenceCount++;
-		flagCandence = 1;	
-		torqueDataFromCadence = torque_NM;
-		
 		/*上坡时,启动阈值为1*/
 		if(UpSlopeFlag == TRUE)
 		{
@@ -145,6 +139,9 @@ void CadenceSensor_Process(MC_CadenceResult_Struct_t* p_MC_CadenceResult, uint16
 		  p_MC_CadenceResult->IsStopFlag = TRUE;
 		}
 		
+		/*根据踏频的信号,对力矩进行滤波处理*/
+		p_MC_CadenceResult->torqueByCadence = torqueFilteredThroughCadence(ADC_SensorData.TorqueSensor,1);
+		
 		//更新停机计时数值
 		CadenceStopJudgeTimeCnt = HAL_GetTick();
 	}
@@ -163,9 +160,89 @@ void CadenceSensor_Process(MC_CadenceResult_Struct_t* p_MC_CadenceResult, uint16
 		Cadence_ActiveFlt = 0;
 		CadenceStarFlagCnt =0;
 		
-		Taping_activeFlt = 0;
-		Taping_activeFlted = 0;
+		/*清零相关变量*/
+		p_MC_CadenceResult->torqueByCadence = torqueFilteredThroughCadence(ADC_SensorData.TorqueSensor,0);
+		
 	}
 	
 	MC_CadenceSensorStatus.HallGropuStatus_Old = MC_CadenceSensorStatus.HallGropuStatus;
 }
+
+uint16_t torqueFilteredThroughCadence(uint16_t torque_temp, uint8_t modeFlag)
+{
+	#define T_FIFO_LENGTH 30                       //每个信号6度,30为180度 
+	static uint16_t T_FIFO[T_FIFO_LENGTH]={0};
+	static uint8_t T_Index=0;
+	static uint32_t T_sum=0;
+	static uint8_t filter_status_falg=0;
+	uint16_t result_filtered=0;
+	
+	if( modeFlag != 0 )
+	{
+		/*根据踏频信号,采样最近180度内力矩平均值*/
+		
+		if(filter_status_falg != 0)
+		{
+			T_sum -= T_FIFO[T_Index];
+			T_sum += torque_temp;
+			T_FIFO[T_Index] = torque_temp;
+		}
+		
+		T_Index++;
+		
+		if(T_Index >= T_FIFO_LENGTH)
+		{
+			T_Index = 0;	
+			if(filter_status_falg == 0)
+			{
+				filter_status_falg = 1;
+			}
+			else if(filter_status_falg == 1)
+			{
+				filter_status_falg = 2;
+			}
+		}
+		
+		if(filter_status_falg == 2)
+		{
+			result_filtered = T_sum / T_FIFO_LENGTH;
+		}
+		else if(filter_status_falg == 1)
+		{
+			/*启动后的前180度-360度,根据实际数据个数求平均值*/
+			if(T_Index == 0)
+			{
+				result_filtered = torque_temp;
+			}
+			else
+			{
+				result_filtered = T_sum / T_Index;
+			}
+		}
+		else
+		{
+			/*启动后的前180度,使用实时值*/
+			result_filtered = torque_temp;
+		}
+		
+		/*力矩实时值低于滤波值的五分之一,使用实时值*/
+		if(torque_temp < (result_filtered/5) )
+		{
+			result_filtered = torque_temp;
+		}
+		/*踏频信号采样*/
+	}
+	else
+	{
+		/*清零变量*/
+		for(uint8_t i=0;i<T_FIFO_LENGTH;i++)
+		{
+				T_FIFO[i] = 0;
+		}
+		T_Index = 0;
+		T_sum = 0;
+		filter_status_falg=0;
+	}		
+	
+	return result_filtered;
+}

+ 13 - 6
User/Src/math_tools.c

@@ -83,16 +83,23 @@ uint16_t Coefficient_GainCal(uint16_t Min, uint16_t Max, uint16_t Th, uint16_t I
 	uint16_t K;
 	
 	//¼ÆËãK
-	K = (Max - Min) * 1024 / Th;
-	if(InputData > Th)
+	if(Th  == 0)
 	{
-		Result = Max;
-		return Result;
+	  return Max;
 	}
 	else
 	{
-		Result = Min + (K * InputData >> 10);
-		return Result;
+		K = (Max - Min) * 1024 / Th;
+		if(InputData > Th)
+		{
+			Result = Max;
+			return Result;
+		}
+		else
+		{
+			Result = Min + (K * InputData >> 10);
+			return Result;
+		}
 	}
 }
 

+ 82 - 595
User/Src/motor_control.c

@@ -514,20 +514,25 @@ MC_CalParam_Struct_t MC_AssistRunMode_Walk_Process(MC_WorkMode_Struct_t p_MC_Wor
 		SpdMotorByIdc = PID_Regulator((MC_ConfigParam1.CurrentLimit * 1000) >> 7, MC_RunInfo.BusCurrent >> 7, &PID_ConstantPower); // 母线电流闭环
 	}
 	
-	//运行模式,设定转速 = 135rpm
+	//运行模式,设定转速 = 设置值
 	else
 	{
-		if(MC_WalkProcess_Param.MotorSpeedSetBigin < (135 << 5) - 10)
+		uint8_t WalkMode_MotorSpeedSet = 0;
+		
+		//新增配置项,兼容旧电机
+		WalkMode_MotorSpeedSet = (MC_ConfigParam1.WalkMode_MotorSpeedSet == 0) ? 135 : MC_ConfigParam1.WalkMode_MotorSpeedSet;
+		
+		if(MC_WalkProcess_Param.MotorSpeedSetBigin < (WalkMode_MotorSpeedSet << 5) - 10)
 		{
 		  MC_WalkProcess_Param.MotorSpeedSetBigin += 1;
 		}
-		else if(MC_WalkProcess_Param.MotorSpeedSetBigin > (135 << 5) + 10)
+		else if(MC_WalkProcess_Param.MotorSpeedSetBigin > (WalkMode_MotorSpeedSet << 5) + 10)
 		{
 		  MC_WalkProcess_Param.MotorSpeedSetBigin -= 1;
 		}
 		else
 		{
-		  MC_WalkProcess_Param.MotorSpeedSetBigin = 135 << 5;
+		  MC_WalkProcess_Param.MotorSpeedSetBigin = WalkMode_MotorSpeedSet << 5;
 		}
 		SpdMotorByIdc = PID_Regulator((MC_ConfigParam1.CurrentLimit * 500) >> 7, MC_RunInfo.BusCurrent >> 7, &PID_ConstantPower); // 母线电流闭环
 	}
@@ -536,11 +541,16 @@ MC_CalParam_Struct_t MC_AssistRunMode_Walk_Process(MC_WorkMode_Struct_t p_MC_Wor
 	TorQueBySpd = PID_Regulator((MC_WalkProcess_Param.MotorSpeedSetBigin >> 5), MC_RunInfo.MotorSpeed, &PID_MotorSpd); // 电机速度闭环输出
 	TorQueBySpd += SpdMotorByIdc;
 	
-	//限制车速低于6km/h
-	if(p_MC_WorkMode != MC_WorkMode_Config) //运行模式,推行限速6km/h
+	//限制车速低于设置值
+	if(p_MC_WorkMode != MC_WorkMode_Config) //运行模式,推行限速
 	{
-	  TorQueBySpd = (uint16_t)((uint32_t)(TorQueBySpd * Function_Linear_3Stage(55, 0, 55, 128, MC_RunInfo.BikeSpeed)) >> 10);
-		if(MC_RunInfo.BikeSpeed > 60)
+		uint8_t WalkMode_SpeedLimit = 0;
+		
+		//新增配置项,兼容旧电机	
+		WalkMode_SpeedLimit = (MC_ConfigParam1.WalkMode_SpeedLimit == 0) ? 60 : MC_ConfigParam1.WalkMode_SpeedLimit;
+		
+	  TorQueBySpd = (uint16_t)((uint32_t)(TorQueBySpd * Function_Linear_3Stage((WalkMode_SpeedLimit - 5), 0, (WalkMode_SpeedLimit - 5), 128, MC_RunInfo.BikeSpeed)) >> 10);
+		if(MC_RunInfo.BikeSpeed > WalkMode_SpeedLimit)
 		{
 			MC_WalkProcess_Param.MotorSpeedSetBigin = 0;
 			MC_MotorStop(&MC_StarFlag);
@@ -628,8 +638,8 @@ MC_CalParam_Struct_t MC_AssistRunMode_Cadence_Process(MC_GearSt_Struct_t GearSt)
 	return (p_MC_CalParam);
 }
 
-//力矩模式处理 运动版
-MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_GearSt_Struct_t GearSt)
+//力矩模式处理
+MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_GearSt_Struct_t GearSt, uint16_t SenorDataByCadence)
 {
   MC_CalParam_Struct_t p_MC_CalParam = {MC_AssistRunMode_INVALID, 0,	0, RESET};
   uint8_t TorqueAccStep = 0;//力矩上升斜率
@@ -644,10 +654,15 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
 	uint16_t CurrentLimitSet;                //限流设置值,不同助力档位更新
 	
 	static uint8_t TorqueRefEndUpdateCount = 0;
+	
+	#define SOFT_SATRT 1
+	
+	#if SOFT_SATRT
 	static FlagStatus SoftStartFlag = SET;
 	static uint16_t SoftStartDelayTimeCount = 0;
 	uint16_t SoftStartDelayTime = 0;
 	uint16_t SoftStartAcc = 0;
+	#endif
 
 	#if 1
 	
@@ -770,9 +785,12 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
 		  MC_TorqueProcess_Param.TorqueRefEnd = 0;
 			//停机处理
 			MC_MotorStop(&MC_StarFlag);
+			
+			#if SOFT_SATRT
 			//缓启动标志置位
 			SoftStartFlag = SET;
 			SoftStartDelayTimeCount = 0;
+			#endif
 		}
 		else
 		{
@@ -783,17 +801,20 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
 	//力矩给定升降速处理
 	else
 	{
+		/*调节助力比,使用经过踏频信号滤波处理的力矩值*/
+		MC_TorqueProcess_Param.TorqueApp = SenorDataByCadence;
+		
 		//按照助力档位调节力矩输入值
 		switch(GearSt)
 		{
 			case MC_GearSt_Torque_ECO:
 			{
 				//控制输入给定加速斜率
-				if(MC_ConfigParam1.UserAdjParam_ECO.StarModel_GAIN <= 80)
+				if(MC_ConfigParam1.UserAdjParam_ECO.StarModel_GAIN <= 90)
 				{
 				  TorqueAccStep = MC_AssisParam.Gear_ECO.AccCnt - 1;
 				}
-				else if(MC_ConfigParam1.UserAdjParam_ECO.StarModel_GAIN >= 120)
+				else if(MC_ConfigParam1.UserAdjParam_ECO.StarModel_GAIN >= 110)
 				{
 				  TorqueAccStep = MC_AssisParam.Gear_ECO.AccCnt + 1;
 				}
@@ -805,7 +826,7 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
 				//控制输入给定减速斜率
 				TorqueDecStep = MC_AssisParam.Gear_ECO.DecCnt;
 				//随力矩输入调节助力比
-				Torque_Temp = (uint16_t)((uint32_t)(MC_TorqueProcess_Param.TorqueApp * Coefficient_GainCal(100, MC_AssisParam.Gear_ECO.Gain_K, MC_AssisParam.Gear_ECO.Upper_Iq, MC_TorqueProcess_Param.TorqueApp)) >> 10);
+				Torque_Temp = (uint16_t)((uint32_t)(MC_TorqueProcess_Param.TorqueApp * Coefficient_GainCal(MC_AssisParam.Gear_ECO.Gain_K >> 1, MC_AssisParam.Gear_ECO.Gain_K, MC_AssisParam.Gear_ECO.TorqueApp_TH, MC_TorqueProcess_Param.TorqueApp)) >> 10);
 				//根据助力增益调节助力比
 				Torque_Temp = Torque_Temp * MC_ConfigParam1.UserAdjParam_ECO.Assist_K_GAIN / 100;
 				//给定下限
@@ -824,11 +845,11 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
 			case MC_GearSt_Torque_NORM:
 			{
 				//控制输入给定加速斜率
-				if(MC_ConfigParam1.UserAdjParam_NORM.StarModel_GAIN <= 80)
+				if(MC_ConfigParam1.UserAdjParam_NORM.StarModel_GAIN <= 90)
 				{
 				  TorqueAccStep = MC_AssisParam.Gear_NORM.AccCnt - 1;
 				}
-				else if(MC_ConfigParam1.UserAdjParam_NORM.StarModel_GAIN >= 120)
+				else if(MC_ConfigParam1.UserAdjParam_NORM.StarModel_GAIN >= 110)
 				{
 				  TorqueAccStep = MC_AssisParam.Gear_NORM.AccCnt + 1;
 				}
@@ -840,13 +861,14 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
 				//控制输入给定减速斜率
 				TorqueDecStep = MC_AssisParam.Gear_NORM.DecCnt;
 				//随力矩输入调节助力比
-				Torque_Temp = (uint16_t)((uint32_t)(MC_TorqueProcess_Param.TorqueApp * Coefficient_GainCal(100, MC_AssisParam.Gear_NORM.Gain_K, MC_AssisParam.Gear_NORM.Upper_Iq, MC_TorqueProcess_Param.TorqueApp)) >> 10);
+				Torque_Temp = (uint16_t)((uint32_t)(MC_TorqueProcess_Param.TorqueApp * Coefficient_GainCal(MC_AssisParam.Gear_NORM.Gain_K >> 1, MC_AssisParam.Gear_NORM.Gain_K, MC_AssisParam.Gear_NORM.TorqueApp_TH, MC_TorqueProcess_Param.TorqueApp)) >> 10);
 				//根据助力增益调节助力比
 				Torque_Temp = Torque_Temp * MC_ConfigParam1.UserAdjParam_NORM.Assist_K_GAIN / 100;
 				//给定下限
 				Torque_Temp = (Torque_Temp < MC_AssisParam.Gear_NORM.Lower_Iq) ? MC_AssisParam.Gear_NORM.Lower_Iq : Torque_Temp;
 				//给定上限
 				Torque_Temp = (Torque_Temp > MC_AssisParam.Gear_NORM.Upper_Iq) ? MC_AssisParam.Gear_NORM.Upper_Iq : Torque_Temp;
+				
 				//限流参数设置
 				CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_NORM.CurrentMax_K * MC_ConfigParam1.CurrentLimit * 1000 >> 17) * 100;
 				CurrentLimitPresent = MC_DataSet_Linear_Process(CurrentLimitSet, CurrentLimitPresent, 5 ,1);
@@ -859,11 +881,11 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
 			case MC_GearSt_Torque_SPORT:
 			{
 				//控制输入给定加速斜率
-				if(MC_ConfigParam1.UserAdjParam_SPORT.StarModel_GAIN <= 80)
+				if(MC_ConfigParam1.UserAdjParam_SPORT.StarModel_GAIN <= 90)
 				{
 				  TorqueAccStep = MC_AssisParam.Gear_SPORT.AccCnt - 1;
 				}
-				else if(MC_ConfigParam1.UserAdjParam_SPORT.StarModel_GAIN >= 120)
+				else if(MC_ConfigParam1.UserAdjParam_SPORT.StarModel_GAIN >= 110)
 				{
 				  TorqueAccStep = MC_AssisParam.Gear_SPORT.AccCnt + 1;
 				}
@@ -875,7 +897,7 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
 				//控制输入给定减速斜率
 				TorqueDecStep = MC_AssisParam.Gear_SPORT.DecCnt;
 				//随力矩输入调节助力比
-				Torque_Temp = (uint16_t)((uint32_t)(MC_TorqueProcess_Param.TorqueApp * Coefficient_GainCal(100, MC_AssisParam.Gear_SPORT.Gain_K, MC_AssisParam.Gear_SPORT.Upper_Iq, MC_TorqueProcess_Param.TorqueApp)) >> 10);
+				Torque_Temp = (uint16_t)((uint32_t)(MC_TorqueProcess_Param.TorqueApp * Coefficient_GainCal(MC_AssisParam.Gear_SPORT.Gain_K >> 1, MC_AssisParam.Gear_SPORT.Gain_K, MC_AssisParam.Gear_SPORT.TorqueApp_TH, MC_TorqueProcess_Param.TorqueApp)) >> 10);
 				//根据助力增益调节助力比
 				Torque_Temp = Torque_Temp * MC_ConfigParam1.UserAdjParam_SPORT.Assist_K_GAIN / 100;
 				//给定下限
@@ -894,11 +916,11 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
 			case MC_GearSt_Torque_TURBO:
 			{
 				//控制输入给定加速斜率
-				if(MC_ConfigParam1.UserAdjParam_TURBO.StarModel_GAIN <= 80)
+				if(MC_ConfigParam1.UserAdjParam_TURBO.StarModel_GAIN <= 90)
 				{
 				  TorqueAccStep = MC_AssisParam.Gear_TURBO.AccCnt - 1;
 				}
-				else if(MC_ConfigParam1.UserAdjParam_TURBO.StarModel_GAIN >= 120)
+				else if(MC_ConfigParam1.UserAdjParam_TURBO.StarModel_GAIN >= 110)
 				{
 				  TorqueAccStep = MC_AssisParam.Gear_TURBO.AccCnt + 1;
 				}
@@ -910,7 +932,7 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
 				//控制输入给定减速斜率
 				TorqueDecStep = MC_AssisParam.Gear_TURBO.DecCnt;
 				//随力矩输入调节助力比
-				Torque_Temp = (uint16_t)((uint32_t)(MC_TorqueProcess_Param.TorqueApp * Coefficient_GainCal(100, MC_AssisParam.Gear_TURBO.Gain_K, MC_AssisParam.Gear_TURBO.Upper_Iq, MC_TorqueProcess_Param.TorqueApp)) >> 10);
+				Torque_Temp = (uint16_t)((uint32_t)(MC_TorqueProcess_Param.TorqueApp * Coefficient_GainCal(MC_AssisParam.Gear_TURBO.Gain_K >> 1, MC_AssisParam.Gear_TURBO.Gain_K, MC_AssisParam.Gear_TURBO.TorqueApp_TH, MC_TorqueProcess_Param.TorqueApp)) >> 10);
 				//根据助力增益调节助力比
 				Torque_Temp = Torque_Temp * MC_ConfigParam1.UserAdjParam_TURBO.Assist_K_GAIN / 100;
 				//给定下限
@@ -929,11 +951,11 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
 			case MC_GearSt_SMART:
 			{
 				//控制输入给定加速斜率
-				if(MC_ConfigParam1.UserAdjParam_SMART.StarModel_GAIN <= 80)
+				if(MC_ConfigParam1.UserAdjParam_SMART.StarModel_GAIN <= 90)
 				{
 				  TorqueAccStep = MC_AssisParam.Gear_SMART.AccCnt - 1;
 				}
-				else if(MC_ConfigParam1.UserAdjParam_SMART.StarModel_GAIN >= 120)
+				else if(MC_ConfigParam1.UserAdjParam_SMART.StarModel_GAIN >= 110)
 				{
 				  TorqueAccStep = MC_AssisParam.Gear_SMART.AccCnt + 1;
 				}
@@ -945,7 +967,7 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
 				//控制输入给定减速斜率
 				TorqueDecStep = MC_AssisParam.Gear_SMART.DecCnt;
 				//助力比控制系数
-				Torque_Temp = (uint32_t)(MC_TorqueProcess_Param.TorqueApp * MC_TorqueProcess_Param.TorqueApp) / (MC_AssisParam.Gear_SMART.i_Sport_TH);
+				Torque_Temp = (uint32_t)(MC_TorqueProcess_Param.TorqueApp * MC_TorqueProcess_Param.TorqueApp) / (MC_AssisParam.Gear_SMART.TorqueApp_TH);
 				//根据助力增益调节助力比
 				Torque_Temp = Torque_Temp * MC_ConfigParam1.UserAdjParam_SMART.Assist_K_GAIN / 100;
 				//给定下限
@@ -1007,45 +1029,52 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
 					MC_TorqueProcess_Param.TorqueRefEnd -= TorqueDecStep;
 				}
 			}		
-		}		
+		}	
+		
+    #if SOFT_SATRT		
     else if(SoftStartFlag == SET)  //启动处理
 		{
-			if(MC_ConfigParam1.StarModel == MC_StarMode_DYNAMIC)
+			if(MC_ConfigParam1.StarModel == MC_StarMode_DYNAMIC)  //强劲模式,无延迟
 			{
-				SoftStartDelayTime = 100;      //启动处理延时100ms
-				SoftStartAcc = 10;             //10ms递增0.1倍
-			}
-			else if(MC_ConfigParam1.StarModel == MC_StarMode_SOFT)
-			{
-				SoftStartDelayTime = 900;      //启动处理延时900ms
-				SoftStartAcc = 90;             //90ms递增0.1倍
+			  SoftStartDelayTimeCount = 0;
+				SoftStartFlag = RESET;
 			}
 			else
 			{
-				SoftStartDelayTime = 300;      //启动处理延时300ms
-				SoftStartAcc = 30;             //30ms递增0.1倍
-			}
-			SoftStartDelayTimeCount++;
-			if(SoftStartDelayTimeCount <= SoftStartDelayTime) // 缓启动过程,按照0.1倍率逐步增加加减速斜率
-			{  
-				if((MC_TorqueProcess_Param.TorqueRef - MC_TorqueProcess_Param.TorqueRefEnd) > 2)
+				if(MC_ConfigParam1.StarModel == MC_StarMode_SOFT)   //柔和模式,延迟300ms
+				{
+					SoftStartDelayTime = 300;      //启动处理延时300ms
+					SoftStartAcc = 30;             //30ms递增0.1倍
+				}
+				else                                                //正常模式,延迟100ms
 				{
-					if((SoftStartDelayTimeCount % (10 - SoftStartDelayTimeCount / SoftStartAcc))  == 0)
+					SoftStartDelayTime = 100;      //启动处理延时100ms
+					SoftStartAcc = 10;             //10ms递增0.1倍
+				}
+				SoftStartDelayTimeCount++;
+				if(SoftStartDelayTimeCount <= SoftStartDelayTime) // 缓启动过程,按照0.1倍率逐步增加加减速斜率
+				{  
+					if((MC_TorqueProcess_Param.TorqueRef - MC_TorqueProcess_Param.TorqueRefEnd) > 2)
+					{
+						if((SoftStartDelayTimeCount % (10 - SoftStartDelayTimeCount / SoftStartAcc))  == 0)
+						{
+							MC_TorqueProcess_Param.TorqueRefEnd += TorqueAccStep;
+						}
+					}
+					else if((MC_TorqueProcess_Param.TorqueRef - MC_TorqueProcess_Param.TorqueRefEnd) < (- 1))
 					{
-						MC_TorqueProcess_Param.TorqueRefEnd += TorqueAccStep;
+						MC_TorqueProcess_Param.TorqueRefEnd -= TorqueDecStep;
 					}
 				}
-				else if((MC_TorqueProcess_Param.TorqueRef - MC_TorqueProcess_Param.TorqueRefEnd) < (- 1))
+				else
 				{
-					MC_TorqueProcess_Param.TorqueRefEnd -= TorqueDecStep;
+					SoftStartDelayTimeCount = 0;
+					SoftStartFlag = RESET;
 				}
 			}
-			else
-			{
-				SoftStartDelayTimeCount = 0;
-				SoftStartFlag = RESET;
-			}
-		}		
+		}	
+    #endif
+		
 		else //正常骑行
 		{
 			if((MC_TorqueProcess_Param.TorqueRef - MC_TorqueProcess_Param.TorqueRefEnd) > 2)
@@ -1060,7 +1089,7 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
 		MC_TorqueProcess_Param.TorqueRefEnd = (MC_TorqueProcess_Param.TorqueRefEnd < 6) ? 6 : MC_TorqueProcess_Param.TorqueRefEnd;
 		
 		//限速点处理
-		if( MC_SpeedSensorData.Speed_Data > (MC_ConfigParam1.SpeedLimit * 10 + 20) ) //限速值+2
+		if( MC_SpeedSensorData.Speed_Data > (MC_ConfigParam1.SpeedLimit * 10 + 22) ) //限速值 + 2.2
 		{
 			MC_TorqueProcess_Param.MotorStopLock_Flag = SET;
 			MC_TorqueProcess_Param.TorqueRefEnd = 0;
@@ -1116,545 +1145,6 @@ MC_CalParam_Struct_t MC_AssistRunMode_Torque_Process(uint16_t SenorData, MC_Gear
 	return (p_MC_CalParam);
 }
 
-//力矩模式处理 城市版
-uint16_t candenceCount;      //踏频磁环信号计数变量,全局变量
-
-uint16_t torqueApp;
-uint16_t torque_NM;                       //力矩值,单位NM
-uint16_t torqueRank=0;                    //由踏频采样后的力矩值,得出的力矩给定
-static uint16_t torqueRankLast=0;        //力矩给定历史值
-static uint16_t torqueRankBak=0;           //力矩给定历史值备份
-static uint8_t flagUpDown=0;      //输入力矩上升、下降的标志位  
-
-static int32_t tmpFltSum=0;     //输入力矩滤波的静态变量
-int16_t  tmpFlted=0;            //输入力矩滤波的临时变量
-
-int16_t torqueApp2;             //力矩计算的临时变量
-
-uint8_t flagCandence=0;           //踏频信号更新标志
-int16_t torqueAppLag=0;           //力局地经过加减速处理后的临时变量
-int16_t torqueAppRatio=0;         //力矩值计算助力比后的临时变量
-
-int16_t torqueAppAccStep = 4; 		//力矩给定升速斜率
-int16_t torqueAppDecStep = 1;		 //力矩给定减速斜率
-
-uint16_t candenceBakAtTop=0;       //踏频最大值备份
-uint16_t torqueByCandenceDec=0;     //由踏频变化计算的力矩减弱量
-int16_t torqueDataFromCadence=0;		//经过踏频信号采样的力矩值
-int32_t Taping_activeFlt=0;   	 //踏频实时值滤波中间量
-int32_t Taping_activeFlted = 0;  	//踏频实时值滤波值
-
-#define TORQUE_TMP  28            //力矩AD值与1NM的换算系数
-
-MC_CalParam_Struct_t MC_AssistRunMode_Torque_compensation(uint16_t SenorData, MC_GearSt_Struct_t GearSt)
-{
-	MC_CalParam_Struct_t p_MC_CalParam = {MC_AssistRunMode_INVALID, 0,	0, RESET};
-	uint16_t TorqueStartData, TorqueStopData;//力矩启动值,力矩停机值
-	int32_t Torque_Ref_Temp;
-	static uint32_t TorqueStopDelayTimeCnt = 0;//低力矩停机计时
-	uint16_t TorqueStopDelayTime;
-	static int16_t IqRefByInPower;//限流计算结果
-	
-	static uint16_t CurrentLimitPresent;     //限流实际值,做升降速处理
-	uint16_t CurrentLimitSet; 
-	
-	static FlagStatus SoftStartFlag = SET;
-	static uint16_t SoftStartDelayTimeCount = 0;
-	uint16_t SoftStartDelayTime = 0;
-	uint16_t SoftStartAcc = 0;
-			
-	#if 0
-	//输入三角波,用于测试
-	static uint32_t WaveTime_Zero = 0;
-	static uint32_t Time_Enter = 0;
-	static uint16_t SensorDataDebug = 0;
-	if((HAL_GetTick() - Time_Enter) > 10) // 超时10ms未进入,波形发生初始时刻清零
-	{
-	  WaveTime_Zero = HAL_GetTick();
-	}
-	Time_Enter = HAL_GetTick();
-	SensorDataDebug  = TriangleWaveGenerate(WaveTime_Zero, 125, 250 ,1500);
-	SenorData = SensorDataDebug;
-  #endif
-	
-	MC_TorqueProcess_Param.TorqueApp = SenorData;
-	
-	/*为下一步抓取最大值,力矩需要滤波*/
-	tmpFltSum += (((int32_t )SenorData << 10) - tmpFltSum) >> 7;
-	tmpFlted = (int16_t)(tmpFltSum >> 10);
-	
-	torque_NM = tmpFlted / TORQUE_TMP ;  //转换为单位NM 的变量
-	
-	//低力矩停机
-	TorqueStopData = (MC_TorqueCorrectParam.StarData < 200) ? 100 : (MC_TorqueCorrectParam.StarData >> 1);
-  if(MC_TorqueProcess_Param.TorqueApp >= (TorqueStopData))
-  {
-    TorqueStopDelayTimeCnt = HAL_GetTick();
-  }
-  else
-  {
-		if(MC_RunInfo.MotorSpeed > 200)
-		{
-		  TorqueStopDelayTime = 218400 / MC_RunInfo.MotorSpeed; //60s / (电机转速 / 4.55 / 2.4) / 3,曲柄1/3圈
-		}
-		else
-		{
-		  TorqueStopDelayTime = 1200;
-		}
-		TorqueStopDelayTime= (TorqueStopDelayTime < 500) ? 500 : TorqueStopDelayTime;
-		
-    if((HAL_GetTick() - TorqueStopDelayTimeCnt) > TorqueStopDelayTime)//超时1200ms
-    {
-      MC_TorqueProcess_Param.MotorStopLock_Flag = SET;
-    }
-  }
-	
-	//启动值判断
-	if(MC_RunInfo.BikeSpeed > 60)
-	{
-		TorqueStartData =  (MC_TorqueCorrectParam.StarData < 200 ? 150 \
-																														 : (MC_TorqueCorrectParam.StarData > 700 ? 525 \
-																																																		 : (MC_TorqueCorrectParam.StarData * 3 / 4)));
-	}
-	else
-	{
-		TorqueStartData =  (MC_TorqueCorrectParam.StarData < 200 ? 150 \
-																														 : (MC_TorqueCorrectParam.StarData > 700 ? 525 \
-																																																		 : MC_TorqueCorrectParam.StarData));
-	}
-	if(MC_TorqueProcess_Param.TorqueApp >= TorqueStartData)
-	{
-		 MC_TorqueProcess_Param.MotorStopLock_Flag = RESET;
-	}
-	
-	//踏频反向或踏频停止停机
-	if((MC_CadenceResult.Cadence_Dir == MC_Cadence_Backward) ||
-		 (MC_CadenceResult.IsStopFlag == TRUE)		
-		)
-	{
-		MC_TorqueProcess_Param.MotorStopLock_Flag = SET;
-	}
-	
-	//停机状态,延时处理
-	if(MC_TorqueProcess_Param.MotorStopLock_Flag == SET) 
-	{
-		torqueRankBak = 0;
-		torqueAppDecStep = 6;//84;
-		
-	  if(MC_TorqueProcess_Param.TorqueRefEnd < 10)
-		{
-		  MC_TorqueProcess_Param.TorqueRefEnd = 0;
-			//停机处理
-			MC_MotorStop(&MC_StarFlag);
-			p_MC_CalParam.Foc_Flag = RESET;
-			//缓启动标志置位
-			SoftStartFlag = SET;
-			SoftStartDelayTimeCount = 0;
-		}
-		else
-		{
-		  MC_TorqueProcess_Param.TorqueRefEnd -= 7;
-			MC_MotorStar(&MC_StarFlag);
-		}
-		torqueAppLag = MC_TorqueProcess_Param.TorqueRefEnd;
-	}
-	else
-	{
-			if(flagCandence==1)
-			{
-				flagCandence = 0;
-				
-				torqueRank = torqueDataFromCadence;     //根据踏频磁环信号采样力矩值
-				
-				if(torqueRank > torqueRankLast)     //比较本次与上次的值
-				{
-					
-					if(flagUpDown==0)
-					{
-						//最低点
-					}
-					 
-					if(torqueRank > torqueRankBak)    //与当前使用的值比较
-					{
-						torqueRankBak = torqueRank;
-						candenceCount = 0;
-						torqueAppDecStep = 1;
-						torqueByCandenceDec = 0;
-					}
-					
-					flagUpDown=1;// 力矩上升标志
-				}
-				else if(torqueRank < torqueRankLast)
-				{
-					if(flagUpDown==1)
-					{	
-						//最高点
-						torqueRankBak = torqueRankLast;
-						candenceCount = 0;
-						torqueAppDecStep = 1;//14;
-						
-						/*备份力矩最高点的踏频*/
-						candenceBakAtTop = Taping_activeFlted;
-						torqueByCandenceDec = 0;
-					}
-					flagUpDown=0;  //降	
-				}
-				
-				torqueRankLast = torqueRank;     //记录上一次的值
-				
-				if(candenceCount > 60)          //没有力矩信号, 踏频信号超过360度,加大降速值,清零给定
-				{
-					torqueRankBak  = 0;
-					torqueAppDecStep = 6;//84;
-				}
-				else if(candenceCount > 35)  //超过210度,没有力矩信号
-				{
-					torqueRankBak  = 0;
-					torqueAppDecStep = 2;
-					
-					if((Taping_activeFlted < (candenceBakAtTop - 3)) && (tmpFlted<100))
-					{		
-						torqueAppDecStep = 6;
-					}
-				}
-				else // (candenceCount < 35)  
-				{
-					/*踏频降低,且力矩低*/
-					if((Taping_activeFlted < (candenceBakAtTop - 3)) && (tmpFlted<100))
-					{
-						torqueByCandenceDec +=3;			
-						torqueAppDecStep = 6;
-					}
-				}
-
-				torqueApp2  = torqueRankBak - torqueByCandenceDec;
-				//torqueApp2  = torqueRankBak;
-				torqueApp2 = torqueApp2 > 0 ? torqueApp2 : 0;
-				
-				//转换力矩值为力矩控制量
-				torqueApp = torqueApp2  * TORQUE_TMP ;
-				
-			}/*if(flagCandence==1)*/
-			
-			if(GearSt == 0x33)
-			{
-				torqueAppRatio = ((int32_t)torqueApp * torqueApp / (MC_AssisParam.Gear_SMART.i_Sport_TH));
-				
-				torqueAppRatio = (int16_t)((int32_t)torqueAppRatio *  MC_ConfigParam1.UserAdjParam_SMART.Assist_K_GAIN / 100);   //上位机助力比增益调节
-				
-				//加速增益调节
-				if(MC_ConfigParam1.UserAdjParam_SMART.StarModel_GAIN <= 80)
-				{
-					torqueAppAccStep = MC_AssisParam.Gear_SMART.AccCnt - 1;
-				}
-				else if(MC_ConfigParam1.UserAdjParam_SMART.StarModel_GAIN >= 120)
-				{
-					torqueAppAccStep = MC_AssisParam.Gear_SMART.AccCnt + 1;
-				}
-				else
-				{
-				  torqueAppAccStep = MC_AssisParam.Gear_SMART.AccCnt;
-				}
-				
-				//给定上限
-				torqueAppRatio = (torqueAppRatio > MC_AssisParam.Gear_SMART.Upper_Iq) ? MC_AssisParam.Gear_SMART.Upper_Iq : torqueAppRatio;
-			
-				//限流参数设置
-				CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_SMART.CurrentMax_K * MC_ConfigParam1.CurrentLimit * 1000 >> 17) * MC_CadenceLimit_K;
-				CurrentLimitPresent = MC_DataSet_Linear_Process(CurrentLimitSet, CurrentLimitPresent, 5 ,1);
-				PID_IMax.hLower_Limit_Output = -(MC_AssisParam.Gear_SMART.Upper_Iq);   //Lower Limit for Output limitation
-				PID_IMax.hUpper_Limit_Output = 0; //Upper Limit for Output limitation
-				PID_IMax.wLower_Limit_Integral = -(MC_AssisParam.Gear_SMART.Upper_Iq << 10); // 放大1024
-				PID_IMax.wUpper_Limit_Integral = 0; // 放大1024
-				
-			}
-			else
-			{
-				switch( GearSt & 0x0F )
-				{
-					case 1:
-						//torqueAppRatio = torqueApp * 0.5;								
-						//torqueAppRatio = (int16_t)((uint32_t)(torqueApp * Coefficient_GainCal( 51 ,410, 1300, torqueApp)) >> 10 ); //0.4
-						torqueAppRatio = (int16_t)((uint32_t)(torqueApp * Coefficient_GainCal( 51 ,MC_AssisParam.Gear_ECO.Gain_K, 1300, torqueApp)) >> 10 ); //0.4
-						torqueAppRatio = (int16_t)((int32_t)torqueAppRatio *  MC_ConfigParam1.UserAdjParam_ECO.Assist_K_GAIN / 100);   //上位机助力比增益调节
-				
-						//加速增益调节
-						if(MC_ConfigParam1.UserAdjParam_ECO.StarModel_GAIN <= 80)
-						{
-							torqueAppAccStep = MC_AssisParam.Gear_ECO.AccCnt - 1;
-						}
-						else if(MC_ConfigParam1.UserAdjParam_ECO.StarModel_GAIN >= 120)
-						{
-							torqueAppAccStep = MC_AssisParam.Gear_ECO.AccCnt + 1;
-						}
-						else
-						{
-						  torqueAppAccStep = MC_AssisParam.Gear_ECO.AccCnt;
-						}
-					
-						//给定上限
-						torqueAppRatio = (torqueAppRatio > MC_AssisParam.Gear_ECO.Upper_Iq) ? MC_AssisParam.Gear_ECO.Upper_Iq : torqueAppRatio;
-						//限流参数设置			
-						CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_ECO.CurrentMax_K * MC_ConfigParam1.CurrentLimit * 1000 >> 17) * 100;
-						CurrentLimitPresent = MC_DataSet_Linear_Process(CurrentLimitSet, CurrentLimitPresent, 5 ,1);
-					
-						PID_IMax.hLower_Limit_Output = -(MC_AssisParam.Gear_ECO.Upper_Iq);   //Lower Limit for Output limitation
-						PID_IMax.hUpper_Limit_Output = 0; //Upper Limit for Output limitation
-						PID_IMax.wLower_Limit_Integral = -(MC_AssisParam.Gear_ECO.Upper_Iq << 10); // 放大1024
-						PID_IMax.wUpper_Limit_Integral = 0; // 放大1024
-						
-						break;
-					case 2:
-						//torqueAppRatio = torqueApp * 0.8;						
-						//torqueAppRatio = (int16_t)((uint32_t)(torqueApp * Coefficient_GainCal( 102 ,717, 1300, torqueApp)) >> 10 );  //0.7
-						torqueAppRatio = (int16_t)((uint32_t)(torqueApp * Coefficient_GainCal( 102 ,MC_AssisParam.Gear_NORM.Gain_K, 1300, torqueApp)) >> 10 );  //0.7
-						torqueAppRatio = (int16_t)((int32_t)torqueAppRatio *  MC_ConfigParam1.UserAdjParam_NORM.Assist_K_GAIN / 100);   //上位机助力比增益调节
-						
-						//加速增益调节
-						if(MC_ConfigParam1.UserAdjParam_NORM.StarModel_GAIN <= 80)
-						{
-							torqueAppAccStep = MC_AssisParam.Gear_NORM.AccCnt - 1;
-						}
-						else if(MC_ConfigParam1.UserAdjParam_NORM.StarModel_GAIN >= 120)
-						{
-							torqueAppAccStep = MC_AssisParam.Gear_NORM.AccCnt + 1;
-						}
-						else
-						{
-						  torqueAppAccStep = MC_AssisParam.Gear_NORM.AccCnt;
-						}
-					
-						//给定上限
-						torqueAppRatio = (torqueAppRatio > MC_AssisParam.Gear_NORM.Upper_Iq) ? MC_AssisParam.Gear_NORM.Upper_Iq : torqueAppRatio;
-					
-						//限流参数设置
-						CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_NORM.CurrentMax_K * MC_ConfigParam1.CurrentLimit * 1000 >> 17) * 100;
-						CurrentLimitPresent = MC_DataSet_Linear_Process(CurrentLimitSet, CurrentLimitPresent, 5 ,1);
-						
-						PID_IMax.hLower_Limit_Output = -(MC_AssisParam.Gear_NORM.Upper_Iq);   //Lower Limit for Output limitation
-						PID_IMax.hUpper_Limit_Output = 0; //Upper Limit for Output limitation
-						PID_IMax.wLower_Limit_Integral = -(MC_AssisParam.Gear_NORM.Upper_Iq << 10); // 放大1024
-						PID_IMax.wUpper_Limit_Integral = 0; // 放大1024
-					  
-						break;
-					
-					case 3:
-						//torqueAppRatio = torqueApp * 1.0;					
-						//torqueAppRatio = (int16_t)((uint32_t)(torqueApp * Coefficient_GainCal( 204 ,1024, 1300, torqueApp)) >> 10 ); //1.0
-						torqueAppRatio = (int16_t)((uint32_t)(torqueApp * Coefficient_GainCal( 204 , MC_AssisParam.Gear_SPORT.Gain_K, 1300, torqueApp)) >> 10 ); //1.0
-						torqueAppRatio = (int16_t)((int32_t)torqueAppRatio *  MC_ConfigParam1.UserAdjParam_SPORT.Assist_K_GAIN / 100);   //上位机助力比增益调节
-						
-						//加速增益调节
-						if(MC_ConfigParam1.UserAdjParam_SPORT.StarModel_GAIN <= 80)
-						{
-							torqueAppAccStep = MC_AssisParam.Gear_SPORT.AccCnt - 1;
-						}
-						else if(MC_ConfigParam1.UserAdjParam_SPORT.StarModel_GAIN >= 120)
-						{
-							torqueAppAccStep = MC_AssisParam.Gear_SPORT.AccCnt + 1;
-						}
-						else
-						{
-						  torqueAppAccStep = MC_AssisParam.Gear_SPORT.AccCnt;
-						}
-					
-						//给定上限
-						torqueAppRatio = (torqueAppRatio > MC_AssisParam.Gear_SPORT.Upper_Iq) ? MC_AssisParam.Gear_SPORT.Upper_Iq : torqueAppRatio;;
-					
-						//限流参数设置
-						CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_SPORT.CurrentMax_K * MC_ConfigParam1.CurrentLimit * 1000 >> 17) * MC_CadenceLimit_K;
-						CurrentLimitPresent = MC_DataSet_Linear_Process(CurrentLimitSet, CurrentLimitPresent, 5 ,1);
-						PID_IMax.hLower_Limit_Output = -(MC_AssisParam.Gear_SPORT.Upper_Iq);   //Lower Limit for Output limitation
-						PID_IMax.hUpper_Limit_Output = 0; //Upper Limit for Output limitation
-						PID_IMax.wLower_Limit_Integral = -(MC_AssisParam.Gear_SPORT.Upper_Iq << 10); // 放大1024
-						PID_IMax.wUpper_Limit_Integral = 0; // 放大1024
-					
-					  break;
-					
-					case 4:
-						//torqueAppRatio = torqueApp * 1.5;
-						//torqueAppRatio = (int16_t)((uint32_t)(torqueApp * Coefficient_GainCal( 307 ,1536, 1300, torqueApp)) >> 10 );  // 1.5
-						torqueAppRatio = (int16_t)((uint32_t)(torqueApp * Coefficient_GainCal( 307 ,MC_AssisParam.Gear_TURBO.Gain_K, 1300, torqueApp)) >> 10 );  // 1.5
-						torqueAppRatio = (int16_t)((int32_t)torqueAppRatio *  MC_ConfigParam1.UserAdjParam_TURBO.Assist_K_GAIN / 100);   //上位机助力比增益调节
-					
-						//加速增益调节
-						if(MC_ConfigParam1.UserAdjParam_TURBO.StarModel_GAIN <= 80)
-						{
-							torqueAppAccStep = MC_AssisParam.Gear_TURBO.AccCnt - 1;
-						}
-						else if(MC_ConfigParam1.UserAdjParam_TURBO.StarModel_GAIN >= 120)
-						{
-							torqueAppAccStep = MC_AssisParam.Gear_TURBO.AccCnt + 1;
-						}
-						else
-						{
-						  torqueAppAccStep = MC_AssisParam.Gear_TURBO.AccCnt;
-						}
-					
-						//给定上限
-						torqueAppRatio = (torqueAppRatio > MC_AssisParam.Gear_TURBO.Upper_Iq) ? MC_AssisParam.Gear_TURBO.Upper_Iq : torqueAppRatio;
-					
-						//限流参数设置
-						CurrentLimitSet = (uint32_t)(MC_AssisParam.Gear_TURBO.CurrentMax_K * MC_ConfigParam1.CurrentLimit * 1000 >> 17) * MC_CadenceLimit_K;
-						CurrentLimitPresent = MC_DataSet_Linear_Process(CurrentLimitSet, CurrentLimitPresent, 5 ,1);
-						PID_IMax.hLower_Limit_Output = -(MC_AssisParam.Gear_TURBO.Upper_Iq);   //Lower Limit for Output limitation
-						PID_IMax.hUpper_Limit_Output = 0; //Upper Limit for Output limitation
-						PID_IMax.wLower_Limit_Integral = -(MC_AssisParam.Gear_TURBO.Upper_Iq << 10); // 放大1024
-						PID_IMax.wUpper_Limit_Integral = 0; // 放大1024
-					
-					  break;
-					
-					default:break;
-				}
-			}
-	
-			//给定上限
-			torqueAppRatio = (torqueAppRatio > MC_AssisParam.Gear_TURBO.Upper_Iq) ? MC_AssisParam.Gear_TURBO.Upper_Iq : torqueAppRatio;
-							
-			//随车速调节助力比
-			#if 0
-			if(MC_ConfigParam1.StarModel == MC_StarMode_DYNAMIC)
-			{
-				torqueAppRatio = (uint16_t)((uint32_t)(torqueAppRatio * Function_Linear_3Stage(90, -2, MC_ConfigParam1.SpeedLimit * 10, 160, MC_RunInfo.BikeSpeed)) >> 10);
-			}
-			else if(MC_ConfigParam1.StarModel == MC_StarMode_SOFT)
-			{
-				torqueAppRatio = (uint16_t)((uint32_t)(torqueAppRatio * Function_Linear_3Stage(120, -3, MC_ConfigParam1.SpeedLimit * 10, 160, MC_RunInfo.BikeSpeed)) >> 10);
-			}
-			else
-			{
-				torqueAppRatio = (uint16_t)((uint32_t)(torqueAppRatio * Function_Linear_3Stage(MC_ConfigParam1.SpeedLimit * 10, 0, MC_ConfigParam1.SpeedLimit * 10, 160, MC_RunInfo.BikeSpeed)) >> 10);
-			}
-			#elif 1
-			torqueAppRatio = (uint16_t)((uint32_t)(torqueAppRatio * Function_Linear_3Stage(MC_ConfigParam1.SpeedLimit * 10, 0, MC_ConfigParam1.SpeedLimit * 10, 160, MC_RunInfo.BikeSpeed)) >> 10);
-			#endif
-				
-			//力矩给定处理
-			if(SoftStartFlag == SET)  //启动处理
-			{
-				if(MC_ConfigParam1.StarModel == MC_StarMode_DYNAMIC)
-				{
-					SoftStartDelayTime = 100;      //启动处理延时100ms
-					SoftStartAcc = 10;             //10ms递增0.1倍
-				}
-				else if(MC_ConfigParam1.StarModel == MC_StarMode_SOFT)
-				{
-					SoftStartDelayTime = 900;      //启动处理延时900ms
-					SoftStartAcc = 90;             //90ms递增0.1倍
-				}
-				else
-				{
-					SoftStartDelayTime = 300;      //启动处理延时300ms
-					SoftStartAcc = 30;             //30ms递增0.1倍
-				}
-				SoftStartDelayTimeCount++;
-				if(SoftStartDelayTimeCount <= SoftStartDelayTime) // 缓启动过程,按照0.1倍率逐步增加加减速斜率
-				{  
-					if(torqueAppRatio > torqueAppLag)
-					{
-						if((SoftStartDelayTimeCount % (10 - SoftStartDelayTimeCount / SoftStartAcc)) == 0)
-						{
-							torqueAppLag += torqueAppAccStep;
-							if(torqueAppLag > torqueAppRatio)
-							{
-								torqueAppLag = torqueAppRatio;
-							}
-						}
-					}
-					else if(torqueAppRatio < torqueAppLag)
-					{
-						torqueAppLag -= torqueAppDecStep;
-						if(torqueAppLag < torqueAppRatio)
-						{
-							torqueAppLag = torqueAppRatio;
-						}
-					}
-				}
-				else
-				{
-					SoftStartDelayTimeCount = 0;
-					SoftStartFlag = RESET;
-				}
-			}
-			else //正常骑行
-			{
-				if(torqueAppRatio > torqueAppLag)
-				{
-					torqueAppLag += torqueAppAccStep;
-					if(torqueAppLag > torqueAppRatio)
-					{
-						torqueAppLag = torqueAppRatio;
-					}
-				}
-				else if(torqueAppRatio < torqueAppLag)
-				{
-					torqueAppLag -= torqueAppDecStep;
-					if(torqueAppLag < torqueAppRatio)
-					{
-						torqueAppLag = torqueAppRatio;
-					}
-				}	
-			}
-					
-			MC_TorqueProcess_Param.TorqueRefEnd = torqueAppLag;		
-			MC_TorqueProcess_Param.TorqueRefEnd = (MC_TorqueProcess_Param.TorqueRefEnd < 6) ? 6 : MC_TorqueProcess_Param.TorqueRefEnd;
-			
-			//限速点处理
-			if( MC_SpeedSensorData.Speed_Data > (MC_ConfigParam1.SpeedLimit * 10 + 20) ) //限速值+2
-			{
-				MC_TorqueProcess_Param.MotorStopLock_Flag = SET;
-				MC_TorqueProcess_Param.TorqueRefEnd = 0;
-				//停机处理
-				MC_MotorStop(&MC_StarFlag);
-			}
-			#if 0  //低于限速点启动电机
-			else if(MC_RunInfo.BikeSpeed < ((MC_ConfigParam.SpeedLimit) * 10))
-			{
-				MC_MotorStar(&MC_StarFlag);
-			}
-			#elif 1  //低于断电点即启动电机
-			else
-			{
-				MC_MotorStar(&MC_StarFlag);
-			}
-			#endif
-	}
-	
-	#if 1
-	static uint16_t K_ByVoltage_Set_Old = 1024;
-	uint16_t K_ByVoltage_Set;
-	static uint16_t K_ByVoltage_Result;
-	uint16_t K_ByTemperature_Set;
-	static uint16_t K_ByTemperature_Result;
-
-	//根据电压调节输出
-  K_ByVoltage_Set = MC_Cal_K_ByVoltage(MC_RunInfo.BusVoltage, MC_MotorParam.Rate_Voltage, K_ByVoltage_Set_Old);//根据母线电压计算衰减比例,递减
-	K_ByVoltage_Set_Old = K_ByVoltage_Set;
-  K_ByVoltage_Result = MC_DataSet_Linear_Process(K_ByVoltage_Set, K_ByVoltage_Result, 1, 1); //设定值与给定值线性处理
-	
-	//根据温度调节输出
-	K_ByTemperature_Set = MC_Cal_K_ByTemperature(MC_RunInfo.T_Coil, MC_ConfigParam1.TempTH_Alarm); //根据温度计算衰减比例
-	K_ByTemperature_Result = MC_DataSet_Linear_Process(K_ByTemperature_Set, K_ByTemperature_Result, 1, 1); //设定值与给定值线性处理
-	
-	#else
-	
-	uint16_t K_ByVoltage_Result = 1024;
-	uint16_t K_ByTemperature_Result = 1024;
-	#endif
-	
-  //限流计算
-  IqRefByInPower =  PID_Regulator(CurrentLimitPresent / 100, (MC_RunInfo.BusCurrent >> 7), &PID_IMax);
-	
-	Torque_Ref_Temp = ((int32_t)MC_TorqueProcess_Param.TorqueRefEnd * K_ByVoltage_Result) >> 10;
-	Torque_Ref_Temp = (Torque_Ref_Temp * K_ByTemperature_Result) >> 10;
-	Torque_Ref_Temp = (Torque_Ref_Temp + IqRefByInPower) >> 1;
-	
-	p_MC_CalParam.Ref_Torque = (int16_t)Torque_Ref_Temp;
-	p_MC_CalParam.Foc_Flag = SET;
-	p_MC_CalParam.AssistRunMode = MC_AssistRunMode_TORQUE;
-	 
-	return (p_MC_CalParam);
-}
 
 /******************************全局函数定义*****************************/
 //传感器初始化
@@ -1815,10 +1305,7 @@ void MC_CalParam_Cal(MC_WorkMode_Struct_t p_MC_WorkMode, \
 		case MC_AssistRunMode_TORQUE:
 		{
 			//计算FOC控制输入
-			//*p_MC_CalParam = MC_AssistRunMode_Torque_Process(p_ADC_SensorData.TorqueSensor, GearSt);
-			
-			*p_MC_CalParam = MC_AssistRunMode_Torque_compensation(p_ADC_SensorData.TorqueSensor, GearSt);
-			
+			*p_MC_CalParam = MC_AssistRunMode_Torque_Process(p_ADC_SensorData.TorqueSensor, GearSt, MC_CadenceResult.torqueByCadence);
 			//助力模式切换标志复位
 			MC_AssistRunMode_ShiftFlag = RESET;
 			break;

+ 17 - 10
User/Src/protect_check.c

@@ -11,7 +11,7 @@ FlagStatus MC_Protect_OverCurrentTrig_Flag = RESET;
 
 /******************************局部函数定义******************************/
 //低压保护检测
-void MC_Protect_UnderVoltage_Process(uint16_t BusVoltage, uint8_t DesignVoltage, MC_ErrorCode_Struct_t* p_MC_ErrorCode)
+void MC_Protect_UnderVoltage_Process(uint16_t BusVoltage, uint8_t DesignVoltage, uint16_t UV_TH, MC_ErrorCode_Struct_t* p_MC_ErrorCode)
 {
   static uint32_t uvTimeCnt = 0;
 	static uint32_t uvFaultTimeCnt = 0;
@@ -22,17 +22,17 @@ void MC_Protect_UnderVoltage_Process(uint16_t BusVoltage, uint8_t DesignVoltage,
 	{
 		case 24:
 		{
-			UV_Voltage = 3100 * 7;//低压保护时,电芯电压为3100mV
+			UV_Voltage = UV_TH * 7;//低压保护时,电芯电压为3100mV
 		  break;
 		}
 		case 36:
 		{
-			UV_Voltage = 3100 * 10;//低压保护时,电芯电压为3100mV
+			UV_Voltage = UV_TH * 10;//低压保护时,电芯电压为3100mV
 		  break;
 		}
 		case 48:
 		{
-			UV_Voltage = 3100 * 13;//低压保护时,电芯电压为3100mV
+			UV_Voltage = UV_TH * 13;//低压保护时,电芯电压为3100mV
 		  break;
 		}
 		default:
@@ -304,9 +304,16 @@ void MC_Protect_VoltageChange_Process(uint16_t Voltage, uint16_t Current, MC_Err
 }
 
 /******************************全局函数定义******************************/
-#define OC_CLEARFLAG_DELAYTIME 15 //过流标志清零延时,单位ms
-#define OC_COUNTER_TH 200         //过流保护计数判断阈值
+#define OC_CLEARFLAG_DELAYTIME 15 //过流标志间隔清零延时,单位ms
+#define OC_COUNTER_TH 100          //过流保护计数判断阈值
 //过流保护检测
+/*
+检测原理:
+1、过流触发后,OverCurrentTrigFlag置位,封波2个周期后再次发波;
+2、在过流触发计数达到OC_COUNTER_TH 次之前,如果存在两次过流触发间隔时间超过OC_CLEARFLAG_DELAYTIME ms,清除过流触发计数;
+3、如果每两次过流触发间隔时间都不超过OC_CLEARFLAG_DELAYTIME ms,当过流触发计数达到OC_COUNTER_TH 次,则进入过流保护;
+4、进入过流保护后,超时5s解除。
+*/
 void MC_Protect_OverCurrent_Process(FlagStatus* OverCurrentTrigFlag, MC_ErrorCode_Struct_t* p_MC_ErrorCode)
 {
   static uint8_t OffPwmCnt = 0;        //过流信号触发后,关闭PWM延时计数
@@ -321,7 +328,7 @@ void MC_Protect_OverCurrent_Process(FlagStatus* OverCurrentTrigFlag, MC_ErrorCod
 		{
 			//关闭PWM计数清零
 			OffPwmCnt = 0;
-			//超时OC_CLEARFLAG_DELAYTIME ms过流次数未达到OC_COUNTER_TH 次,过流计数清零
+			//两次过流触发间隔超时OC_CLEARFLAG_DELAYTIME ms过流次数未达到OC_COUNTER_TH 次,过流计数清零
 			if(ocCnt < OC_COUNTER_TH)
 			{
 				if((HAL_GetTick() - ocTimeCnt) >= OC_CLEARFLAG_DELAYTIME)
@@ -339,7 +346,7 @@ void MC_Protect_OverCurrent_Process(FlagStatus* OverCurrentTrigFlag, MC_ErrorCod
 		}
 		else
 		{
-			//开启PPWM计数清零
+			//开启PWM计数清零
 			StarPwmCnt = 0;
 			//关闭PWM
 			Disable_PwmGpio_Out();
@@ -362,7 +369,7 @@ void MC_Protect_OverCurrent_Process(FlagStatus* OverCurrentTrigFlag, MC_ErrorCod
 				//记录故障日志
 			  ErrorLogSave_Update(&MC_ErrorLogSaveInfo);
 		  	IsErrorLogSaveInfoUpdateFlag = TRUE;
-				//存储故障次数,此处在TIM中断中进行存储,可能存在问题
+				//存储故障次数
 				MC_RunLog1.OC_ProtectCnt++;
 				RunLogSaveIndex = 1;	
 			}
@@ -386,7 +393,7 @@ void MC_Protect_OverCurrent_Process(FlagStatus* OverCurrentTrigFlag, MC_ErrorCod
 void MC_Protect_Check_Process(void)
 {
 	//低压保护检测
-	MC_Protect_UnderVoltage_Process(MC_RunInfo.BusVoltage, MC_MotorParam.Rate_Voltage, &MC_ErrorCode);
+	MC_Protect_UnderVoltage_Process(MC_RunInfo.BusVoltage, MC_MotorParam.Rate_Voltage, ((MC_ConfigParam1.UV_Protect_TH == 0) ? 3100 : MC_ConfigParam1.UV_Protect_TH), &MC_ErrorCode);
 
 	//过压保护检测
 	MC_Protect_OverVoltage_Process(MC_RunInfo.BusVoltage, MC_MotorParam.Rate_Voltage, &MC_ErrorCode);

+ 18 - 14
User/Src/remain_distance.c

@@ -25,7 +25,8 @@
 extern const MC_AvgPower_Struct_t MC_AvgPower_Default;
 
 //续航计算相关参数
-Remain_Dis_t RemainDis;
+
+Remain_Dis_t RemainDis = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFFFF, 0, 0, FALSE, 0};
 //电池信息
 Battery_Info_t Battery_Info;
 
@@ -52,10 +53,10 @@ static void RD_getQRemainRecord(uint16_t Volgate)
 	BusVoltage = Volgate;
 	
 	//查表读取电池电量
-	num = sizeof(battery_VoltageQuantity)/4;
+	num = sizeof(battery_VoltageQuantity) / 4;
 	batteryTotalQ = battery_VoltageQuantity[num-1][1];
 	batteryRemainQ = batteryTotalQ;
-	for(i=0;i<num;i++)
+	for(i=0; i<num; i++)
 	{
 		if(battery_VoltageQuantity[i][0] <=  BusVoltage)
 		{
@@ -86,30 +87,33 @@ static void RD_getQRemainRecord(uint16_t Volgate)
 *          20181221      V1.2          Damon             modify
 * 
 *******************************************************************************/
-void RD_RemainDis_Init(uint16_t uwWheelLength, uint16_t BusVoltage, uint8_t DesignVol)
+void RD_RemainDis_Init(uint16_t uwWheelLength, TrueOrFalse_Flag_Struct_t BMS_COM_OK, uint16_t BusVoltage, uint8_t DesignVol, uint16_t BMS_RC)
 {
 	Battery_Info.Q_discharged = 0;
 	Battery_Info.Q_remain_real = 0;
 	Battery_Info.Q_remain_record = BATTERY_TATAL_Q_MAH;
 	Battery_Info.Q_remain_real_last = 0;
 	
-#if RD_BATTERY_INFO_TABLE
-	/*配置不带CAN通讯的电池时调用,上电读取电池电压,查表获得剩余电量,放电曲线是按照36V,针对48V或24V做等效转换*/
-       RD_getQRemainRecord(BusVoltage * 36 / DesignVol);
-	RemainDis.IsBMS_ComOK_Flag = FALSE;
-#endif
+	if(BMS_COM_OK == TRUE) //电池通讯正常时,直接获取电池容量
+	{
+	  Battery_Info.Q_remain_real = BMS_RC;
+	}
+	else //电池不含通讯时,根据母线电压估算剩余容量
+	{
+	  RD_getQRemainRecord(BusVoltage * 36 / DesignVol); //放电曲线是按照36V,针对48V或24V做等效转换
+	}
 	
-	RemainDis.acc_period = Q_ADD_TIME_MS;
-	RemainDis.wheel_Count = 0;
+	RemainDis.start = 0;
 	RemainDis.I_motor = 0;
+	RemainDis.acc_period = Q_ADD_TIME_MS;
 	RemainDis.Q_add = 0;
 	RemainDis.wheelLength = uwWheelLength;
-	RemainDis.flag_saveInfo = 0;
-	RemainDis.flag_helpModeChange = 0;
+	RemainDis.wheel_Count = 0;
 	RemainDis.Power_per_km = 0;
 	RemainDis.Power_per_km_average = 0;
 	RemainDis.remainDistance = 0xFFFF;//码表显示---km
-	RemainDis.start = 0;
+	RemainDis.flag_saveInfo = 0;
+	RemainDis.flag_helpModeChange = 0;
 	RemainDis.IsBMS_ComOK_Flag = FALSE;
 	RemainDis.BMS_Com_DelayTimeCnt = HAL_GetTick();	
 	

+ 1 - 1
User/Src/speed_sensor.c

@@ -17,7 +17,7 @@ void SpeedSensor_GPIO_Init(void)
 {
    GPIO_InitTypeDef GPIO_InitStruct;
 
-	__HAL_RCC_GPIOB_CLK_ENABLE();
+	__HAL_RCC_GPIOD_CLK_ENABLE();
 	
   GPIO_InitStruct.Pin = SPEED_SENSOR_Pin;
   GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;

+ 16 - 0
User/Src/stm32f10x_svpwm_3shunt.c

@@ -2,6 +2,7 @@
 #include "MC_const.h"
 #include "adc.h"
 #include "pwm_driver.h"
+#include "log_save.h"
 
 //全局变量定义
 
@@ -56,6 +57,13 @@ void SVPWM_3ShuntCurrentReadingCalibration(MC_ErrorCode_Struct_t* p_MC_ErrorCode
 	  )
 	{
 	  p_MC_ErrorCode->ERROR_Bit.Fault_Circuit = 1;
+		//记录故障日志
+		MC_ErrorLogSaveInfo.NotesInfo1 = 6;
+		ErrorLogSave_Update(&MC_ErrorLogSaveInfo);
+		IsErrorLogSaveInfoUpdateFlag = TRUE;
+		//存储故障次数
+		MC_RunLog2.Circuit_FaultCnt++;
+		RunLogSaveIndex = 2;
 	}
 	
 	Disable_Pwm_Output();
@@ -98,6 +106,14 @@ void CurrentReadingCalibration(MC_ErrorCode_Struct_t* p_MC_ErrorCode)
 			if((uw_current_offset < 1000) || (uw_current_offset > 3000))
 			{
 			  p_MC_ErrorCode->ERROR_Bit.Fault_Circuit = 1;
+				//记录故障日志
+				MC_ErrorLogSaveInfo.NotesInfo1 = 7;
+				MC_ErrorLogSaveInfo.NotesInfo2 = uw_current_offset;
+				ErrorLogSave_Update(&MC_ErrorLogSaveInfo);
+				IsErrorLogSaveInfoUpdateFlag = TRUE;
+				//存储故障次数
+				MC_RunLog2.Circuit_FaultCnt++;
+				RunLogSaveIndex = 2;
 			}
 			PeriodTimeCnt = HAL_GetTick();
 		}

+ 2 - 2
User/Src/tasks.c

@@ -33,7 +33,6 @@ void HAL_SYSTICK_Callback(void)
 	static uint16_t TimeCnt_50ms = 0;
 	static uint16_t TimeCnt_100ms = 0;
 	static uint16_t TimeCnt_1000ms = 0;
-
 	
 	if(IsInitFinish_Flag == FALSE)
 	{
@@ -138,7 +137,8 @@ void MC_RunInfo_Update(void)
 	  PeriodTimeCnt = HAL_GetTick();
 		
 		//计算电功率
-		MC_RunInfo.Power = (uint16_t)((uint32_t)(MC_RunInfo.BusCurrent / 100 * MC_RunInfo.BusVoltage / 100) / 100) / 2;
+//		MC_RunInfo.Power = (uint16_t)((uint32_t)(MC_RunInfo.BusCurrent / 100 * MC_RunInfo.BusVoltage / 100) / 100) / 2;
+		MC_RunInfo.Power = ((uint32_t)MC_RunInfo.BusCurrent) * 25 / (MC_ConfigParam1.CurrentLimit*100);
 		MC_RunInfo.Power = (MC_RunInfo.Power < 20) ? 0 : MC_RunInfo.Power;
 		
 		//更新踏频方向

+ 1 - 1
User/Src/tim.c

@@ -205,7 +205,7 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
     PA0-WKUP     ------> TIM2_ETR 
     */
     GPIO_InitStruct.Pin = GPIO_PIN_0;
-    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+    GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
     GPIO_InitStruct.Pull = GPIO_NOPULL;
     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

+ 75 - 72
User/Src/var.c

@@ -36,7 +36,7 @@ ComOK_Check_Struct_t IsComOK_PBU = {FALSE, 0};            //PBU通
 ComOK_Check_Struct_t IsComOK_HMI = {FALSE, 0};            //HMI通信状态标志
 ComOK_Check_Struct_t IsComOK_BMS = {FALSE, 0};            //BMS通信状态标志
 MC_AttitudeAngle_Struct_t MC_AttitudeAngle;               //姿态传感器数值
-MC_RideLog_Struct_t MC_RideLog;
+MC_RideLog_Struct_t MC_RideLog;                    //骑行历史
 MC_AvgPower_Struct_t MC_AvgPower;                         //助力平均功耗
 
 //BMS默认设计信息
@@ -64,7 +64,7 @@ const MC_ConfigParam1_Struct_t MC_ConfigParam1_Default =
 	(uint8_t)3,                                      //下降速度
 	(uint8_t)14,                                     //前齿数 T
 	(uint8_t)9,                                      //后齿数 T
-	(uint8_t)16,                                     //限流 A
+	(uint8_t)15,                                     //限流 A
 	(uint8_t)135,                                    //高温预警值 +40℃
 	(uint8_t)165,                                    //高温保护值 +40℃
   (MC_SupportFlag_Struct_t)MC_SUPPORT_DISABLE,     //无码表支持,0x55-不支持,0x-AA支持	
@@ -78,7 +78,10 @@ const MC_ConfigParam1_Struct_t MC_ConfigParam1_Default =
 	(uint8_t)1,                                      //速度传感器极数
 	(uint8_t)2,                                      //踏频启动信号个数
 	(MC_SpeedSignal_Struct_t)MC_SPEED_WHEEL_TRIG,    //速度信号来源,0x55-车轮触发,0x-AA踏频估算,0x-EE通信获取车轮旋转周期	
-	(int8_t)0                                        //轮胎周长微调值                                        
+	(int8_t)0,                                       //轮胎周长微调值 
+	(uint16_t)3100,                                  //低压保护阈值,单位mV,针对单节电芯的设置值	
+  (uint8_t)60,                                     //推行限速值,单位0.1km/h
+	(uint8_t)135                                     //推行模式电机转速设置值
 };
 
 //MC配置参数2,占用32bytes
@@ -176,47 +179,47 @@ const uint8_t Secret_Key_Default[8] = "AVONITOM";
 //ECO档位助力参数
 const nGearParam_Struct_t GearParam_Default_ECO_Volans =
 {
-  (uint16_t)410, //327,
+  (uint16_t)392,
 	(uint16_t)0,
 	(uint16_t)100,
 	(uint16_t)800,
-	(uint8_t)4,
+	(uint8_t)2,
 	(uint8_t)1,
-	(uint16_t)250
+	(uint16_t)512
 };
 
 //NORM档位助力参数
 const nGearParam_Struct_t GearParam_Default_NORM_Volans =
 {
-  (uint16_t)717, //655,
+  (uint16_t)786,
 	(uint16_t)0,
 	(uint16_t)100,
 	(uint16_t)1000,
-	(uint8_t)4,
+	(uint8_t)2,
 	(uint8_t)1,
-	(uint16_t)500
+	(uint16_t)686
 };
 
 //SPORT档位助力参数
 const nGearParam_Struct_t GearParam_Default_SPORT_Volans =
 {
-  (uint16_t)1024,
-	(uint16_t)0,
+  (uint16_t)1309,
+	(uint16_t)700,
 	(uint16_t)100,
-	(uint16_t)1200, //1300,
-	(uint8_t)4,
+	(uint16_t)1300,
+	(uint8_t)3,
 	(uint8_t)1,
-	(uint16_t)750
+	(uint16_t)870
 };
 
 //TURBO档位助力参数
 const nGearParam_Struct_t GearParam_Default_TURBO_Volans =
 {
-  (uint16_t)1536, //1310,
-	(uint16_t)0,
+  (uint16_t)1964,
+	(uint16_t)840,
 	(uint16_t)100,
-	(uint16_t)1400, //1800,
-	(uint8_t)4,
+	(uint16_t)2100,
+	(uint8_t)5,
 	(uint8_t)1,
 	(uint16_t)1024
 };
@@ -224,10 +227,10 @@ const nGearParam_Struct_t GearParam_Default_TURBO_Volans =
 //SMART档位助力参数
 const nGearParam_Struct_t GearParam_Default_SMART_Volans =
 {
-  (uint16_t)1000,
-	(uint16_t)2000,
+  (uint16_t)0,
+	(uint16_t)980,
 	(uint16_t)100,
-	(uint16_t)1400, //1600,
+	(uint16_t)2100,
 	(uint8_t)4,
 	(uint8_t)1,
 	(uint16_t)1024
@@ -237,47 +240,47 @@ const nGearParam_Struct_t GearParam_Default_SMART_Volans =
 //ECO档位助力参数
 const nGearParam_Struct_t GearParam_Default_ECO_Volans_Plus =
 {
-  (uint16_t)410,   //377,
+  (uint16_t)452,
 	(uint16_t)0,
 	(uint16_t)100,
 	(uint16_t)840,
-	(uint8_t)4,
+	(uint8_t)2,
 	(uint8_t)1,
-	(uint16_t)338
+	(uint16_t)512
 };
 
 //NORM档位助力参数
 const nGearParam_Struct_t GearParam_Default_NORM_Volans_Plus =
 {
-  (uint16_t)717,  //795,
+  (uint16_t)954,
 	(uint16_t)0,
 	(uint16_t)100,
 	(uint16_t)1200,
-	(uint8_t)4,
+	(uint8_t)2,
 	(uint8_t)1,
-	(uint16_t)605
+	(uint16_t)686
 };
 
 //SPORT档位助力参数
 const nGearParam_Struct_t GearParam_Default_SPORT_Volans_Plus =
 {
-  (uint16_t)1024,  //1504,
-	(uint16_t)0,
+  (uint16_t)1504,
+	(uint16_t)700,
 	(uint16_t)100,
 	(uint16_t)1590,
-	(uint8_t)4,
+	(uint8_t)3,
 	(uint8_t)1,
-	(uint16_t)850
+	(uint16_t)870
 };
 
 //TURBO档位助力参数
-const nGearParam_Struct_t GearParam_Default_TURBO_Volans_Plus =
+const nGearParam_Struct_t GearParam_Default_TURBO_Volans_Plus = 
 {
-  (uint16_t)1536,   //2354,
-	(uint16_t)0,
+  (uint16_t)2354,
+	(uint16_t)840,
 	(uint16_t)100,
 	(uint16_t)2100,
-	(uint8_t)4,
+	(uint8_t)5,
 	(uint8_t)1,
 	(uint16_t)1024
 };
@@ -285,8 +288,8 @@ const nGearParam_Struct_t GearParam_Default_TURBO_Volans_Plus =
 //SMART档位助力参数
 const nGearParam_Struct_t GearParam_Default_SMART_Volans_Plus =
 {
-  (uint16_t)1000,
-	(uint16_t)2000,
+  (uint16_t)0,
+	(uint16_t)960,
 	(uint16_t)100,
 	(uint16_t)2100,
 	(uint8_t)4,
@@ -298,11 +301,11 @@ const nGearParam_Struct_t GearParam_Default_SMART_Volans_Plus =
 //ECO档位助力参数
 const nGearParam_Struct_t GearParam_Default_ECO_Pegasi =
 {
-  (uint16_t)410,  //381,
+  (uint16_t)476,
+	(uint16_t)560,
 	(uint16_t)0,
-	(uint16_t)100,
 	(uint16_t)937,
-	(uint8_t)4,
+	(uint8_t)2,
 	(uint8_t)1,
 	(uint16_t)338
 };
@@ -310,36 +313,36 @@ const nGearParam_Struct_t GearParam_Default_ECO_Pegasi =
 //NORM档位助力参数
 const nGearParam_Struct_t GearParam_Default_NORM_Pegasi =
 {
-  (uint16_t)717,  //914,
+  (uint16_t)1142,
+	(uint16_t)700,
 	(uint16_t)0,
-	(uint16_t)100,
 	(uint16_t)1250,
-	(uint8_t)4,
-	(uint8_t)1,
+	(uint8_t)3,
+	(uint8_t)2,
 	(uint16_t)489
 };
 
 //SPORT档位助力参数
 const nGearParam_Struct_t GearParam_Default_SPORT_Pegasi =
 {
-  (uint16_t)1024,  //1523,
+  (uint16_t)1903,
+	(uint16_t)840,
 	(uint16_t)0,
-	(uint16_t)100,
 	(uint16_t)1459,
 	(uint8_t)4,
-	(uint8_t)1,
+	(uint8_t)2,
 	(uint16_t)686
 };
 
 //TURBO档位助力参数
 const nGearParam_Struct_t GearParam_Default_TURBO_Pegasi =
 {
-  (uint16_t)1536,  //2286,
+  (uint16_t)2857,
+	(uint16_t)980,
 	(uint16_t)0,
-	(uint16_t)100,
 	(uint16_t)2100,
-	(uint8_t)4,
-	(uint8_t)1,
+	(uint8_t)5,
+	(uint8_t)3,
 	(uint16_t)1024
 };
 
@@ -347,11 +350,11 @@ const nGearParam_Struct_t GearParam_Default_TURBO_Pegasi =
 const nGearParam_Struct_t GearParam_Default_SMART_Pegasi =
 {
   (uint16_t)0,
-	(uint16_t)2000,
-	(uint16_t)100,
+	(uint16_t)1200,
+	(uint16_t)0,
 	(uint16_t)2100,
 	(uint8_t)4,
-	(uint8_t)1,
+	(uint8_t)2,
 	(uint16_t)1024
 };
 
@@ -359,11 +362,11 @@ const nGearParam_Struct_t GearParam_Default_SMART_Pegasi =
 //ECO档位助力参数
 const nGearParam_Struct_t GearParam_Default_ECO_Pegasi_Plus =
 {
-  (uint16_t)419,
-	(uint16_t)0,
+  (uint16_t)523,
+	(uint16_t)560,
 	(uint16_t)100,
 	(uint16_t)871,
-	(uint8_t)4,
+	(uint8_t)1,
 	(uint8_t)1,
 	(uint16_t)235
 };
@@ -371,11 +374,11 @@ const nGearParam_Struct_t GearParam_Default_ECO_Pegasi_Plus =
 //NORM档位助力参数
 const nGearParam_Struct_t GearParam_Default_NORM_Pegasi_Plus =
 {
-  (uint16_t)717,  //959,
-	(uint16_t)0,
+  (uint16_t)1198,
+	(uint16_t)700,
 	(uint16_t)100,
 	(uint16_t)1055,
-	(uint8_t)4,
+	(uint8_t)2,
 	(uint8_t)1,
 	(uint16_t)331
 };
@@ -383,11 +386,11 @@ const nGearParam_Struct_t GearParam_Default_NORM_Pegasi_Plus =
 //SPORT档位助力参数
 const nGearParam_Struct_t GearParam_Default_SPORT_Pegasi_Plus =
 {
-  (uint16_t)1024,  //1370,
-	(uint16_t)0,
+  (uint16_t)1712,
+	(uint16_t)840,
 	(uint16_t)100,
 	(uint16_t)1464,
-	(uint8_t)4,
+	(uint8_t)3,
 	(uint8_t)1,
 	(uint16_t)512
 };
@@ -395,12 +398,12 @@ const nGearParam_Struct_t GearParam_Default_SPORT_Pegasi_Plus =
 //TURBO档位助力参数
 const nGearParam_Struct_t GearParam_Default_TURBO_Pegasi_Plus =
 {
-  (uint16_t)1536,  //2289,
-	(uint16_t)0,
+  (uint16_t)2861,
+	(uint16_t)980,
 	(uint16_t)100,
 	(uint16_t)2100,
-	(uint8_t)4,
-	(uint8_t)1,
+	(uint8_t)5,
+	(uint8_t)2,
 	(uint16_t)1024
 };
 
@@ -408,7 +411,7 @@ const nGearParam_Struct_t GearParam_Default_TURBO_Pegasi_Plus =
 const nGearParam_Struct_t GearParam_Default_SMART_Pegasi_Plus =
 {
   (uint16_t)0,
-	(uint16_t)2000,
+	(uint16_t)1850,
 	(uint16_t)100,
 	(uint16_t)2100,
 	(uint8_t)4,
@@ -484,11 +487,11 @@ void Var_Init(void)
 	memcpy((uint8_t*)&PBU_ConfigParam.GearsNum, (uint8_t*)&PBU_ConfigParam_Default.GearsNum, sizeof(PBU_ConfigParam_Struct_t));
 		
 	//MC版本信息初始化,Mode和SN从EEPROM读取
-  strncpy(MC_VerInfo.HW_Version, (char*)"QD007E.         ", 16);
-	strncpy(MC_VerInfo.FW_Version, (char*)"V5r1r0_20200615.", 16);
+  strncpy(MC_VerInfo.HW_Version, (char*)"QD007G.         ", 16);
+	strncpy(MC_VerInfo.FW_Version, (char*)"V5r2r0_20200917.", 16);
 		
 	//电机型号
-	strncpy(MC_VerInfo.Mode, (char*)"VR7500K01.      ", 16);
+	strncpy(MC_VerInfo.Mode, (char*)"VR7500.      ", 16);
 	
 	//电机序列号
 	strncpy(MC_VerInfo.SN_Num, (char*)"0000000000000000", 16);
@@ -496,7 +499,7 @@ void Var_Init(void)
 	//生产信息
 	strncpy(MC_MacInfo.Manufacturer, (char*)"TTIUM.  ", 8);  //生产信息
 	strncpy(MC_MacInfo.MacAddr, (char*)"WUHAN.  ", 8);
-	strncpy(MC_MacInfo.MacDate, (char*)"20200101", 8);
+	strncpy(MC_MacInfo.MacDate, (char*)"20200901", 8);
 		
 	//MCU ID读取
 	memcpy((uint8_t*)MC_CheckInfo.MAC_ID, (uint8_t*)(0x1FFFF7E8), 12);

+ 74 - 0
修改说明.txt

@@ -277,6 +277,80 @@ V5.1.0_20200615
 12、对ECU的通信超时判断由1s改为30s;
 13、版本号:V5.1.0_20200615
 
+V2.0.4_20200615
+1、采集母线电压时,根据母线电流乘一个线阻(200mOhm);
+2、版本:V2.0.4_20200615
+
+V2.1.0_20200624
+1、增加力矩根据踏频滤波的处理,根据信号变化,取180度的均值;
+2、采用运动版程序,根据踏频滤波的数值作为助力处理函数的输入;
+3、版本号:V2.1.0_20200624
+
+V2.1.1_20200720
+1、开启Flash读保护;
+2、按照Damon的处理方式,将力矩180度均值处理函数模块化;
+3、nGearParam_Struct_t结构体类型定义,成员i_Sport_TH修改为TorqueApp_TH,Smart外用于低力矩衰减的阈值,Smart档作为助力比变化阈值;
+4、按照Pegasi相同的方式调整OC检测;
+5、运行信息中电功率改用根据限流值、按照25分度修改,保证达到限流时仪表显示功率条为满格;、
+6、设定每个档位的低力矩衰减阈值;
+7、版本号:V2.1.1_20200720
+
+V2.1.2_20200812
+1、低力矩衰减函数增加不衰减的处理,将ECO、NORM档位低力矩衰减阈值设为0;
+2、去掉软启动处理;
+3、调整Volans/Volans Plus的助力体验,ECO和NORM的助力比和限流加大,SMART减小阈值;
+4、版本号:V2.1.2_20200812
+
+V2.1.3_20200814
+1、增加推行限速、推行马达转速、低压保护阈值参数设置,及相关的处理,并兼容旧电机;
+2、将全系列型号PID积分限幅设为最大;
+3、相电流零点偏移故障时补充日志和历史记录;
+4、版本号:V2.1.3_20200814
+
+V2.1.3_20200821
+1、打开软启动,修改强劲、正常、柔和的处理;
+2、加速增益的阈值由80和120修改为90和110;
+3、TIM2的ETR接口PA0由GPIO_MODE_AF_PP修改为GPIO_MODE_INPUT;
+4、限速的上限由27km/h调整为27.2km/h;
+5、软件版本:V2r1r3_20200821
+
+V2.1.3_20200821_1
+1、关闭根据TE发送的标志确定是否对TE进行检查,否则如果TE真的出现故障,就会检测不出来。
+2、版本号不变,V2.1.3_20200813。
+
+V2.1.4_20200821
+1、屏蔽GPIOD寄存器微故障检测;
+2、增加5us延时,解决DMA_CNDTR寄存器微故障检测不通过问题;
+3、软件版本:V2r1r4_20200821
+V2.1.4_20200826
+1、修改GPIOD寄存器微故障检测方法,只检测PD0 PD1和PD2相关的寄存器位;
+2、软件版本:V2r1r4_20200826
+3、修改ADC处理函数,增加三角波发生函数;
+V2.1.5_20200903
+1、修改母线电压滤波时间和比例系数;
+2、程序开始运行前两秒不执行续航里程初始化和计算程序,等母线电压采集稳定后再计算续航里程;
+3、修改电池版本号为V2.1.5_20200903;
+
+2.1.5_20200904
+1、优化开机时刻初始续航里程的计算,根据电池通讯状态计算,解决轮子转5圈后续航跳变的问题;
+2、软件版本:V2r1r5_20200904
+
+V5.2.0_20200917
+1、基于V5.1.0_20200615,结合V2.1.5_20200904版本进行改动;
+2、相对于V2.1.5_20200904版本,该版本的差异如下:
+  a) 速度的计算,除了根据传感器和踏频两种方式外,增加了根据通信获取车轮转速的方式及骑行里程的统计,0x55-车轮触发,0x-AA踏频计算,0xEE-通讯获取车轮旋转周期;
+  b) CAN的接收处理中,屏蔽PBU/OBC的指令,打开ECU指令,并增加车轮转速信息的获取;
+  c) 检测PBU/OBC/ECU通信超时的时间由1s改为30s
+  d) 版本号V5.2.0_20200917
+
+
+
+
+
+
+
+
+