|
@@ -19,6 +19,7 @@
|
|
#include "bikethrottle.h"
|
|
#include "bikethrottle.h"
|
|
#include "api.h"
|
|
#include "api.h"
|
|
#include "board_config.h"
|
|
#include "board_config.h"
|
|
|
|
+#include "bikespeed.h"
|
|
/******************************
|
|
/******************************
|
|
*
|
|
*
|
|
* static Parameter
|
|
* static Parameter
|
|
@@ -97,53 +98,61 @@ void bikethrottle_voBikeThrottleInit(void)
|
|
****************************************************************/
|
|
****************************************************************/
|
|
void bikethrottle_voBikeThrottleADC(void) // need to match ADC_StartConversion(ADC1);
|
|
void bikethrottle_voBikeThrottleADC(void) // need to match ADC_StartConversion(ADC1);
|
|
{
|
|
{
|
|
- if (bikethrottle_stBikeThrottleOut.blThrottleErrorFlg == TRUE)
|
|
|
|
|
|
+ if(bikespeed_stSpdLimCoef.blThrottleExist)
|
|
{
|
|
{
|
|
- bikethrottle_stBikeThrottleOut.uwThrottleVolPu = 0;
|
|
|
|
- bikethrottle_stBikeThrottleOut.uwThrottleVolLPFPu = 0;
|
|
|
|
- bikethrottle_stBikeThrottleOut.uwThrottlePercent = 0;
|
|
|
|
- bikethrottle_stBikeThrottleOut.uwThrottleRecoverCnt++;
|
|
|
|
- if (bikethrottle_stBikeThrottleOut.uwThrottleRecoverCnt == bikethrottle_stBikeThrottleCof.uwThrottleRecoverCnt)
|
|
|
|
|
|
+ if (bikethrottle_stBikeThrottleOut.blThrottleErrorFlg == TRUE)
|
|
{
|
|
{
|
|
- bikethrottle_stBikeThrottleOut.blThrottleErrorFlg = FALSE;
|
|
|
|
- bikethrottle_stBikeThrottleOut.uwThrottleRecoverCnt = 0;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- bikethrottle_stBikeThrottleOut.uwThrottleVolReg = iAdc_GetResultPointer(0)[HW_ADC_THRO_CH]; //hw_uwADC2[6];
|
|
|
|
- bikethrottle_stBikeThrottleOut.uwThrottleVolPu =
|
|
|
|
- (UWORD)(((ULONG)bikethrottle_stBikeThrottleOut.uwThrottleVolReg * bikethrottle_stBikeThrottleCof.uwThrottleVolReg2Pu) >> 10); // Q14
|
|
|
|
- mth_voLPFilter((SWORD)bikethrottle_stBikeThrottleOut.uwThrottleVolPu, &scm_stBikeThrottleLpf);
|
|
|
|
- bikethrottle_stBikeThrottleOut.uwThrottleVolLPFPu = scm_stBikeThrottleLpf.slY.sw.hi;
|
|
|
|
-
|
|
|
|
- if (bikethrottle_stBikeThrottleOut.uwThrottleVolPu < bikethrottle_stBikeThrottleCof.uwMinThrottleVolOutputPu)
|
|
|
|
- {
|
|
|
|
- bikethrottle_stBikeThrottleOut.uwThrottleVolLPFPu = bikethrottle_stBikeThrottleCof.uwMinThrottleVolOutputPu;
|
|
|
|
- bikethrottle_stBikeThrottleOut.uwThrottleErrorCnt++;
|
|
|
|
- if (bikethrottle_stBikeThrottleOut.uwThrottleErrorCnt == bikethrottle_stBikeThrottleCof.uwThrottleErrorCnt)
|
|
|
|
|
|
+ bikethrottle_stBikeThrottleOut.uwThrottleVolPu = 0;
|
|
|
|
+ bikethrottle_stBikeThrottleOut.uwThrottleVolLPFPu = 0;
|
|
|
|
+ bikethrottle_stBikeThrottleOut.uwThrottlePercent = 0;
|
|
|
|
+ bikethrottle_stBikeThrottleOut.uwThrottleRecoverCnt++;
|
|
|
|
+ if (bikethrottle_stBikeThrottleOut.uwThrottleRecoverCnt == bikethrottle_stBikeThrottleCof.uwThrottleRecoverCnt)
|
|
{
|
|
{
|
|
- bikethrottle_stBikeThrottleOut.blThrottleErrorFlg = TRUE;
|
|
|
|
- bikethrottle_stBikeThrottleOut.uwThrottleErrorCnt = 0;
|
|
|
|
|
|
+ bikethrottle_stBikeThrottleOut.blThrottleErrorFlg = FALSE;
|
|
|
|
+ bikethrottle_stBikeThrottleOut.uwThrottleRecoverCnt = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else if (bikethrottle_stBikeThrottleOut.uwThrottleVolPu > bikethrottle_stBikeThrottleCof.uwMaxThrottleVolOutputPu)
|
|
|
|
|
|
+ else
|
|
{
|
|
{
|
|
- bikethrottle_stBikeThrottleOut.uwThrottleVolLPFPu = bikethrottle_stBikeThrottleCof.uwMaxThrottleVolOutputPu;
|
|
|
|
- bikethrottle_stBikeThrottleOut.uwThrottleErrorCnt++;
|
|
|
|
- if (bikethrottle_stBikeThrottleOut.uwThrottleErrorCnt == bikethrottle_stBikeThrottleCof.uwThrottleErrorCnt)
|
|
|
|
|
|
+ bikethrottle_stBikeThrottleOut.uwThrottleVolReg = iAdc_GetResultPointer(0)[HW_ADC_THRO_CH]; //hw_uwADC2[6];
|
|
|
|
+ bikethrottle_stBikeThrottleOut.uwThrottleVolPu =
|
|
|
|
+ (UWORD)(((ULONG)bikethrottle_stBikeThrottleOut.uwThrottleVolReg * bikethrottle_stBikeThrottleCof.uwThrottleVolReg2Pu) >> 10); // Q14
|
|
|
|
+ //mth_voLPFilter((SWORD)bikethrottle_stBikeThrottleOut.uwThrottleVolPu, &scm_stBikeThrottleLpf);
|
|
|
|
+ //bikethrottle_stBikeThrottleOut.uwThrottleVolLPFPu = scm_stBikeThrottleLpf.slY.sw.hi;
|
|
|
|
+ bikethrottle_stBikeThrottleOut.uwThrottleVolLPFPu = bikethrottle_stBikeThrottleOut.uwThrottleVolPu;
|
|
|
|
+
|
|
|
|
+ if (bikethrottle_stBikeThrottleOut.uwThrottleVolPu < bikethrottle_stBikeThrottleCof.uwMinThrottleVolOutputPu)
|
|
|
|
+ {
|
|
|
|
+ bikethrottle_stBikeThrottleOut.uwThrottleVolLPFPu = bikethrottle_stBikeThrottleCof.uwMinThrottleVolOutputPu;
|
|
|
|
+ bikethrottle_stBikeThrottleOut.uwThrottleErrorCnt++;
|
|
|
|
+ if (bikethrottle_stBikeThrottleOut.uwThrottleErrorCnt == bikethrottle_stBikeThrottleCof.uwThrottleErrorCnt)
|
|
|
|
+ {
|
|
|
|
+ bikethrottle_stBikeThrottleOut.blThrottleErrorFlg = TRUE;
|
|
|
|
+ bikethrottle_stBikeThrottleOut.uwThrottleErrorCnt = 0;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else if (bikethrottle_stBikeThrottleOut.uwThrottleVolPu > bikethrottle_stBikeThrottleCof.uwMaxThrottleVolOutputPu)
|
|
|
|
+ {
|
|
|
|
+ bikethrottle_stBikeThrottleOut.uwThrottleVolLPFPu = bikethrottle_stBikeThrottleCof.uwMaxThrottleVolOutputPu;
|
|
|
|
+ bikethrottle_stBikeThrottleOut.uwThrottleErrorCnt++;
|
|
|
|
+ if (bikethrottle_stBikeThrottleOut.uwThrottleErrorCnt == bikethrottle_stBikeThrottleCof.uwThrottleErrorCnt)
|
|
|
|
+ {
|
|
|
|
+ bikethrottle_stBikeThrottleOut.blThrottleErrorFlg = TRUE;
|
|
|
|
+ bikethrottle_stBikeThrottleOut.uwThrottleErrorCnt = 0;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
{
|
|
{
|
|
- bikethrottle_stBikeThrottleOut.blThrottleErrorFlg = TRUE;
|
|
|
|
bikethrottle_stBikeThrottleOut.uwThrottleErrorCnt = 0;
|
|
bikethrottle_stBikeThrottleOut.uwThrottleErrorCnt = 0;
|
|
|
|
+ bikethrottle_stBikeThrottleOut.uwThrottlePercent =
|
|
|
|
+ (bikethrottle_stBikeThrottleOut.uwThrottleVolLPFPu - bikethrottle_stBikeThrottleCof.uwThrottleOffsetPu) * 1000 /
|
|
|
|
+ (bikethrottle_stBikeThrottleCof.uwMaxThrottleVolOutputPu - bikethrottle_stBikeThrottleCof.uwMinThrottleVolOutputPu);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else
|
|
|
|
- {
|
|
|
|
- bikethrottle_stBikeThrottleOut.uwThrottleErrorCnt = 0;
|
|
|
|
- bikethrottle_stBikeThrottleOut.uwThrottlePercent =
|
|
|
|
- (bikethrottle_stBikeThrottleOut.uwThrottleVolLPFPu - bikethrottle_stBikeThrottleCof.uwThrottleOffsetPu) * 1000 /
|
|
|
|
- (bikethrottle_stBikeThrottleCof.uwMaxThrottleVolOutputPu - bikethrottle_stBikeThrottleCof.uwMinThrottleVolOutputPu);
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ bikethrottle_stBikeThrottleOut.uwThrottlePercent = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|