/** * @file canAppl.c * @author Zhang, Kai(zhangkai71@midea.com) * @brief * @version 0.1 * @date 2022-03-02 * * @copyright Copyright (c) 2022 * */ #include "canAppl.h" #include "CodePara.h" #include "FuncLayerAPI.h" #include "adc.h" #include "alarm.h" #include "usart.h" #include "can.h" #include "flash_master.h" #include "glbcof.h" #include "spdctrmode.h" #include "string.h" #include "syspar.h" #include "AssistCurve.h" #include "hwsetup.h" #include "spi_master.h" #include "fp.def" #include "CadAssist.h" #include "bikeinformation.h" #include "FSM_1st.h" #include "FSM_2nd.h" /****************************** * * Parameter * ******************************/ typedef _Bool BOOL; MC_RunInfo_Struct_t MC_RunInfo; MC_ErrorCode_Struct_t MC_ErrorCode = CAN_MC_ALARMCODE_DEFAULT; MC_ErrorCode_CNT_RECORD_Struct_t MC_ErrorCntRecord = CAN_MC_ALARMCODE_CNT_RECORD_DEFAULT; MC_VerInfo_Struct_t MC_VerInfo; char Firmware_Special[32]; MC_MacInfo_Struct_t MC_MacInfo; MC_RideLog_Struct_t MC_RideLog; BMS_RunInfo_Struct_t BMS_RunInfo; MC_ControlCode_Struct_t MC_ControlCode; MC_RunInfoToCDL_Struct_t MC_RunInfoToCDL; MC_RS_ASCII_Struct_t MC_RsASSCII; MC_UpperPCInfo_Struct_t MC_UpcInfo; BMS_VoltEstimat_Struct_t BMS_VoltEstimat; CONTORLFUN_STRUCT OBC_ControlFUN; MC_Error_Address_Struct ManageError_Address; OBC_SetCustomPara_Struct_t OBC_SetCustomPara; OBC_ButtonStatus_Struct_t OBC_ButtonStatus = {0,0,0,FALSE}; ULONG ulOBC_ComTimeOutCount = 0; ULONG ulBMS_ComTimeOutCount = 0; uint8_t MC_MotorSPD_rpm_Percent = 0; uint8_t MC_WorkMode; uint8_t MC_BC_COM = 0; LPF_OUT BMS_swCurIdcLpf; BOOL blBMSCommFault = FALSE; static UWORD uwRemainDistanceCal; POWER_STRUCT Powercal; void Power_Cal(void); void Can_voUpdateMC_UpcInfo(void) { MC_UpcInfo.stMotorInfo.uwPolePairs = cp_stMotorPara.swMotrPolePairs; MC_UpcInfo.stMotorInfo.uwRsmOhm = cp_stMotorPara.swRsOhm; MC_UpcInfo.stMotorInfo.uwLduH = cp_stMotorPara.uwLdmH; MC_UpcInfo.stMotorInfo.uwLquH = cp_stMotorPara.uwLqmH; MC_UpcInfo.stMotorInfo.uwFluxmWb = cp_stMotorPara.swFluxWb; MC_UpcInfo.stMotorInfo.uwIdMaxA = cp_stMotorPara.swIdMaxA; MC_UpcInfo.stMotorInfo.uwIdMinA = cp_stMotorPara.swIdMinA; MC_UpcInfo.stMotorInfo.uwRSpdRpm = cp_stMotorPara.swRSpeedRpm; MC_UpcInfo.stMotorInfo.uwRPwrWt = cp_stMotorPara.uwRPwrWt; MC_UpcInfo.stMotorInfo.uwRCurA = cp_stMotorPara.swRIarmsA; MC_UpcInfo.stMotorInfo.uwRVolV = cp_stMotorPara.swRUdcV; MC_UpcInfo.stMotorInfo.uwJD = cp_stMotorPara.swJD; MC_UpcInfo.stMotorInfo.uwTorMaxNm = cp_stMotorPara.swTorMax; MC_UpcInfo.stBikeInfo.uwWheelPerimeter = ass_ParaCong.uwWheelPerimeter; MC_UpcInfo.stBikeInfo.uwMechRationMotor = ass_ParaCong.uwMechRationMotorEEPROM;//(UWORD)(((ULONG)ass_ParaCong.uwMechRationMotor*1000)/1024); MC_UpcInfo.stBikeInfo.uwThrottleMaxSpdKmH = ass_ParaCong.uwThrottleMaxSpdKmH; MC_UpcInfo.stBikeInfo.uwCartSpdKmH = ass_ParaCong.uwCartSpdKmH; MC_UpcInfo.stBikeInfo.uwNmFrontChainring = ass_ParaCong.uwNmFrontChainring; MC_UpcInfo.stBikeInfo.uwNmBackChainring = ass_ParaCong.uwNmBackChainring; MC_UpcInfo.stBikeInfo.uwAssistSelect1 = ass_ParaCong.uwAssistSelect1; MC_UpcInfo.stBikeInfo.uwAssistSelect2 = ass_ParaCong.uwAssistSelect2; MC_UpcInfo.stBikeInfo.uwLightConfig = ass_ParaCong.uwLightConfig; MC_UpcInfo.stBikeInfo.swWheelSizeAdjust = ass_ParaCong.swDeltPerimeter; MC_UpcInfo.stBikeInfo.uwStartMode = ass_ParaCong.uwStartMode; MC_UpcInfo.stBikeInfo.uwAutoPowerOffTime = ass_ParaCong.uwAutoPowerOffTime; MC_UpcInfo.stMContorlInfo.uwSPIPosOffsetOrigin =0;// spi_stResolverOut.swSpiThetaOffsetOrignPu; MC_UpcInfo.stMContorlInfo.uwSPIPosOffsetNow = 0;//spi_stResolverOut.swSpiThetaOffsetPu; MC_UpcInfo.stMContorlInfo.uwIPeakMaxA = cp_stMotorPara.swIpeakMaxA; MC_UpcInfo.stMContorlInfo.uwAlamOCurA = cp_stControlPara.swAlmOverCurrentVal; MC_UpcInfo.stMContorlInfo.uwAlamOVolV = cp_stControlPara.swAlmOverVolVal1; MC_UpcInfo.stMContorlInfo.uwAlamUVolV = cp_stControlPara.swAlmUnderVolVal1; MC_UpcInfo.stMContorlInfo.uwAlamOverSpdRpm = cp_stControlPara.swAlmOverSpdVal; MC_UpcInfo.stMContorlInfo.uwAlamOverHeatCe = cp_stControlPara.swAlmOverHeatCeVal; MC_UpcInfo.stMContorlInfo.uwAlamRecHeatCe = cp_stControlPara.swAlmRecOHeatVal; MC_UpcInfo.stMContorlInfo.uwPwrLimitStartCe = cp_stControlPara.swAlmPwrLimitStartTempVal; MC_UpcInfo.stMContorlInfo.uwAlamMotorOverHeatCe = cp_stControlPara.swAlmMotorOverHeatCeVal; MC_UpcInfo.stMContorlInfo.uwAlamMotorRecHeatCe = cp_stControlPara.swAlmMotorRecOHeatVal; MC_UpcInfo.stMContorlInfo.uwPwrLimitMotorStartCe = cp_stControlPara.swAlmPwrLimitMotorStartTempVal; MC_UpcInfo.stMContorlInfo.uwControlFunEN= cp_stControlPara.uwControlFunEN; MC_UpcInfo.stSensorInfo.uwTorSensorOffsetOrigin = torsensor_stTorSensorCof.uwTorqueOffsetOrign; MC_UpcInfo.stSensorInfo.uwTorSensorOffsetNow1 = torsensor_stTorSensorCof.uwTorqueOffsetNow1; MC_UpcInfo.stSensorInfo.uwTorSensorOffsetNow2 = torsensor_stTorSensorCof.uwTorqueOffsetNow2; MC_UpcInfo.stSensorInfo.uwTorSensorOffsetNow3 = torsensor_stTorSensorCof.uwTorqueOffsetNow3; MC_UpcInfo.stSensorInfo.uwTorSensorOffsetNow4 = torsensor_stTorSensorCof.uwTorqueOffsetNow4; MC_UpcInfo.stSensorInfo.uwBikeTorMaxNm = torsensor_stTorSensorCof.uwMaxSensorTorquePu; MC_UpcInfo.stSensorInfo.uwBikeTor1StepRealNm = torsensor_stTorSensorCof.uwBikeTorStep1RealNm; MC_UpcInfo.stSensorInfo.uwBikeTor1StepADC = torsensor_stTorSensorCof.uwBikeTorStep1ADC; MC_UpcInfo.stSensorInfo.uwBikeTor2StepRealNm = torsensor_stTorSensorCof.uwBikeTorStep2RealNm; MC_UpcInfo.stSensorInfo.uwBikeTor2StepADC = torsensor_stTorSensorCof.uwBikeTorStep2ADC; MC_UpcInfo.stSensorInfo.uwBikeTor3StepRealNm = torsensor_stTorSensorCof.uwBikeTorStep3RealNm; MC_UpcInfo.stSensorInfo.uwBikeTor3StepADC = torsensor_stTorSensorCof.uwBikeTorStep3ADC; MC_UpcInfo.stSensorInfo.uwBikeTor4StepRealNm = torsensor_stTorSensorCof.uwBikeTorStep4RealNm; MC_UpcInfo.stSensorInfo.uwBikeTor4StepADC = torsensor_stTorSensorCof.uwBikeTorStep4ADC; MC_UpcInfo.stSensorInfo.uwTorque_SensorPulseNm = cadence_stFreGetCof.uwTorque_NumbersPulses; MC_UpcInfo.stSensorInfo.uwBikeSpdSensorPulseNm = bikespeed_stFreGetCof.uwNumbersPulses; MC_UpcInfo.stSensorInfo.uwCad_SensorPulseNm= cadence_stFreGetCof.uwCad_NumbersPulses; MC_UpcInfo.stAssistInfo.swStartupGain = ass_ParaSet.uwStartupCoef; MC_UpcInfo.stAssistInfo.swStartcruiseGain = ass_ParaSet.uwStartupCruiseCoef; MC_UpcInfo.stAssistInfo.uwAssistStartNm = ass_ParaSet.uwAssistStartNm; MC_UpcInfo.stAssistInfo.uwAssistStopNm = ass_ParaSet.uwAssistStopNm; MC_UpcInfo.stAssistInfo.uwStartUpGainStep = ass_ParaSet.uwStartUpGainStep; MC_UpcInfo.stAssistInfo.uwStartUpCadNm = ass_ParaSet.uwStartUpCadNm; MC_UpcInfo.stAssistInfo.uwTorLPFCadNm = ass_ParaSet.uwTorLPFCadNm; MC_UpcInfo.stAssistInfo.uwSpeedAssistSpdRpm = ass_ParaSet.uwSpeedAssistSpdRpm; MC_UpcInfo.stAssistInfo.uwSpeedAssistIMaxA = ass_ParaSet.uwSpeedAssistIMaxA; MC_UpcInfo.stAssistInfo.uwAssistLimitBikeSpdStart = ass_ParaSet.uwAssistLimitBikeSpdStart; MC_UpcInfo.stAssistInfo.uwAssistLimitBikeSpdStop = ass_ParaSet.uwAssistLimitBikeSpdStop; MC_UpcInfo.stAssistInfo.uwCadenceAssistWeight = ass_ParaSet.uwCadenceWeight; MC_UpcInfo.stAssistInfo.uwCadAssPidKp = ass_stCadAssSpdCtl.uwPidKp; MC_UpcInfo.stAssistInfo.swCadAssPidLimMax = ass_stCadAssSpdCtl.swPidLimMax; MC_UpcInfo.stAssistInfo.swCadAssPidVolDec = ass_stCadAssSpdCtl.swPidVolDec; MC_UpcInfo.stAssistInfo.swCadAssTargetAssCurAcc = ass_stCadAssParaPro.swTargetAssCurAcc; MC_UpcInfo.stAssistInfo.uwMaxCadRpm = ass_stCadAssCoef.uwMaxCadRpm; MC_UpcInfo.stAssistInfo.reserve2 = ass_stReservePara.uwReserve2; MC_UpcInfo.stAssistInfo.reserve3 = ass_stReservePara.uwReserve3; MC_UpcInfo.stAssistInfo.reserve4 = ass_stReservePara.uwReserve4; MC_UpcInfo.stRideParaInfo.ucAssistRatioGain1 = ass_stCalCoef.ucAssistRatioGain[0]; MC_UpcInfo.stRideParaInfo.ucAssistRatioGain2 = ass_stCalCoef.ucAssistRatioGain[1]; MC_UpcInfo.stRideParaInfo.ucAssistRatioGain3 = ass_stCalCoef.ucAssistRatioGain[2]; MC_UpcInfo.stRideParaInfo.ucAssistRatioGain4 = ass_stCalCoef.ucAssistRatioGain[3]; MC_UpcInfo.stRideParaInfo.ucAssistRatioGain5 = ass_stCalCoef.ucAssistRatioGain[4]; MC_UpcInfo.stRideParaInfo.ucAssistAccelerationGain1 = ass_stCalCoef.ucAssistAccelerationGain[0]; MC_UpcInfo.stRideParaInfo.ucAssistAccelerationGain2 = ass_stCalCoef.ucAssistAccelerationGain[1]; MC_UpcInfo.stRideParaInfo.ucAssistAccelerationGain3 = ass_stCalCoef.ucAssistAccelerationGain[2]; MC_UpcInfo.stRideParaInfo.ucAssistAccelerationGain4 = ass_stCalCoef.ucAssistAccelerationGain[3]; MC_UpcInfo.stRideParaInfo.ucAssistAccelerationGain5 = ass_stCalCoef.ucAssistAccelerationGain[4]; MC_UpcInfo.stRideParaInfo.ucMaxCurrentGain1 = ass_stCalCoef.ucMaxCurrentGain[0]; MC_UpcInfo.stRideParaInfo.ucMaxCurrentGain2 = ass_stCalCoef.ucMaxCurrentGain[1]; MC_UpcInfo.stRideParaInfo.ucMaxCurrentGain3 = ass_stCalCoef.ucMaxCurrentGain[2]; MC_UpcInfo.stRideParaInfo.ucMaxCurrentGain4 = ass_stCalCoef.ucMaxCurrentGain[3]; MC_UpcInfo.stRideParaInfo.ucMaxCurrentGain5 = ass_stCalCoef.ucMaxCurrentGain[4]; MC_UpcInfo.stRideParaInfo.ucMaxTorqueGain1 = ass_stCalCoef.ucMaxTorqueGain[0]; MC_UpcInfo.stRideParaInfo.ucMaxTorqueGain2 = ass_stCalCoef.ucMaxTorqueGain[1]; MC_UpcInfo.stRideParaInfo.ucMaxTorqueGain3 = ass_stCalCoef.ucMaxTorqueGain[2]; MC_UpcInfo.stRideParaInfo.ucMaxTorqueGain4 = ass_stCalCoef.ucMaxTorqueGain[3]; MC_UpcInfo.stRideParaInfo.ucMaxTorqueGain5 = ass_stCalCoef.ucMaxTorqueGain[4]; MC_UpcInfo.stBikeInfo2.uwNoneOBCEnable = ass_ParaCong.uwNoneOBCEnable; MC_UpcInfo.stBikeInfo2.uwRearLightCycle = ass_ParaCong.uwRearLightCycle; MC_UpcInfo.stBikeInfo2.uwRearLightDuty = ass_ParaCong.uwRearLightDuty; MC_UpcInfo.stBikeInfo2.swDeltaBikeSpeedLimit = ass_ParaCong.swDeltaBikeSpeedLimit; MC_UpcInfo.stHistoryInfo.uwOpenTimes = cp_stHistoryPara.uwOpenTimes; MC_UpcInfo.stHistoryInfo.uwUsedTimeH = (UWORD)(cp_stHistoryPara.ulUsedTime >> 16); MC_UpcInfo.stHistoryInfo.uwUsedTimeL = (UWORD)(cp_stHistoryPara.ulUsedTime); MC_UpcInfo.stHistoryInfo.swNTCTempMaxCe = cp_stHistoryPara.swNTCTempMaxCe; MC_UpcInfo.stHistoryInfo.swNTCTempMinCe = cp_stHistoryPara.swNTCTempMinCe; MC_UpcInfo.stHistoryInfo.uwAlamHOcurTimes = cp_stHistoryPara.uwAlamHOcurTimes; MC_UpcInfo.stHistoryInfo.uwAlamSOcurTimes = cp_stHistoryPara.uwAlamSOcurTimes; MC_UpcInfo.stHistoryInfo.uwAlamOHeatTimes = cp_stHistoryPara.uwAlamOHeatTimes; MC_UpcInfo.stHistoryInfo.uwAlamRotorLockTimes = cp_stHistoryPara.uwAlamRotorLockTimes; MC_UpcInfo.stHistoryInfo.uwAlamPhsLossTimes = cp_stHistoryPara.uwAlamPhsLossTimes; MC_UpcInfo.stHistoryInfo.uwAlamOVolTimes = cp_stHistoryPara.uwAlamOVolTimes; MC_UpcInfo.stHistoryInfo.uwAlamUVolTimes = cp_stHistoryPara.uwAlamUVolTimes; MC_UpcInfo.stHistoryInfo.uwAlamComOTimeTimes = cp_stHistoryPara.uwAlamComOTimeTimes; MC_UpcInfo.stHistoryInfo.uwG1AvgPwrConsumption = cp_stHistoryPara.uwG1AvgPwrConsumption; MC_UpcInfo.stHistoryInfo.uwG2AvgPwrConsumption = cp_stHistoryPara.uwG2AvgPwrConsumption; MC_UpcInfo.stHistoryInfo.uwG3AvgPwrConsumption = cp_stHistoryPara.uwG3AvgPwrConsumption; MC_UpcInfo.stHistoryInfo.uwG4AvgPwrConsumption = cp_stHistoryPara.uwG4AvgPwrConsumption; MC_UpcInfo.stHistoryInfo.uwG5AvgPwrConsumption = cp_stHistoryPara.uwG5AvgPwrConsumption; MC_UpcInfo.stHistoryInfo.uwODOTripH = (UWORD)(cp_stHistoryPara.ulODOTrip >> 16); MC_UpcInfo.stHistoryInfo.uwODOTripL = (UWORD)cp_stHistoryPara.ulODOTrip; MC_UpcInfo.stHistoryInfo.uwODOTimeH = (UWORD)(cp_stHistoryPara.ulODOTime >> 16); MC_UpcInfo.stHistoryInfo.uwODOTimeL = (UWORD)cp_stHistoryPara.ulODOTime; MC_UpcInfo.stHistoryInfo.uwTripSumH = (UWORD)(cp_stHistoryPara.ulTripSum >> 16); MC_UpcInfo.stHistoryInfo.uwTripSumL = (UWORD)cp_stHistoryPara.ulTripSum; MC_UpcInfo.stHistoryInfo.uwTripSumTimeH = (UWORD)(cp_stHistoryPara.ulTripSumTime >> 16); MC_UpcInfo.stHistoryInfo.uwTripSumTimeL = (UWORD)cp_stHistoryPara.ulTripSumTime; MC_UpcInfo.stHistoryInfo.uwTorSensorAlamTimes = cp_stHistoryPara.uwTorSensorAlamTimes; MC_UpcInfo.stHistoryInfo.uwCadSensorAlamTimes = cp_stHistoryPara.uwCadSensorAlamTimes; MC_UpcInfo.stHistoryInfo.uwBikeSpdSensorAlamTimes = cp_stHistoryPara.uwBikeSpdSensorAlamTimes; MC_UpcInfo.stHistoryInfo.uwPosSensorAlamTimes = cp_stHistoryPara.uwPosSensorAlamTimes; MC_UpcInfo.stHistoryInfo.uwRealODOTripH = (UWORD)(cp_stHistoryPara.ulRealODOTrip >> 16); MC_UpcInfo.stHistoryInfo.uwRealODOTripL = (UWORD)cp_stHistoryPara.ulRealODOTrip; MC_UpcInfo.stHistoryInfo.uwRealODOTimeH = (UWORD)(cp_stHistoryPara.ulRealODOTime >> 16); MC_UpcInfo.stHistoryInfo.uwRealODOTimeL = (UWORD)cp_stHistoryPara.ulRealODOTime; MC_UpcInfo.stTestParaInfo.uwEEFirstDefaultSetFlg = cp_stFlg.ParaFirstSetFlg; // MC_UpcInfo.stTestParaInfo.uwSPIOffsetFirstSetFlg = cp_stFlg.SpiOffsetFirstSetFlg; MC_UpcInfo.stTestParaInfo.RunModelSelect = cp_stFlg.RunModelSelect; MC_UpcInfo.stTestParaInfo.ThetaGetModelSelect = cp_stFlg.ThetaGetModelSelect; MC_UpcInfo.stTestParaInfo.CurrentSampleModelSelect = cp_stFlg.CurrentSampleModelSelect; MC_UpcInfo.stTestParaInfo.RotateDirectionSelect = cp_stFlg.RotateDirectionSelect; MC_UpcInfo.stTestParaInfo.uwInitPosCurAmp = cp_stControlPara.swAlignCurAp; MC_UpcInfo.stTestParaInfo.uwVFControlVolAmp = cp_stControlPara.swDragVolAp; MC_UpcInfo.stTestParaInfo.uwIFControlCurAmp = cp_stControlPara.swDragCurAp; MC_UpcInfo.stTestParaInfo.uwVFIFTargetFreHz = cp_stControlPara.swDragSpdHz; MC_UpcInfo.stTestParaInfo.uwSpeedLoopAccRate = 500; MC_UpcInfo.stTestParaInfo.uwSpeedLoopDecRate = 100; MC_UpcInfo.stTestParaInfo.uwSpeedLoopBandWidthHz = cp_stControlPara.swAsrPIBandwidth; MC_UpcInfo.stTestParaInfo.uwSpeedLoopCoefM = cp_stControlPara.swAsrPIM; MC_UpcInfo.stTestParaInfo.uwCuerrentLoopBandWidthHz = cp_stControlPara.swAcrPIBandwidth; MC_UpcInfo.stTestParaInfo.uwCurrentLoopCoefM = cp_stControlPara.swAcrRaCoef; MC_UpcInfo.stTestParaInfo.uwFluxObsBandWidthHz = cp_stControlPara.swObsFluxPICrossfreHz; MC_UpcInfo.stTestParaInfo.uwFluxObsCoefM = cp_stControlPara.swObsFluxPIDampratio; MC_UpcInfo.stTestParaInfo.uwThetaObsPLLBandWidthHz = cp_stControlPara.swObsSpdPLLBandWidthHz; MC_UpcInfo.stTestParaInfo.uwThetaObsPLLCoefM = cp_stControlPara.swObsSpdPLLM; MC_UpcInfo.stTestParaInfo.uwJm = cp_stMotorPara.swJD ; MC_UpcInfo.stTestParaInfo.uwPWMMaxDuty = cp_stControlPara.swPWMMaxDuty; MC_UpcInfo.stTestParaInfo.uwPWM7to5Duty = cp_stControlPara.swPWM7to5Duty; MC_UpcInfo.stTestParaInfo.uwPwrLimit = cp_stControlPara.swPwrLimitValWt; MC_UpcInfo.stTestParaInfo.uwPwrLimitError = cp_stControlPara.swPwrLimitErrWt; MC_UpcInfo.stTestParaInfo.uwPwrLimitKp = cp_stControlPara.swPwrLimitKpPu; MC_UpcInfo.stTestParaInfo.uwPwrLimitKi = cp_stControlPara.swPwrLimitKiPu; OBC_SetCustomPara.uwWheelPerimeter = ass_ParaCong.uwWheelPerimeter + ass_ParaCong.swDeltPerimeter; OBC_SetCustomPara.StartUpMod = 1; OBC_SetCustomPara.BikeSpeedLimit = ass_ParaSet.uwAssistLimitBikeSpdStart; OBC_SetCustomPara.DeltDiameter = ass_ParaCong.swDeltPerimeter; OBC_SetCustomPara.AssistMod = ass_ParaSet.uwAsssistSelectNum; OBC_SetCustomPara.AutoPowerOffTime = ass_ParaCong.uwAutoPowerOffTime; OBC_SetCustomPara.scDeltaBikeSpeedLimit = (SBYTE)ass_ParaCong.swDeltaBikeSpeedLimit; } UWORD SizeMCUP; void Can_voInitMC_Run(void) { // flash_voVerRead(); // flash_voErrorRead(); // MC版本信息初始化,Mode和SN从EEPROM读取 strncpy(MC_VerInfo.HW_Version, (char *)"SC20100101V1 ", 16); //长度不超过16 // Software version char chFwVersion[16]="V1r0r0_"; strncat(chFwVersion,COMPLIE_TIME,9); // Commit time COMPLIE_TIME strncpy(MC_VerInfo.FW_Version, (char *)chFwVersion, 16); // Firmware Special Info char chFrimware[32]="NC2025X000-MS0000-V0r0. "; strncat(chFrimware,FINGER_PRINT,8); // Git Version if(cp_stFlg.RunModelSelect == CadAssist) { strncat(chFrimware,"C",1); // Cadance assist end with "C" Torque assist end with "T" } else if(cp_stFlg.RunModelSelect == TorqAssist) { strncat(chFrimware,"T",1); // Torque Assist end with "T", Cadence Assist end with "C" } else { /* 不做处理*/ } strncpy(Firmware_Special, (char *)chFrimware, 32); //电机型号 // memcpy(MC_VerInfo.Mode, Syspara2.flash_stPara.ubMotorVersion, sizeof(Syspara2.flash_stPara.ubMotorVersion)); // memcpy(MC_VerInfo.SN_Num, Syspara2.flash_stPara.ubSN, sizeof(Syspara2.flash_stPara.ubSN)); memcpy(MC_VerInfo.Mode, Productionpara.ubMotorVersion, sizeof(Productionpara.ubMotorVersion)); memcpy(MC_VerInfo.SN_Num, Productionpara.ubSN, sizeof(Productionpara.ubSN)); // MC生产信息 memcpy(MC_MacInfo.Manufacturer, Productionpara.ubProdInfo.Manufacturer, sizeof(Productionpara.ubProdInfo)); //自定义字符串 memcpy(MC_RsASSCII.CustomASCII1, Syspara2.flash_stPara.ubRsASSCII.CustomASCII1, sizeof(MC_RsASSCII.CustomASCII1)); memcpy(MC_RsASSCII.CustomASCII2, Syspara2.flash_stPara.ubRsASSCII.CustomASCII2, sizeof(MC_RsASSCII.CustomASCII2)); memcpy(MC_RsASSCII.CustomASCII3, Syspara2.flash_stPara.ubRsASSCII.CustomASCII3, sizeof(MC_RsASSCII.CustomASCII3)); //控制参数 memcpy(&MC_UpcInfo.stTestParaInfo.uwTestParaSaveFlg, &Syspara2.flash_stPara.stTestParaInfo.uwTestParaSaveFlg, sizeof(MC_UpcInfo.stTestParaInfo)); BMS_VoltEstimat.uwInterResistpu = ((ULONG)1700 << 15) / cof_uwRbOm; //Q15 0.1mOhm BMS internal resistance 150mOhm + 20mOhm mth_voLPFilterCoef(1000000 / 100, EVENT_1MS_HZ, &BMS_swCurIdcLpf.uwKx); //100Hz uwRemainDistanceCal = 0xffff; // init invalid value } void Can_voMC_Run_1ms(void) { static UWORD time_s=0; if (cp_stBikeRunInfoPara.BikeSpeedKmH > 30) { cp_stBikeRunInfoPara.ulRiTime++; cp_stBikeRunInfoPara.ulRiTirpTime++; cp_stBikeRunInfoPara.ulRealODOTime++; } else {} if(++time_s>60000) { cp_stHistoryPara.ulUsedTime++; time_s=0; } // Error Cnt record and Error Display Set MC_ErrorCntRecord.ulAlamCntTimeCnt_1ms ++; UART_RxBuff_Struct_OBC.ul_UartComTimeOutCount++; UART_RxBuff_Struct_BMS.ul_UartComTimeOutCount++; if(MC_ErrorCntRecord.ulAlamCntTimeCnt_1ms == ALAM_DETECT_CNT_IN_1ms && MC_ErrorCode.Code == 0) { MC_ErrorCntRecord.Protect_OverCurrentCnt = 0; MC_ErrorCntRecord.Protect_OverVoltageCnt = 0; MC_ErrorCntRecord.Protect_UnderVoltageCnt = 0; MC_ErrorCntRecord.Protect_LockRotorCnt = 0; MC_ErrorCntRecord.Protect_OverTempCnt = 0; MC_ErrorCntRecord.Fault_PhaseLineCnt = 0; MC_ErrorCntRecord.ulAlamCntTimeCnt_1ms = 0; } else {} //故障日志获取故障状态 if ((alm_blAlmOccrFlg == TRUE) || (alm_blWarnOccrFlg == TRUE)) { // if (alm_blAlmSingleRecordDoneFlg == FALSE)// { if ((alm_unCode.bit.IPMFlt == 1) && (MC_ErrorCode.ERROR_Bit.Protect_OverCurrent == 0)) //硬件过流 { MC_ErrorCntRecord.Protect_OverCurrentCnt++; if (MC_ErrorCntRecord.Protect_OverCurrentCnt == ALAM_DISPLAY_CNT_0LEVEL) // ALAM_DISPLAY_CNT_2LEVEL { if(MC_ErrorCode.ERROR_Bit.Protect_OverCurrent==0) { MC_ErrorCode.ERROR_Bit.Protect_OverCurrent = 1; cp_stHistoryPara.uwAlamHOcurTimes++; /*error log updata*/ ErrorLog_Updata(); que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1); } } } if ((alm_unCode.bit.OvrCur == 1) && (MC_ErrorCode.ERROR_Bit.Protect_OverCurrent == 0))//软件过流 { MC_ErrorCntRecord.Protect_OverCurrentCnt++; if (MC_ErrorCntRecord.Protect_OverCurrentCnt == ALAM_DISPLAY_CNT_0LEVEL) // ALAM_DISPLAY_CNT_2LEVEL { if(MC_ErrorCode.ERROR_Bit.Protect_OverCurrent==0) { MC_ErrorCode.ERROR_Bit.Protect_OverCurrent = 1; cp_stHistoryPara.uwAlamSOcurTimes++; /*error log updata*/ ErrorLog_Updata(); que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1); } } } if ((alm_unCode.bit.OvrVlt == 1) && (MC_ErrorCode.ERROR_Bit.Protect_OverVoltage == 0))//过压 { MC_ErrorCntRecord.Protect_OverVoltageCnt++; if (MC_ErrorCntRecord.Protect_OverVoltageCnt == ALAM_DISPLAY_CNT_0LEVEL) // ALAM_DISPLAY_CNT_2LEVEL { if(MC_ErrorCode.ERROR_Bit.Protect_OverVoltage==0) { MC_ErrorCode.ERROR_Bit.Protect_OverVoltage = 1; cp_stHistoryPara.uwAlamOVolTimes++; /*error log updata*/ ErrorLog_Updata(); que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1); } } } if ((alm_unCode.bit.UndrVlt == 1) && (MC_ErrorCode.ERROR_Bit.Protect_UnderVoltage == 0))//欠压 { MC_ErrorCntRecord.Protect_UnderVoltageCnt++; if (MC_ErrorCntRecord.Protect_UnderVoltageCnt == ALAM_DISPLAY_CNT_0LEVEL) // ALAM_DISPLAY_CNT_2LEVEL { if(MC_ErrorCode.ERROR_Bit.Protect_UnderVoltage==0) { MC_ErrorCode.ERROR_Bit.Protect_UnderVoltage = 1; cp_stHistoryPara.uwAlamUVolTimes++; /*error log updata*/ ErrorLog_Updata(); que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1); } } } if ((alm_unCode.bit.RotorLock == 1) && (MC_ErrorCode.ERROR_Bit.Protect_LockRotor == 0))//堵转 { MC_ErrorCntRecord.Protect_LockRotorCnt++; if (MC_ErrorCntRecord.Protect_LockRotorCnt == ALAM_DISPLAY_CNT_0LEVEL) // ALAM_DISPLAY_CNT_2LEVEL { if(MC_ErrorCode.ERROR_Bit.Protect_LockRotor==0) { MC_ErrorCode.ERROR_Bit.Protect_LockRotor = 1; cp_stHistoryPara.uwAlamRotorLockTimes++; /*error log updata*/ ErrorLog_Updata(); que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1); } } } if ((alm_unCode.bit.IPMOvrHeat == 1) && (MC_ErrorCode.ERROR_Bit.Protect_OverTemp == 0))//PCB过热 { MC_ErrorCntRecord.Protect_OverTempCnt++; if (MC_ErrorCntRecord.Protect_OverTempCnt == ALAM_DISPLAY_CNT_0LEVEL) { if(MC_ErrorCode.ERROR_Bit.Protect_OverTemp==0) { MC_ErrorCode.ERROR_Bit.Protect_OverTemp = 1; cp_stHistoryPara.uwAlamOHeatTimes++; /*error log updata*/ ErrorLog_Updata(); que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1); } } } if ((alm_unCode.bit.PhsLoss == 1) && (MC_ErrorCode.ERROR_Bit.Fault_PhaseLine == 0))//缺相 { MC_ErrorCntRecord.Fault_PhaseLineCnt++; if (MC_ErrorCntRecord.Fault_PhaseLineCnt == ALAM_DISPLAY_CNT_0LEVEL) { if(MC_ErrorCode.ERROR_Bit.Fault_PhaseLine==0) { MC_ErrorCode.ERROR_Bit.Fault_PhaseLine = 1; cp_stHistoryPara.uwAlamPhsLossTimes++; /*error log updata*/ ErrorLog_Updata(); que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1); } } } // if(alm_unCode.bit.CommOvrTm) // { // cp_stHistoryPara.uwAlamComOTimeTimes++; // } // if (alm_unCode.bit.SpiThetaFlt == 1) //位置传感器故障 // { // MC_ErrorCode.ERROR_Bit.Fault_SpiPosSensor = 1; // /*error log updata*/ // ErrorLog_Updata(); // que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1); // } if ((alm_unBikeCode.bit.BikeSpdSen == 1) && (MC_ErrorCode.ERROR_Bit.Fault_BikeSpdSensor == 0)) { MC_ErrorCntRecord.Fault_SpeedSensorCnt++; if (MC_ErrorCntRecord.Fault_SpeedSensorCnt == ALAM_DISPLAY_CNT_0LEVEL) { MC_ErrorCode.ERROR_Bit.Fault_BikeSpdSensor = 1; cp_stHistoryPara.uwBikeSpdSensorAlamTimes++; /*error log updata*/ ErrorLog_Updata(); que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1); } } if ((alm_unBikeCode.bit.CadenceSen == 1) && (MC_ErrorCode.ERROR_Bit.Fault_CadenceSensor == 0)) { MC_ErrorCntRecord.Fault_CadenceSensorCnt++; if (MC_ErrorCntRecord.Fault_CadenceSensorCnt == ALAM_DISPLAY_CNT_0LEVEL) { MC_ErrorCode.ERROR_Bit.Fault_CadenceSensor = 1; cp_stHistoryPara.uwCadSensorAlamTimes++; /*error log updata*/ ErrorLog_Updata(); que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1); } } if ((alm_unBikeCode.bit.PCBNTC == 1) && (MC_ErrorCode.ERROR_Bit.Fault_PCBNTC == 0)) { MC_ErrorCntRecord.Fault_NtcSensorCnt++; if (MC_ErrorCntRecord.Fault_NtcSensorCnt == ALAM_DISPLAY_CNT_0LEVEL) { MC_ErrorCode.ERROR_Bit.Fault_PCBNTC = 1; /*error log updata*/ ErrorLog_Updata(); que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1); } } // if (alm_unBikeCode.bit.Throttle == 1) //油门故障 // { // MC_ErrorCode.ERROR_Bit.Fault_Throttle = 1; // /*error log updata*/ // ErrorLog_Updata(); // que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1); // } if ((alm_unBikeCode.bit.TorqSen == 1) && (MC_ErrorCode.ERROR_Bit.Fault_TorqueSensor == 0)) { MC_ErrorCntRecord.Fault_TorqueSensorCnt++; if (MC_ErrorCntRecord.Fault_TorqueSensorCnt == ALAM_DISPLAY_CNT_0LEVEL) { MC_ErrorCode.ERROR_Bit.Fault_TorqueSensor = 1; cp_stHistoryPara.uwTorSensorAlamTimes++; /*error log updata*/ ErrorLog_Updata(); que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1); } } // 电机霍尔故障 if (alm_unCode.bit.HallLoss == 1) { MC_ErrorCntRecord.Fault_HallSensorCnt++; if (MC_ErrorCntRecord.Fault_HallSensorCnt >= ALAM_DISPLAY_CNT_0LEVEL) { MC_ErrorCntRecord.Fault_HallSensorCnt = ALAM_DISPLAY_CNT_0LEVEL+1; if(MC_ErrorCode.ERROR_Bit.Fault_HallSensor == 0) { cp_stHistoryPara.uwPosSensorAlamTimes++; MC_ErrorCode.ERROR_Bit.Fault_HallSensor = 1; /*error log updata*/ ErrorLog_Updata(); que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1); } } } //电机温度过热 if (alm_unCode.bit.MotorOvrHeat == 1) { MC_ErrorCntRecord.Protect_MotorOverTempCnt++; if (MC_ErrorCntRecord.Protect_MotorOverTempCnt >= ALAM_DISPLAY_CNT_0LEVEL) { MC_ErrorCntRecord.Protect_MotorOverTempCnt = ALAM_DISPLAY_CNT_0LEVEL+1; if(MC_ErrorCode.ERROR_Bit.Protect_MotorOverTemp == 0) { cp_stHistoryPara.uwAlamOHeatTimes++; MC_ErrorCode.ERROR_Bit.Protect_MotorOverTemp = 1; /*error log updata*/ ErrorLog_Updata(); que_ubPushIn(&que_stFlashErrorLog, &que_stErrorLog, 1); } } } alm_blAlmSingleRecordDoneFlg = TRUE; } } // Claear error Display if (MC_ErrorCode.ERROR_Bit.Protect_OverCurrent == 1) { if (alm_unCode.bit.IPMFlt != 1 && alm_unCode.bit.OvrCur != 1) { MC_ErrorCntRecord.Protect_OverCurrentCnt = 0; MC_ErrorCode.ERROR_Bit.Protect_OverCurrent = 0; } } if (MC_ErrorCode.ERROR_Bit.Protect_OverVoltage == 1) { if (alm_unCode.bit.OvrVlt != 1) { MC_ErrorCntRecord.Protect_OverVoltageCnt = 0; MC_ErrorCode.ERROR_Bit.Protect_OverVoltage = 0; } } if (MC_ErrorCode.ERROR_Bit.Protect_UnderVoltage == 1) { if (alm_unCode.bit.UndrVlt != 1) { MC_ErrorCntRecord.Protect_UnderVoltageCnt = 0; MC_ErrorCode.ERROR_Bit.Protect_UnderVoltage = 0; } } if (MC_ErrorCode.ERROR_Bit.Protect_LockRotor == 1) { if (alm_unCode.bit.RotorLock != 1) { MC_ErrorCntRecord.Protect_LockRotorCnt = 0; MC_ErrorCode.ERROR_Bit.Protect_LockRotor = 0; } } if (MC_ErrorCode.ERROR_Bit.Protect_OverTemp == 1) { if (alm_unCode.bit.IPMOvrHeat != 1) { MC_ErrorCntRecord.Protect_OverTempCnt = 0; MC_ErrorCode.ERROR_Bit.Protect_OverTemp = 0; } } if (MC_ErrorCode.ERROR_Bit.Fault_PhaseLine == 1) { if (alm_unCode.bit.PhsLoss != 1) { MC_ErrorCntRecord.Fault_PhaseLineCnt = 0; MC_ErrorCode.ERROR_Bit.Fault_PhaseLine = 0; } } // if (MC_ErrorCode.ERROR_Bit.Fault_SpiPosSensor == 1) // { // if (alm_unCode.bit.SpiThetaFlt != 1) // { // MC_ErrorCntRecord.Fault_SpiPosSensorCnt = 0; // MC_ErrorCode.ERROR_Bit.Fault_SpiPosSensor = 0; // } // } if (MC_ErrorCode.ERROR_Bit.Fault_BikeSpdSensor == 1) { if (alm_unBikeCode.bit.BikeSpdSen != 1) { MC_ErrorCntRecord.Fault_SpeedSensorCnt = 0; MC_ErrorCode.ERROR_Bit.Fault_BikeSpdSensor = 0; } } if (MC_ErrorCode.ERROR_Bit.Fault_CadenceSensor == 1) { if (alm_unBikeCode.bit.CadenceSen != 1) { MC_ErrorCntRecord.Fault_CadenceSensorCnt = 0; MC_ErrorCode.ERROR_Bit.Fault_CadenceSensor = 0; } } if (MC_ErrorCode.ERROR_Bit.Fault_PCBNTC == 1) { if (alm_unBikeCode.bit.PCBNTC != 1) { MC_ErrorCntRecord.Fault_NtcSensorCnt = 0; MC_ErrorCode.ERROR_Bit.Fault_PCBNTC = 0; } } if (MC_ErrorCode.ERROR_Bit.Fault_Throttle == 1) { if (alm_unBikeCode.bit.Throttle != 1) { MC_ErrorCntRecord.Fault_GasSensorCnt = 0; MC_ErrorCode.ERROR_Bit.Fault_Throttle = 0; } } if (MC_ErrorCode.ERROR_Bit.Fault_TorqueSensor == 1) { if (alm_unBikeCode.bit.TorqSen != 1) { MC_ErrorCntRecord.Fault_TorqueSensorCnt = 0; MC_ErrorCode.ERROR_Bit.Fault_TorqueSensor = 0; } } if (MC_ErrorCode.ERROR_Bit.Fault_HallSensor == 1) { if (alm_unCode.bit.HallLoss != 1) { MC_ErrorCntRecord.Fault_HallSensorCnt = 0; MC_ErrorCode.ERROR_Bit.Fault_HallSensor = 0; } } if (MC_ErrorCode.ERROR_Bit.Protect_MotorOverTemp == 1) { if (alm_unCode.bit.MotorOvrHeat != 1) { MC_ErrorCntRecord.Protect_MotorOverTempCnt = 0; MC_ErrorCode.ERROR_Bit.Protect_MotorOverTemp = 0; } } SWORD TempPower; if (FSM2nd_Run_state.state == Exit) { TempPower = 0; } else { TempPower = scm_stMotoPwrInLpf.slY.sw.hi; } BMS_VoltEstimat.swIdcPu = (SWORD)(((SLONG)TempPower << 13) / (SLONG)adc_stUpOut.uwVdcLpfPu); // Q15+Q13-Q14=Q14 Calculated dc current if (BMS_VoltEstimat.swIdcPu < 0) { BMS_VoltEstimat.swIdcPu = 0; } mth_voLPFilter(BMS_VoltEstimat.swIdcPu, &BMS_swCurIdcLpf); BMS_VoltEstimat.uwVdcCompPu = (ULONG)BMS_swCurIdcLpf.slY.sw.hi * BMS_VoltEstimat.uwInterResistpu >> 15; //Q14+Q15-Q15=Q14 } void Can_voMC_Run_5ms(void) { cp_stBikeRunInfoPara.BikeSpeedKmH = (((SQWORD)bikespeed_stFreGetOut.uwLPFFrequencyPu * FBASE * (ass_ParaCong.uwWheelPerimeter + ass_ParaCong.swDeltPerimeter) * 36 >> 20) * 1048 * 10) >>20; // 1048 = Q20(1/1000) 0.1 km/h MC_RunInfo.BusVoltage = ((SLONG)adc_stUpOut.uwVdcPu * cof_uwUbVt >> 14) * 100; MC_RunInfo.MotorSpeed = (SLONG)scm_uwSpdFbkLpfAbsPu * cof_uwVbRpm >> 15; MC_RunInfo.BikeSpeed = cp_stBikeRunInfoPara.BikeSpeedKmH;//cp_stBikeRunInfoPara.BikeSpeedKmH; // MC_RunInfo.MotorSpeed / 10 ; } void Can_voMC_Run_200ms(void) { // UWORD TempPower; // 电池通讯异常采用控制器计算电量 if((cp_ulSystickCnt - ulBMS_ComTimeOutCount) > 3000) { blBMSCommFault = TRUE; // communication abnormal } else { blBMSCommFault = FALSE; // communication normal } Can_MaxMinTempHistory(); Can_GearSt_switch(); SizeMCUP = sizeof(MC_UpcInfo.stAssistInfo); if (MC_BC_COM == 1) { MC_RunInfoToCDL.SysStatus = FSM1st_Sys_state.state; MC_RunInfoToCDL.SubStatus = FSM2nd_Run_state.state; MC_RunInfoToCDL.MotorStatus = curSpeed_state.state; MC_RunInfoToCDL.AssitStatus = Ass_FSM; MC_RunInfoToCDL.Id = scm_swIdRefPu; MC_RunInfoToCDL.Iq = scm_swIqRefPu; MC_RunInfoToCDL.Ud = scm_swUdRefPu; MC_RunInfoToCDL.Uq = scm_swUqRefPu; MC_RunInfoToCDL.InstantTorq = torsensor_stTorSensorOut.uwTorqueReg; MC_RunInfoToCDL.FilteTorq = torsensor_stTorSensorOut.uwTorqueLPFPu; MC_RunInfoToCDL.FreqTorq = maf_torque.AverValue; MC_RunInfoToCDL.RS[0] = scm_swIdFdbLpfPu; MC_RunInfoToCDL.RS[1] = scm_swIqFdbLpfPu; MC_RunInfoToCDL.RS[2] = Assist_torqueper; MC_RunInfoToCDL.RS[3] = bikethrottle_stBikeThrottleOut.uwThrottlePercent; SendData(&UART_TxBuff_Struct_OBC, ID_MC_TO_CDL, MODE_REPORT, 0xBA20, (UBYTE *)&MC_RunInfoToCDL.SysStatus); } MC_RunInfo.BikeSpeed = cp_stBikeRunInfoPara.BikeSpeedKmH; ///>车速 0.1km/h,地址偏移0 if(cp_stFlg.ThetaGetModelSelect == ANG_SWITCHHALL) { MC_RunInfo.MotorSpeed = (SLONG)abs(switchhall_stOut.swLowSpdLpfPu) * cof_uwVbRpm >> 15; ///>输出转速 1rpm,地址偏移2 if(scm_swMotorPwrInLpfWt > 5000) } else { MC_RunInfo.MotorSpeed = (SLONG)abs(scm_stSpdFbkLpf.slY.sw.hi)* cof_uwVbRpm >> 15; } if(scm_swMotorPwrInLpfWt > 5000) { scm_swMotorPwrInLpfWt = 5000; } if(scm_swMotorPwrInLpfWt < 0 ) { scm_swMotorPwrInLpfWt = 0; } if(hw_blPWMOnFlg == FALSE) { scm_swMotorPwrInLpfWt = 0; } else { } Power_Cal(); MC_RunInfo.Power= Powercal.PowerPoit; //MC_RunInfo.Power = scm_swMotorPwrInLpfWt / 10; ///>电功率 1W,地址偏移4 MC_RunInfo.BusVoltage = ((ULONG)adc_stUpOut.uwVdcLpfPu * cof_uwUbVt * 100) >> 14; ///>母线电压 1mV,地址偏移6 // MC_RunInfo.BusVoltage = ((ULONG)(adc_stUpOut.uwVdcLpfPu + BMS_VoltEstimat.uwVdcCompPu) * cof_uwUbVt * 100) >> 14; ///>母线电压 1mV,地址偏移6 // if (scm_stMotoPwrInLpf.slY.sw.hi < 10) // { // TempPower = 0; // } // else // { // TempPower = scm_stMotoPwrInLpf.slY.sw.hi; // } // MC_RunInfo.BusCurrent = (((ULONG)TempPower << 13) / adc_stUpOut.uwVdcLpfPu) * cof_uwIbAp * 100 >> 14; ///>母线电流 1mA,地址偏移8 MC_RunInfo.BusCurrent = ((ULONG)adc_stUpOut.uwIbusAvgLpfPu) * cof_uwIbAp * 10 >> 14; ///14 >母线电流 1mA,地址偏移8 MC_RunInfo.Cadence = (cadence_stFreGetOut.uwLPFFrequencyPu * cof_uwFbHz * 60) >> 20; ///>踏频 1rpm,地址偏移10 MC_RunInfo.Torque = ((ULONG)torsensor_stTorSensorOut.uwTorqueLPFPu * cof_uwTorqNm / 10) >> 14; ///>踩踏力矩 1Nm,地址偏移11 MC_RunInfo.CadenceDir = (MC_CadenceDir_Struct_t)cadence_stFreGetOut.cadence_dir; ///>踩踏方向 0-正,1-反,2-停止,地址偏移12 MC_RunInfo.GearSt = MC_ControlCode.GearSt; ///>助力档位,地址偏移13 MC_RunInfo.LightSwitch = MC_ControlCode.LightSwitch; ///>灯开关 0xF0-关,0xF1-开,地址偏移14 MC_RunInfo.SOC = Can_SOC_Cal(); ///>剩余电量 1%,地址偏移15 if(hw_blPWMOnFlg == FALSE) { MC_RunInfo.BusCurrent=0; } // MC_RunInfo.ODO_Km = MC_RideLog.ODO_Km / 10; ///>总里程 1km,地址偏移18 Can_Trip_Cal(); if (cp_stBikeRunInfoPara.blGearStUpdate) { if(cp_stBikeRunInfoPara.uwBikeGear > 0 &&(cp_stBikeRunInfoPara.uwBikeGear <=5)) { MC_RunInfo.PowerPerKm = *(&cp_stHistoryPara.uwG1AvgPwrConsumption + (cp_stBikeRunInfoPara.uwBikeGear - 1)) / 10; //>平均功耗 0.01Ah/km ,地址偏移20 uwRemainDistanceCal = BMS_RunInfo.RC / MC_RunInfo.PowerPerKm / 10; } else { MC_RunInfo.PowerPerKm = 0; uwRemainDistanceCal = 0xffff; //invalid value } cp_stBikeRunInfoPara.BMSRestChargeLast = BMS_RunInfo.RC; cp_stBikeRunInfoPara.uwPowerPerKm = 0; cp_stBikeRunInfoPara.uwAvePowerPerKm = 0; cp_stBikeRunInfoPara.uwPowerPerKmSum = 0; memset(cp_stBikeRunInfoPara.uwPowerPerKmBuf, 0, sizeof(cp_stBikeRunInfoPara.uwPowerPerKmBuf)); cp_stBikeRunInfoPara.uwAvePowerCNT = 0; cp_stBikeRunInfoPara.uwCruisDis = 0; } if(blBMSCommFault == TRUE) { MC_RunInfo.RemainDistance = 0xeeee; /* no bms info*/ } else { MC_RunInfo.RemainDistance = uwRemainDistanceCal; } MC_RunInfo.T_PCB = adc_stUpOut.PCBTemp + 40; ///>PCB温度 +40℃,地址偏移21 MC_RunInfo.T_Coil = adc_stUpOut.MotorTemp + 40; ///>绕组温度 +40℃,地址偏移22 MC_RunInfo.T_MCU = adc_stUpOut.PCBTemp + 40; ///>MCU温度 +40℃,地址偏移23 MC_RunInfo.Ride_Time = cp_stBikeRunInfoPara.ulRiTime >> 10; ///>开机后骑行时间 1s,地址偏移26 MC_RunInfo.TorqueSensorData1=(UBYTE)torsensor_stTorSensorCof.uwTorqueOffsetNow1; MC_RunInfo.TorqueSensorData2=(UBYTE)torsensor_stTorSensorCof.uwTorqueOffsetNow2; MC_RunInfo.TorqueSensorData3=(UBYTE)torsensor_stTorSensorCof.uwTorqueOffsetNow3; static UBYTE test1 = 0; if (MC_WorkMode == 1) { #if(UART_ID==3) test1++; if(test1>=5) #else test1++; if(test1>=2) #endif { test1=0; SendData(&UART_TxBuff_Struct_OBC, ID_MC_BC, MODE_REPORT, 0x1020, (uint8_t *)&MC_RunInfo.BikeSpeed); } } } void Can_Trip_Cal(void) { if (bikespeed_stFreGetOut.blUpdateTripCntFlg == TRUE) { MC_RunInfo.Ride_Km++; cp_stHistoryPara.ulODOTrip++; // Unit: 0.1km cp_stHistoryPara.ulRealODOTrip++; // Unit: 0.1km cp_stHistoryPara.ulTripSum++; Can_RemainTrip_Cal(); bikespeed_stFreGetOut.blUpdateTripCntFlg = FALSE; } MC_RideLog.ODO_Km = cp_stHistoryPara.ulODOTrip; MC_RideLog.TRIP_Km = cp_stHistoryPara.ulTripSum; MC_RideLog.ODO_Time = cp_stHistoryPara.ulODOTime + (cp_stBikeRunInfoPara.ulRiTime >> 10) / 60; // min MC_RideLog.TRIP_Time = cp_stHistoryPara.ulTripSumTime + (cp_stBikeRunInfoPara.ulRiTirpTime >> 10) / 60; // min } void Can_RemainTrip_Cal(void) { if(blBMSCommFault == FALSE) { UWORD uwCruisCoef; //功耗系数 Q12 cp_stBikeRunInfoPara.uwCruisDis++; // 0.1 km if (cp_stBikeRunInfoPara.uwCruisDis >= 5) // 5 = 0.5km { cp_stBikeRunInfoPara.uwCruisDis = 0; cp_stBikeRunInfoPara.BMSRestChargeNow = BMS_RunInfo.RC; cp_stBikeRunInfoPara.uwPowerPerKm = (cp_stBikeRunInfoPara.BMSRestChargeLast - cp_stBikeRunInfoPara.BMSRestChargeNow) << 1; // BMS_RunInfo.RC (BMSRestChargeLast - BMSRestChargeNow) /0.5 km cp_stBikeRunInfoPara.BMSRestChargeLast = cp_stBikeRunInfoPara.BMSRestChargeNow; cp_stBikeRunInfoPara.uwPowerPerKmSum -= cp_stBikeRunInfoPara.uwPowerPerKmBuf[cp_stBikeRunInfoPara.uwAvePowerCNT]; cp_stBikeRunInfoPara.uwPowerPerKmBuf[cp_stBikeRunInfoPara.uwAvePowerCNT] = cp_stBikeRunInfoPara.uwPowerPerKm; cp_stBikeRunInfoPara.uwPowerPerKmSum += cp_stBikeRunInfoPara.uwPowerPerKmBuf[cp_stBikeRunInfoPara.uwAvePowerCNT]; if (cp_stBikeRunInfoPara.uwPowerPerKmBuf[31] == 0) { cp_stBikeRunInfoPara.uwAvePowerPerKm = cp_stBikeRunInfoPara.uwPowerPerKmSum / (cp_stBikeRunInfoPara.uwAvePowerCNT + 1); } else { cp_stBikeRunInfoPara.uwAvePowerPerKm = cp_stBikeRunInfoPara.uwPowerPerKmSum >> 5; } cp_stBikeRunInfoPara.uwAvePowerCNT++; if (cp_stBikeRunInfoPara.uwAvePowerCNT >= 32) { cp_stBikeRunInfoPara.uwAvePowerCNT = 0; } if(cp_stBikeRunInfoPara.uwAvePowerPerKm > 0) { if (cp_stBikeRunInfoPara.uwBikeGear == 1) { uwCruisCoef = ((ULONG)cp_stBikeRunInfoPara.uwAvePowerPerKm << 12) / cp_stHistoryPara.uwG1AvgPwrConsumption; cp_stHistoryPara.uwG1AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG1AvgPwrConsumption * uwCruisCoef >> 12; cp_stHistoryPara.uwG2AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG2AvgPwrConsumption * uwCruisCoef >> 12; cp_stHistoryPara.uwG3AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG3AvgPwrConsumption * uwCruisCoef >> 12; cp_stHistoryPara.uwG4AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG4AvgPwrConsumption * uwCruisCoef >> 12; cp_stHistoryPara.uwG5AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG5AvgPwrConsumption * uwCruisCoef >> 12; MC_RunInfo.PowerPerKm = cp_stHistoryPara.uwG1AvgPwrConsumption / 10; } else if (cp_stBikeRunInfoPara.uwBikeGear == 2) { uwCruisCoef = ((ULONG)cp_stBikeRunInfoPara.uwAvePowerPerKm << 12) / cp_stHistoryPara.uwG2AvgPwrConsumption; cp_stHistoryPara.uwG1AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG1AvgPwrConsumption * uwCruisCoef >> 12; cp_stHistoryPara.uwG2AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG2AvgPwrConsumption * uwCruisCoef >> 12; cp_stHistoryPara.uwG3AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG3AvgPwrConsumption * uwCruisCoef >> 12; cp_stHistoryPara.uwG4AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG4AvgPwrConsumption * uwCruisCoef >> 12; cp_stHistoryPara.uwG5AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG5AvgPwrConsumption * uwCruisCoef >> 12; MC_RunInfo.PowerPerKm = cp_stHistoryPara.uwG2AvgPwrConsumption / 10; } else if (cp_stBikeRunInfoPara.uwBikeGear == 3) { uwCruisCoef = ((ULONG)cp_stBikeRunInfoPara.uwAvePowerPerKm << 12) / cp_stHistoryPara.uwG3AvgPwrConsumption; cp_stHistoryPara.uwG1AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG1AvgPwrConsumption * uwCruisCoef >> 12; cp_stHistoryPara.uwG2AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG2AvgPwrConsumption * uwCruisCoef >> 12; cp_stHistoryPara.uwG3AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG3AvgPwrConsumption * uwCruisCoef >> 12; cp_stHistoryPara.uwG4AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG4AvgPwrConsumption * uwCruisCoef >> 12; cp_stHistoryPara.uwG5AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG5AvgPwrConsumption * uwCruisCoef >> 12; MC_RunInfo.PowerPerKm = cp_stHistoryPara.uwG3AvgPwrConsumption / 10; } else if (cp_stBikeRunInfoPara.uwBikeGear == 4) { uwCruisCoef = ((ULONG)cp_stBikeRunInfoPara.uwAvePowerPerKm << 12) / cp_stHistoryPara.uwG4AvgPwrConsumption; cp_stHistoryPara.uwG1AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG1AvgPwrConsumption * uwCruisCoef >> 12; cp_stHistoryPara.uwG2AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG2AvgPwrConsumption * uwCruisCoef >> 12; cp_stHistoryPara.uwG3AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG3AvgPwrConsumption * uwCruisCoef >> 12; cp_stHistoryPara.uwG4AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG4AvgPwrConsumption * uwCruisCoef >> 12; cp_stHistoryPara.uwG5AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG5AvgPwrConsumption * uwCruisCoef >> 12; MC_RunInfo.PowerPerKm = cp_stHistoryPara.uwG4AvgPwrConsumption / 10; } else if (cp_stBikeRunInfoPara.uwBikeGear == 5) { uwCruisCoef = ((ULONG)cp_stBikeRunInfoPara.uwAvePowerPerKm << 12) / cp_stHistoryPara.uwG5AvgPwrConsumption; cp_stHistoryPara.uwG1AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG1AvgPwrConsumption * uwCruisCoef >> 12; cp_stHistoryPara.uwG2AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG2AvgPwrConsumption * uwCruisCoef >> 12; cp_stHistoryPara.uwG3AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG3AvgPwrConsumption * uwCruisCoef >> 12; cp_stHistoryPara.uwG4AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG4AvgPwrConsumption * uwCruisCoef >> 12; cp_stHistoryPara.uwG5AvgPwrConsumption = (ULONG)cp_stHistoryPara.uwG5AvgPwrConsumption * uwCruisCoef >> 12; MC_RunInfo.PowerPerKm = cp_stHistoryPara.uwG5AvgPwrConsumption / 10; } else { uwCruisCoef = 4096; } uwRemainDistanceCal = BMS_RunInfo.RC / MC_RunInfo.PowerPerKm / 10; } } } } //#if (IPM_VOLTAGE_SEL == IPM_VOLTAGE_48V) // SLONG slBMSMaxVol = 54000; // SLONG slBMSMinVol = 40500; //#elif (IPM_VOLTAGE_SEL == IPM_VOLTAGE_36V) // SLONG slBMSMaxVol = 41500; // SLONG slBMSMinVol = 31000; //#else // SLONG slBMSMaxVol = 41500; // SLONG slBMSMinVol = 31000; //#endif SLONG slBMSMaxVol ; SLONG slBMSMinVol ; SWORD SOC_Cnt, SOC_Value; SWORD SOC_MIN=50; SLONG Voltage_Sum; static BOOL blSOCfirstSet = FALSE; UWORD Can_SOC_Cal(void) { UWORD templenght, VoltageAvg = 0; // 开机1s等待电压稳定后初始化电量 if (cp_ulSystickCnt < 500) { return (UWORD)0; } //---------------------------------电压等级计算电量范围 if(cp_stMotorPara.swRUdcV==480) { slBMSMaxVol = 54000; slBMSMinVol = 40500; } else if(cp_stMotorPara.swRUdcV==360) { slBMSMaxVol = 41500; slBMSMinVol = 31000; } else { slBMSMaxVol = 41500; slBMSMinVol = 31000; } //------------------- if(blBMSCommFault == FALSE) { SOC_Value = BMS_RunInfo.SOC; if((blSOCfirstSet == FALSE) && ( ulBMS_ComTimeOutCount !=0) )// 开机初始化一次电量 { SOC_MIN = BMS_RunInfo.SOC; blSOCfirstSet = TRUE; } } else if(blSOCfirstSet == FALSE)// 开机初始化一次电量 { if(0 == ulBMS_ComTimeOutCount) { if (MC_RunInfo.BusVoltage >= slBMSMaxVol) { SOC_Value = 100; } else if (MC_RunInfo.BusVoltage <= slBMSMinVol) { SOC_Value = 0; } else { SOC_Value = (SWORD)(((SLONG)MC_RunInfo.BusVoltage - slBMSMinVol) * 100 / (slBMSMaxVol - slBMSMinVol)); } SOC_MIN = SOC_Value; } else { SOC_MIN = BMS_RunInfo.SOC; } blSOCfirstSet = TRUE; } // 1min更新一次电量 else { templenght = 300; // 60s in 200ms time task SOC_Cnt++; Voltage_Sum += MC_RunInfo.BusVoltage; if (SOC_Cnt >= templenght) // 60s { VoltageAvg = (UWORD)(Voltage_Sum / templenght); if (VoltageAvg <= slBMSMinVol) { SOC_Value = 0; } else { SOC_Value = (SWORD)(((SLONG)VoltageAvg - (SLONG)slBMSMinVol) * 100 / ((SLONG)slBMSMaxVol - (SLONG)slBMSMinVol)); } if (SOC_Value < SOC_MIN) { SOC_MIN = SOC_Value; } else { } SOC_Cnt = 0; Voltage_Sum = 0; } // 电量仅递减 if (SOC_Value > SOC_MIN) { SOC_Value = SOC_MIN; } else if (SOC_Value < 0) { SOC_Value = 0; } else { // do noting } } return (UWORD)SOC_Value; } void Can_MaxMinTempHistory(void) { if (adc_stUpOut.PCBTemp > ((SWORD)cp_stHistoryPara.swNTCTempMaxCe)) { cp_stHistoryPara.swNTCTempMaxCe = adc_stUpOut.PCBTemp; } else {} if (adc_stUpOut.PCBTemp < ((SWORD)cp_stHistoryPara.swNTCTempMinCe)) { cp_stHistoryPara.swNTCTempMinCe = adc_stUpOut.PCBTemp; } else {} } void Can_GearSt_switch(void) { cp_stBikeRunInfoPara.uwBikeGearLast = cp_stBikeRunInfoPara.uwBikeGear; if (MC_WorkMode == 1) // 配置模式不自动关闭助力 { ulOBC_ComTimeOutCount = cp_ulSystickCnt; } if ((cp_ulSystickCnt - ulOBC_ComTimeOutCount) < 3000) // 控制器与仪表通信中断超过3s,关闭助力 { if (MC_ControlCode.GearSt <= 0x05) { cp_stBikeRunInfoPara.uwBikeGear = MC_ControlCode.GearSt; } else if (MC_ControlCode.GearSt == 0x33) { cp_stBikeRunInfoPara.uwBikeGear = 5; } else if(MC_ControlCode.GearSt == 0x22) { cp_stBikeRunInfoPara.uwBikeGear = 0x22; } else { cp_stBikeRunInfoPara.uwBikeGear = 0; } } #if(BIKE_OXFORD_EN==0) else { MC_ControlCode.GearSt = MC_GearSt_OFF; MC_RunInfo.GearSt = 0x00; cp_stBikeRunInfoPara.uwBikeGear = 0x00; } #endif if (cp_stBikeRunInfoPara.uwBikeGear != cp_stBikeRunInfoPara.uwBikeGearLast) { cp_stBikeRunInfoPara.blGearStUpdate = TRUE; } else { cp_stBikeRunInfoPara.blGearStUpdate = FALSE; } } void Can_Light_switch(void) { /* light switch*/ if (MC_ControlCode.LightSwitch == 0xF0) { cp_stBikeRunInfoPara.uwLightSwitch = 0; } else if (MC_ControlCode.LightSwitch == 0xF1) { cp_stBikeRunInfoPara.uwLightSwitch = 1; } } void Can_AssistCoef_Read(UPC_CurveOrderInfo_Struct_t *order) { MC_UpcInfo.stAssistInfo.stCurveOrderInfo = *order; memcpy(&MC_UpcInfo.stAssistInfo.slTorquePolyA, &Syspara2.flash_stPara.slTorqAssGain[order->uwTorqueCurveNum - 1], sizeof(POLY_COEF)); memcpy(&MC_UpcInfo.stAssistInfo.slCadencePolyA, &Syspara2.flash_stPara.slCadAssGain[order->uwCadenceCurveNum - 1], sizeof(POLY_COEF)); } void Can_AssistCoef_Write(UPC_CurveOrderInfo_Struct_t *order) { memcpy(&Syspara2.flash_stPara.slTorqAssGain[order->uwTorqueCurveNum - 1], &MC_UpcInfo.stAssistInfo.slTorquePolyA, sizeof(POLY_COEF)); memcpy(&Syspara2.flash_stPara.slCadAssGain[order->uwCadenceCurveNum - 1], &MC_UpcInfo.stAssistInfo.slCadencePolyA, sizeof(POLY_COEF)); } void ErrorLog_Updata(void) { que_stErrorLog.ErrorCode = MC_ErrorCode.Code; que_stErrorLog.RunTime = cp_stHistoryPara.ulUsedTime;//MC_RunInfo.Ride_Time; que_stErrorLog.RunInfo = MC_RunInfo; //memcpy((uint8_t*)&que_stErrorLog.RunInfo, (uint8_t*)&MC_RunInfo.BikeSpeed, sizeof(MC_RunInfo_Struct_t)); que_stErrorLog.IqCurrentPu = scm_swIqFdbLpfPu; que_stErrorLog.IqVoltagePu = scm_swUqRefPu; que_stErrorLog.IdCurrentPu = scm_swIdFdbLpfPu; que_stErrorLog.IdVoltagePu = scm_swUdRefPu; } void Power_Cal(void) { SWORD V_temp; UWORD Poit_temp; UWORD Power_temp; SLONG Power_clac; Poit_temp= (cp_stMotorPara.uwRPwrWt)>>11; Power_temp=cp_stMotorPara.uwRPwrWt & 0x07ff; if(cp_stControlPara.swPwrLimitValWt>700) { Powercal.swMaxpower=cp_stControlPara.swPwrLimitValWt-600; } V_temp=MC_RunInfo.BusVoltage/100; Powercal.swPowerFdb=(SWORD) ((SLONG)(V_temp) * (SLONG)MC_RunInfo.BusCurrent/1000); if(Poit_temp==0) { Powercal.PowerPoit=(SWORD)((SLONG)Powercal.swPowerFdb*250/((SLONG)Powercal.swMaxpower)); if(Powercal.PowerPoit > 250) { Powercal.PowerPoit = 250; } else if(Powercal.PowerPoit < 0 ) { Powercal.PowerPoit = 0; } } else { Power_clac=(SLONG)Powercal.swPowerFdb*(Poit_temp+1) ; Powercal.PowerPoit=(SWORD)((Power_clac/10) >>5); } if(hw_blPWMOnFlg == FALSE) { Powercal.PowerPoit = 0; } }