Commit 2e05216e authored by 时昊's avatar 时昊

Merge branch 'shihao' into 'dev'

Shihao

See merge request !33
parents a6b11402 68146ff4
...@@ -7,6 +7,16 @@ ...@@ -7,6 +7,16 @@
#define BACK_LIGHT_Val_4 700 #define BACK_LIGHT_Val_4 700
#define BACK_LIGHT_Val_5 900 #define BACK_LIGHT_Val_5 900
#define LIGHT_DATA_TIME 10u /*这里填写多长时间采集一个数据,单位ms*/
#define LIGHT_DATA_NUM 20u /*燃油电阻采集数据总数 最大255*/
#define LIGHT_CAL_START 5u /*数据排序后取中间部分计算平均:起始*/
#define LIGHT_CAL_END 15u /*数据排序后取中间部分计算平均:结束*/
Light_uint8_t LightADCompleteFlg = 0u;
Light_uint16_t LightR = 0u;
Light_uint16_t LightR_Status = 0;
Light_uint16_t LightR_Status_Count = 0u;
Light_uint16_t NtcDataCount;
Light_uint16_t NtcData[LIGHT_DATA_NUM];
typedef struct typedef struct
{ {
Light_uint16_t Temperature; /* 温度 */ Light_uint16_t Temperature; /* 温度 */
...@@ -47,6 +57,96 @@ _st_BacklightLevel BacklightLevelTable[BacklightLevel_Max] = ...@@ -47,6 +57,96 @@ _st_BacklightLevel BacklightLevelTable[BacklightLevel_Max] =
}; };
void Data_Light_Res_service(Light_uint8_t deltaTime)//获取光感阻值,并做平均
{
uint16_t LightRes = 0;
uint8_t i, j;
uint32_t temp32;
static uint16_t timeCount = 0;
if (timeCount >= LIGHT_DATA_TIME)
{
timeCount = 0;
if (NtcDataCount < LIGHT_DATA_NUM)
{
/*获取光敏电阻*/
LightRes = ADC_Read_Signal(ADC_CH_LIGHT_SENSITIVE); // ADC_Read_Signal(ADC_CH_FUEL1);
/*四舍五入*/
if (LightRes < 32000)
{
if (LightRes % 10 >= 5)
{
LightRes += 5;
}
}
else
{
LightRes = 32000;
}
/*由小到大插入数据*/
for (i = 0; i < NtcDataCount; i++)
{
if (LightRes < NtcData[i])
{
break;
}
}
for (j = NtcDataCount; j > i; j--)
{
NtcData[j] = NtcData[j - 1];
}
NtcData[i] = LightRes;
NtcDataCount++;
}
else
{
/*一组数据采集完毕,取中间部分计算平均值*/
temp32 = 0;
for (i = LIGHT_CAL_START; i < LIGHT_CAL_END; i++)
{
temp32 += NtcData[i];
}
LightR = (uint16_t) (temp32 / (LIGHT_CAL_END - LIGHT_CAL_START));
NtcDataCount = 0;
LightADCompleteFlg = 1;
}
}
timeCount += deltaTime;
if(LightADCompleteFlg)
{
if(LightR_Status == 0)
{
if(LightR >20)
{
LightR_Status_Count++;
}
else
{
LightR_Status_Count = 0 ;
}
}
else
{
if(LightR <20)
{
LightR_Status_Count++;
}
else
{
LightR_Status_Count = 0 ;
}
}
if(LightR_Status_Count>=150)
{
LightR_Status_Count = 0;
LightR_Status = !LightR_Status;
}
}
}
Light_uint16_t GetBacklightDutyByLevel(Light_uint16_t level) Light_uint16_t GetBacklightDutyByLevel(Light_uint16_t level)
...@@ -409,6 +509,6 @@ void BackLight_Process(void) ...@@ -409,6 +509,6 @@ void BackLight_Process(void)
} }
else else
{ {
; TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, BACK_LIGHT_Val_4);
} }
} }
...@@ -20,7 +20,7 @@ void Gpio_Init(_GpioUser_Enum InitMode) ...@@ -20,7 +20,7 @@ void Gpio_Init(_GpioUser_Enum InitMode)
RTE_GPIO_Config(RTE_GPIO_PORT00_PIN05, GpioOut_Low); //L_BiasBitSW 里程百位--- RTE_GPIO_Config(RTE_GPIO_PORT00_PIN05, GpioOut_Low); //L_BiasBitSW 里程百位---
RTE_GPIO_Config(RTE_GPIO_PORT00_PIN06, GpioOut_Low); //L_BiasBitSW 里程千位--- RTE_GPIO_Config(RTE_GPIO_PORT00_PIN06, GpioOut_Low); //L_BiasBitSW 里程千位---
RTE_GPIO_Config(RTE_GPIO_PORT01_PIN00, RTE_GPIO_DIR_OUT); //表盘背光-PWM RTE_GPIO_Config(RTE_GPIO_PORT01_PIN00, GpioOut_Low); //表盘背光-PWM
RTE_GPIO_Config(RTE_GPIO_PORT01_PIN01, GpioOut_Low); //RXD-ESP-IN-MCU RTE_GPIO_Config(RTE_GPIO_PORT01_PIN01, GpioOut_Low); //RXD-ESP-IN-MCU
RTE_GPIO_Config(RTE_GPIO_PORT01_PIN02, GpioOut_Low); //TXD-ESP-IN-MCU RTE_GPIO_Config(RTE_GPIO_PORT01_PIN02, GpioOut_Low); //TXD-ESP-IN-MCU
RTE_GPIO_Config(RTE_GPIO_PORT01_PIN03, RTE_GPIO_DIR_IN); RTE_GPIO_Config(RTE_GPIO_PORT01_PIN03, RTE_GPIO_DIR_IN);
......
...@@ -3402,6 +3402,7 @@ static void AMT630H_GUI_Trip(uint32_t Trip, uint8_t Uint) ...@@ -3402,6 +3402,7 @@ static void AMT630H_GUI_Trip(uint32_t Trip, uint8_t Uint)
SetPagePic(GRAPHICS_PAGE_0, Pic_0861_91_324);/*单位mile*/ SetPagePic(GRAPHICS_PAGE_0, Pic_0861_91_324);/*单位mile*/
} }
} }
DisplayNum(GRAPHICS_PAGE_0, &DisplayNumPara, Tripnumber);
} }
else if(g_u8Display_Mode == ModeNIGHT) else if(g_u8Display_Mode == ModeNIGHT)
{ {
...@@ -3457,6 +3458,7 @@ static void AMT630H_GUI_Trip(uint32_t Trip, uint8_t Uint) ...@@ -3457,6 +3458,7 @@ static void AMT630H_GUI_Trip(uint32_t Trip, uint8_t Uint)
SetPagePic(GRAPHICS_PAGE_0, Pic_0863_91_324);/*单位mile*/ SetPagePic(GRAPHICS_PAGE_0, Pic_0863_91_324);/*单位mile*/
} }
} }
DisplayNum(GRAPHICS_PAGE_0, &DisplayNumPara, Tripnumber);
} }
} }
......
...@@ -74,7 +74,7 @@ ADC_Data_st_t stADCData[ADC_SIGNAL_CH_NUMBER]; ...@@ -74,7 +74,7 @@ ADC_Data_st_t stADCData[ADC_SIGNAL_CH_NUMBER];
const uint8_t __attribute__((aligned(4))) u8ADCChList[ADC_CONV_CH_NUMBER] = const uint8_t __attribute__((aligned(4))) u8ADCChList[ADC_CONV_CH_NUMBER] =
{ {
2U, 3U, 7U, 5U, 6U, 2U, 3U, 7U, 5U, 6U, 4U, 12U,
}; };
const __attribute__((aligned(4))) ADC_Ch_Cfg_st_t stADCChCfg[ADC_SIGNAL_CH_NUMBER] = const __attribute__((aligned(4))) ADC_Ch_Cfg_st_t stADCChCfg[ADC_SIGNAL_CH_NUMBER] =
...@@ -84,6 +84,9 @@ const __attribute__((aligned(4))) ADC_Ch_Cfg_st_t stADCChCfg[ADC_SIGNAL_CH_NUMBE ...@@ -84,6 +84,9 @@ const __attribute__((aligned(4))) ADC_Ch_Cfg_st_t stADCChCfg[ADC_SIGNAL_CH_NUMBE
{ 2U, 0U, 0U, 0U, 0U, 1U, ADC_Voltage_Calc_Circuit101,}, { 2U, 0U, 0U, 0U, 0U, 1U, ADC_Voltage_Calc_Circuit101,},
{ 3U, 2U, 0U, 2U, 0U, 1U, ADC_Res_Calc_Circuit101,}, { 3U, 2U, 0U, 2U, 0U, 1U, ADC_Res_Calc_Circuit101,},
{ 4U, 2U, 0U, 2U, 0U, 1U, ADC_Res_Calc_Circuit101,}, { 4U, 2U, 0U, 2U, 0U, 1U, ADC_Res_Calc_Circuit101,},
{ 5U, 3U, 0U, 5000U, 0U, 10U, ADC_Res_Calc_Circuit201,},
{ 6U, 2U, 0U, 2U, 0U, 1U, ADC_Res_Calc_Circuit101,},
}; };
const __attribute__((aligned(4))) ADC_Res_List_st_t stADCResList[ADC_SIGNAL_CH_NUMBER] = const __attribute__((aligned(4))) ADC_Res_List_st_t stADCResList[ADC_SIGNAL_CH_NUMBER] =
...@@ -93,6 +96,8 @@ const __attribute__((aligned(4))) ADC_Res_List_st_t stADCResList[ADC_SIGNAL_CH_N ...@@ -93,6 +96,8 @@ const __attribute__((aligned(4))) ADC_Res_List_st_t stADCResList[ADC_SIGNAL_CH_N
{ 0U, 0U, 0U, 0U,}, { 0U, 0U, 0U, 0U,},
{ 0U, 0U, 500U, 300U,}, { 0U, 0U, 500U, 300U,},
{ 0U, 0U, 500U, 0U,}, { 0U, 0U, 500U, 0U,},
{ 47000U, 0U, 100000U, 0U,},
{ 0U, 0U, 500U, 0U,},
}; };
/* Private function prototypes ----------------------------------------------*/ /* Private function prototypes ----------------------------------------------*/
......
...@@ -33,11 +33,13 @@ enum ADCChName ...@@ -33,11 +33,13 @@ enum ADCChName
ADC_CH_FUEL_VREF, ADC_CH_FUEL_VREF,
ADC_CH_FUEL1, ADC_CH_FUEL1,
ADC_CH_COOLANT_TEMP1_R, ADC_CH_COOLANT_TEMP1_R,
ADC_CH_NTC_TEMP,
ADC_CH_LIGHT_SENSITIVE,
}; };
/* Exported macro ------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/
#define ADC_TOTAL_CH_NUMBER (5U) #define ADC_TOTAL_CH_NUMBER (7U)
#define ADC_SIGNAL_CH_NUMBER (5U) #define ADC_SIGNAL_CH_NUMBER (7U)
#define ADC_REF_VOLTAGE u16ADCRefVoltage #define ADC_REF_VOLTAGE u16ADCRefVoltage
/* Exported variables --------------------------------------------------------*/ /* Exported variables --------------------------------------------------------*/
......
...@@ -75,7 +75,7 @@ void Data_User_Mileage_KL30Init(void) ...@@ -75,7 +75,7 @@ void Data_User_Mileage_KL30Init(void)
{ {
ODOInit.Offset = TempBuf[2]; ODOInit.Offset = TempBuf[2];
} }
ODOInit.MaxValue = 16103058; ODOInit.MaxValue = 9999999;
Data_ODO_KL30_Init(DataODOBuf, &ODOInit, Func.EEPromWrite_Cbk); Data_ODO_KL30_Init(DataODOBuf, &ODOInit, Func.EEPromWrite_Cbk);
(void)Data_User_EEPROM_Read(EM_TRIP_BLOCK, TempBuf + 3, 8); (void)Data_User_EEPROM_Read(EM_TRIP_BLOCK, TempBuf + 3, 8);
...@@ -194,18 +194,18 @@ void Services_Mileage_Callback(void) ...@@ -194,18 +194,18 @@ void Services_Mileage_Callback(void)
uint32_t Get_ODO_Value(void) uint32_t Get_ODO_Value(void)
{ {
uint32_t ODO = 0; uint32_t ODO = 0;
// if (Get_Dis_Unit() == 0) /* 公制 */ if (Get_Dis_Unit() == 0) /* 公制 */
// { {
// ODO = Data_ODO_Read(); ODO = Data_ODO_Read();
// } }
// else if (Get_Dis_Unit() == 1) /* 英制 */ else if (Get_Dis_Unit() == 1) /* 英制 */
// { {
// ODO = Data_Km_To_Mile(Data_ODO_Read()); ODO = Data_Km_To_Mile(Data_ODO_Read());
// } }
// else /* 无效值,按照公里处理,理论上不会执行到这 */ else /* 无效值,按照公里处理,理论上不会执行到这 */
// { {
// ODO = Data_ODO_Read(); ODO = Data_ODO_Read();
// } }
return ODO; return ODO;
} }
...@@ -216,18 +216,18 @@ uint32_t Get_ODO_Value(void) ...@@ -216,18 +216,18 @@ uint32_t Get_ODO_Value(void)
uint32_t Get_Trip_Value(void) uint32_t Get_Trip_Value(void)
{ {
uint32_t Trip = 0; uint32_t Trip = 0;
// if (Get_Dis_Unit() == 0) /* 公制 */ if (Get_Dis_Unit() == 0) /* 公制 */
// { {
// Trip = Data_Read_Trip(EM_TRIP_A); Trip = Data_Read_Trip(EM_TRIP_A);
// } }
// else if (Get_Dis_Unit() == 1) /* 英制 */ else if (Get_Dis_Unit() == 1) /* 英制 */
// { {
// Trip = Data_Km_To_Mile(Data_Read_Trip(EM_TRIP_A)); Trip = Data_Km_To_Mile(Data_Read_Trip(EM_TRIP_A));
// } }
// else /* 无效值,按照公里处理,理论上不会执行到这 */ else /* 无效值,按照公里处理,理论上不会执行到这 */
// { {
// Trip = Data_Read_Trip(EM_TRIP_A); Trip = Data_Read_Trip(EM_TRIP_A);
// } }
return Trip; return Trip;
} }
...@@ -237,13 +237,13 @@ uint32_t Get_Trip_Value(void) ...@@ -237,13 +237,13 @@ uint32_t Get_Trip_Value(void)
*/ */
void Trip_Clear_Km_Service(void) void Trip_Clear_Km_Service(void)
{ {
// if (Get_Dis_Unit() == 0) /* 公制 */ if (Get_Dis_Unit() == 0) /* 公制 */
// { {
// if (Data_Read_Trip(EM_TRIP_A) > 9999) /* 当前单位在KM时,里程大于999.9KM进行清零 */ if (Data_Read_Trip(EM_TRIP_A) > 9999) /* 当前单位在KM时,里程大于999.9KM进行清零 */
// { {
// Data_Clear_Trip_All(); Data_Clear_Trip_All();
// } }
// } }
} }
......
...@@ -56,7 +56,7 @@ static void Power_KL30_Init(void) ...@@ -56,7 +56,7 @@ static void Power_KL30_Init(void)
Fuel_KL30_Init(); Fuel_KL30_Init();
Amt630hInit(); Amt630hInit();
Telltales_Init(); Telltales_Init();
TimerM_PWM_counter_Output_Init(TIMERM_COUNTER1, 400, 64000000); TimerM_PWM_counter_Output_Init(TIMERM_COUNTER1, 20000, 64000000);
TimerM_PWM_CH_Output_init(TIMERM_COUNTER1, TIMERM_CHB, ActiveLevel_High); TimerM_PWM_CH_Output_init(TIMERM_COUNTER1, TIMERM_CHB, ActiveLevel_High);
g_stRTCInformation.u8RTCSecond = 0; g_stRTCInformation.u8RTCSecond = 0;
g_stRTCInformation.u8RTCMinute = 0; g_stRTCInformation.u8RTCMinute = 0;
...@@ -68,7 +68,7 @@ static void Power_KL30_Init(void) ...@@ -68,7 +68,7 @@ static void Power_KL30_Init(void)
Menu_User_Init(); Menu_User_Init();
Can_Init(); Can_Init();
Protocol_KL30_Wakeup_Init(); Protocol_KL30_Wakeup_Init();
TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, 100); TimerM_PWM_set_duty(TIMERM_COUNTER1, TIMERM_CHB, 500);
RTE_DEEPSLEEP_GPIO_Interrupt_Enable(KL15_AD_IN, Trigger_Rising); RTE_DEEPSLEEP_GPIO_Interrupt_Enable(KL15_AD_IN, Trigger_Rising);
FaultCode_Init(); FaultCode_Init();
} }
...@@ -88,7 +88,7 @@ static void Power_Wakeup_Init(void) ...@@ -88,7 +88,7 @@ static void Power_Wakeup_Init(void)
Line_In_KL15_ON_Init(); Line_In_KL15_ON_Init();
Fuel_KL30_Init(); Fuel_KL30_Init();
Amt630hInit(); Amt630hInit();
TimerM_PWM_counter_Output_Init(TIMERM_COUNTER1, 400, 64000000); TimerM_PWM_counter_Output_Init(TIMERM_COUNTER1, 20000, 64000000);
TimerM_PWM_CH_Output_init(TIMERM_COUNTER1, TIMERM_CHB, ActiveLevel_High); TimerM_PWM_CH_Output_init(TIMERM_COUNTER1, TIMERM_CHB, ActiveLevel_High);
Telltales_Init(); Telltales_Init();
Key_KL30_Init_EXample(); Key_KL30_Init_EXample();
...@@ -120,13 +120,13 @@ static void Power_IG_ON_Init(void) ...@@ -120,13 +120,13 @@ static void Power_IG_ON_Init(void)
Line_In_KL15_ON_Init(); Line_In_KL15_ON_Init();
Telltales_KL15_Init(); Telltales_KL15_Init();
Fuel_KL15_Init(); Fuel_KL15_Init();
RTE_GPIO_Set_Level(Blacklight_PWM, 1); //RTE_GPIO_Set_Level(Blacklight_PWM, 1);
FaultCode_Init(); FaultCode_Init();
} }
static void Power_Sleep_Init(void) static void Power_Sleep_Init(void)
{ {
TimerM_PWM_counter_Output_Init(TIMERM_COUNTER1, 400, 0); TimerM_PWM_counter_Output_Init(TIMERM_COUNTER1, 20000, 0);
rte_can_deinit(CAN_CH_0); rte_can_deinit(CAN_CH_0);
TMM0_Stop(); TMM0_Stop();
TMM1_Stop(); TMM1_Stop();
......
/* /*
* TrmerM.c * TrmerM.c
* *
* Created on: 2024�?2�?21�? * Created on: 2024年2月21日
*/ */
#include <stdint.h> #include <stdint.h>
// #include "gpio.h" // #include "gpio.h"
...@@ -25,21 +25,21 @@ typedef struct ...@@ -25,21 +25,21 @@ typedef struct
// /*占空比精度千分之一*/ // /*占空比精度千分之一*/
// extern void TimerB_PWM_Channel_Duty_Set(TIMERB_Channel_en_t enTimerBChannel, uint16_t u16Duty); // extern void TimerB_PWM_Channel_Duty_Set(TIMERB_Channel_en_t enTimerBChannel, uint16_t u16Duty);
// extern void TimerB_PWM_Channel_Start(TIMERB_Channel_en_t enTimerBChannel); // extern void TimerB_PWM_Channel_Start(TIMERB_Channel_en_t enTimerBChannel);
// /*调用该函数后,仅重新调用开始函数功能即可正常使�?*/ // /*调用该函数后,仅重新调用开始函数功能即可正常使*/
// extern void TimerB_PWM_Channel_Stop(TIMERB_Channel_en_t enTimerBChannel); // extern void TimerB_PWM_Channel_Stop(TIMERB_Channel_en_t enTimerBChannel);
// /*仅休眠时可调用,调用该函数后需要重新初始化相关通道才可以正常使用�?*/ // /*仅休眠时可调用,调用该函数后需要重新初始化相关通道才可以正常使用*/
// extern void TimerB_PWM_Channel_Sleep(TIMERB_Channel_en_t enTimerBChannel); // extern void TimerB_PWM_Channel_Sleep(TIMERB_Channel_en_t enTimerBChannel);
TMM_InitTypeDef TIMM_InitStructure[2] = {0}; TMM_InitTypeDef TIMM_InitStructure[2] = {0};
static uint32_t cycle_pulse[2]; //一个周期的时钟�? //频率 static uint32_t cycle_pulse[2]; //一个周期的时钟 //频率
static uint32_t high_level_Pulse[2][3]; //高电平时钟数 //占空�? static uint32_t high_level_Pulse[2][3]; //高电平时钟数 //占空
static uint32_t pwm_duty[2][3]; static uint32_t pwm_duty[2][3];
/** /**
* @brief 设置TimerM的定时器x的模式为比较输出 * @brief 设置TimerM的定时器x的模式为比较输出
* *
* @param counter 定时�? * @param counter 定时
* @param freq 比较输出频率 * @param freq 比较输出频率
* @return uint8_t 返回0成功,非0失败 * @return uint8_t 返回0成功,非0失败
*/ */
...@@ -48,32 +48,20 @@ uint8_t TimerM_PWM_counter_Output_Init(TIMERM_PWM_Counter_en_t counter, uint16_t ...@@ -48,32 +48,20 @@ uint8_t TimerM_PWM_counter_Output_Init(TIMERM_PWM_Counter_en_t counter, uint16_t
if (counter == TIMERM_COUNTER0) if (counter == TIMERM_COUNTER0)
{ {
TIMM_InitStructure[counter].TMM_Select = TMM0; TIMM_InitStructure[counter].TMM_Select = TMM0;
TIMM_InitStructure[counter].TMM_Channel = TMM_Channel_A|TMM_Channel_B|TMM_Channel_C|TMM_Channel_D;
TIMM_InitStructure[counter].TMM_Mode = TMM_Mode_PWM;
TIMM_InitStructure[counter].TMM_CounterClear = TM_Clear_Match_TMGRA; //when TM is matched with TMGRA, TM0 is cleared
TIMM_InitStructure[counter].TMM_Intp = TMM_Int_NONE; ///compare match interrupt enable A (IMIEA)
} }
else if (counter == TIMERM_COUNTER1) else if (counter == TIMERM_COUNTER1)
{ {
TIMM_InitStructure[counter].TMM_Select = TMM1; TIMM_InitStructure[counter].TMM_Select = TMM1;
TIMM_InitStructure[counter].TMM_Channel = TMM_Channel_A|TMM_Channel_B;//|TMM_Channel_C|TMM_Channel_D;
TIMM_InitStructure[counter].TMM_Mode = TMM_Mode_PWM;
TIMM_InitStructure[counter].TMM_CounterClear = TM_Clear_Match_TMGRA; //when TM is matched with TMGRA, TM0 is cleared
TIMM_InitStructure[counter].TMM_Intp = TMM_Int_NONE; ///compare match interrupt enable A (IMIEA)
} }
else else
{ {
return 1; return 1;
} }
// TIMM_InitStructure[counter].TMM_Channel = TMM_Channel_A|TMM_Channel_B|TMM_Channel_C|TMM_Channel_D; TIMM_InitStructure[counter].TMM_Channel = TMM_Channel_A|TMM_Channel_B|TMM_Channel_C|TMM_Channel_D;
// TIMM_InitStructure[counter].TMM_Mode = TMM_Mode_PWM; TIMM_InitStructure[counter].TMM_Mode = TMM_Mode_PWM;
// TIMM_InitStructure[counter].TMM_CounterClear = TM_Clear_Match_TMGRA; //when TM is matched with TMGRA, TM0 is cleared TIMM_InitStructure[counter].TMM_CounterClear = TM_Clear_Match_TMGRA; //when TM is matched with TMGRA, TM0 is cleared
// TIMM_InitStructure[counter].TMM_Intp = TMM_Int_IMIA; ///compare match interrupt enable A (IMIEA) TIMM_InitStructure[counter].TMM_Intp = TMM_Int_NONE; ///compare match interrupt enable A (IMIEA)
if (freq > 2000) if (freq > 2000)
{ {
...@@ -95,7 +83,7 @@ uint8_t TimerM_PWM_counter_Output_Init(TIMERM_PWM_Counter_en_t counter, uint16_t ...@@ -95,7 +83,7 @@ uint8_t TimerM_PWM_counter_Output_Init(TIMERM_PWM_Counter_en_t counter, uint16_t
return 1; return 1;
} }
TIMM_InitStructure[counter].TMM_CHA_Pulse = cycle_pulse[counter] & 0x0FFFF;//这里需要计算,调试�? period; //周期设置为period TIMM_InitStructure[counter].TMM_CHA_Pulse = cycle_pulse[counter] & 0x0FFFF;//这里需要计算,调试 period; //周期设置为period
...@@ -115,34 +103,23 @@ uint8_t TimerM_PWM_counter_Output_Init(TIMERM_PWM_Counter_en_t counter, uint16_t ...@@ -115,34 +103,23 @@ uint8_t TimerM_PWM_counter_Output_Init(TIMERM_PWM_Counter_en_t counter, uint16_t
//uint8_t TimerM_PWM_counter_Output_Init(TIMERM_PWM_Counter_en_t counter, uint16_t freq)//, uint32_t PWM_Clock //SystemCoreClock //uint8_t TimerM_PWM_counter_Output_Init(TIMERM_PWM_Counter_en_t counter, uint16_t freq)//, uint32_t PWM_Clock //SystemCoreClock
//{ //{
// SystemCoreClock = 64000000UL;
//
// if (counter == TIMERM_COUNTER0) // if (counter == TIMERM_COUNTER0)
// { // {
// TIMM_InitStructure[counter].TMM_Select = TMM0; // TIMM_InitStructure[counter].TMM_Select = TMM0;
//
// TIMM_InitStructure[counter].TMM_Channel = TMM_Channel_B|TMM_Channel_C|TMM_Channel_D;
// TIMM_InitStructure[counter].TMM_Mode = TMM_Mode_PWM;
// TIMM_InitStructure[counter].TMM_CounterClear = TM_Clear_Match_TMGRA; //when TM is matched with TMGRA, TM0 is cleared
// TIMM_InitStructure[counter].TMM_Intp = TMM_Int_IMIA; ///compare match interrupt enable A (IMIEA)
// } // }
// else if (counter == TIMERM_COUNTER1) // else if (counter == TIMERM_COUNTER1)
// { // {
// TIMM_InitStructure[counter].TMM_Select = TMM1; // TIMM_InitStructure[counter].TMM_Select = TMM1;
// TIMM_InitStructure[counter].TMM_Channel = TMM_Channel_B;
// TIMM_InitStructure[counter].TMM_Mode = TMM_Mode_PWM;
// TIMM_InitStructure[counter].TMM_CounterClear = TM_Clear_Match_TMGRA; //when TM is matched with TMGRA, TM0 is cleared
// TIMM_InitStructure[counter].TMM_Intp = TMM_Int_IMIA; ///compare match interrupt enable A (IMIEA)
// } // }
// else // else
// { // {
// return 1; // return 1;
// } // }
// //
//// TIMM_InitStructure[counter].TMM_Channel = TMM_Channel_A|TMM_Channel_B|TMM_Channel_C|TMM_Channel_D; // TIMM_InitStructure[counter].TMM_Channel = TMM_Channel_A|TMM_Channel_B|TMM_Channel_C|TMM_Channel_D;
//// TIMM_InitStructure[counter].TMM_Mode = TMM_Mode_PWM; // TIMM_InitStructure[counter].TMM_Mode = TMM_Mode_PWM;
//// TIMM_InitStructure[counter].TMM_CounterClear = TM_Clear_Match_TMGRA; //when TM is matched with TMGRA, TM0 is cleared // TIMM_InitStructure[counter].TMM_CounterClear = TM_Clear_Match_TMGRA; //when TM is matched with TMGRA, TM0 is cleared
//// TIMM_InitStructure[counter].TMM_Intp = TMM_Int_IMIA; ///compare match interrupt enable A (IMIEA) // TIMM_InitStructure[counter].TMM_Intp = TMM_Int_IMIA; ///compare match interrupt enable A (IMIEA)
// //
// if (freq > 2000) // if (freq > 2000)
// { // {
...@@ -164,7 +141,7 @@ uint8_t TimerM_PWM_counter_Output_Init(TIMERM_PWM_Counter_en_t counter, uint16_t ...@@ -164,7 +141,7 @@ uint8_t TimerM_PWM_counter_Output_Init(TIMERM_PWM_Counter_en_t counter, uint16_t
// return 1; // return 1;
// } // }
// //
// TIMM_InitStructure[counter].TMM_CHA_Pulse = cycle_pulse[counter] & 0x0FFFF;//这里需要计算,调试�? period; //周期设置为period // TIMM_InitStructure[counter].TMM_CHA_Pulse = cycle_pulse[counter] & 0x0FFFF;//这里需要计算,调试 period; //周期设置为period
// //
// //
// //
...@@ -187,9 +164,9 @@ uint8_t TimerM_PWM_counter_Output_Init(TIMERM_PWM_Counter_en_t counter, uint16_t ...@@ -187,9 +164,9 @@ uint8_t TimerM_PWM_counter_Output_Init(TIMERM_PWM_Counter_en_t counter, uint16_t
/** /**
* @brief 设置timerM定时器x通道x的占空比 * @brief 设置timerM定时器x通道x的占空比
* *
* @param counter 定时�? * @param counter 定时
* @param ch 通道 * @param ch 通道
* @param duty 占空�? xxxx/1000 千分�? * @param duty 占空比 xxxx/1000 千分之
* @param ActiveLevel 0负占空比 1正占空比 * @param ActiveLevel 0负占空比 1正占空比
* @return uint8_t 返回0成功,非0失败 * @return uint8_t 返回0成功,非0失败
*/ */
...@@ -201,7 +178,7 @@ uint8_t TimerM_PWM_CH_Output_init(TIMERM_PWM_Counter_en_t counter, TIMERM_PWM_Ch ...@@ -201,7 +178,7 @@ uint8_t TimerM_PWM_CH_Output_init(TIMERM_PWM_Counter_en_t counter, TIMERM_PWM_Ch
switch (ch) switch (ch)
{ {
case TIMERM_CHB: case TIMERM_CHB:
TIMM_InitStructure[counter].TMM_CHB_Pulse = ((cycle_pulse[counter]) ) & 0x0FFFF; //TM计数达到TMGRB. 占空�?:duty2/period TIMM_InitStructure[counter].TMM_CHB_Pulse = ((cycle_pulse[counter]) ) & 0x0FFFF; //TM计数达到TMGRB. 占空:duty2/period
TIMM_InitStructure[counter].TMM_PWM.TMM_CHB.TMM_PWMInitLevel = TMM_PWMInitLevel_High; TIMM_InitStructure[counter].TMM_PWM.TMM_CHB.TMM_PWMInitLevel = TMM_PWMInitLevel_High;
TIMM_InitStructure[counter].TMM_PWM.TMM_CHB.TMM_PWMActiveLevel = ActiveLevel; TIMM_InitStructure[counter].TMM_PWM.TMM_CHB.TMM_PWMActiveLevel = ActiveLevel;
if (counter == TIMERM_COUNTER0) if (counter == TIMERM_COUNTER0)
...@@ -217,7 +194,7 @@ uint8_t TimerM_PWM_CH_Output_init(TIMERM_PWM_Counter_en_t counter, TIMERM_PWM_Ch ...@@ -217,7 +194,7 @@ uint8_t TimerM_PWM_CH_Output_init(TIMERM_PWM_Counter_en_t counter, TIMERM_PWM_Ch
break; break;
case TIMERM_CHC: case TIMERM_CHC:
TIMM_InitStructure[counter].TMM_CHC_Pulse = ((cycle_pulse[counter]) ) & 0x0FFFF; //TM计数达到TMGRC. 占空�?:duty2/period TIMM_InitStructure[counter].TMM_CHC_Pulse = ((cycle_pulse[counter]) ) & 0x0FFFF; //TM计数达到TMGRC. 占空:duty2/period
TIMM_InitStructure[counter].TMM_PWM.TMM_CHC.TMM_PWMInitLevel = TMM_PWMInitLevel_High; TIMM_InitStructure[counter].TMM_PWM.TMM_CHC.TMM_PWMInitLevel = TMM_PWMInitLevel_High;
TIMM_InitStructure[counter].TMM_PWM.TMM_CHC.TMM_PWMActiveLevel = ActiveLevel; TIMM_InitStructure[counter].TMM_PWM.TMM_CHC.TMM_PWMActiveLevel = ActiveLevel;
if (counter == TIMERM_COUNTER0) if (counter == TIMERM_COUNTER0)
...@@ -232,7 +209,7 @@ uint8_t TimerM_PWM_CH_Output_init(TIMERM_PWM_Counter_en_t counter, TIMERM_PWM_Ch ...@@ -232,7 +209,7 @@ uint8_t TimerM_PWM_CH_Output_init(TIMERM_PWM_Counter_en_t counter, TIMERM_PWM_Ch
break; break;
case TIMERM_CHD: case TIMERM_CHD:
TIMM_InitStructure[counter].TMM_CHD_Pulse = ((cycle_pulse[counter]) ) & 0x0FFFF; //TM计数达到TMGRD. 占空�?:duty3/period TIMM_InitStructure[counter].TMM_CHD_Pulse = ((cycle_pulse[counter]) ) & 0x0FFFF; //TM计数达到TMGRD. 占空:duty3/period
TIMM_InitStructure[counter].TMM_PWM.TMM_CHD.TMM_PWMInitLevel = TMM_PWMInitLevel_High;//TMM_PWMInitLevel_High;// TIMM_InitStructure[counter].TMM_PWM.TMM_CHD.TMM_PWMInitLevel = TMM_PWMInitLevel_High;//TMM_PWMInitLevel_High;//
TIMM_InitStructure[counter].TMM_PWM.TMM_CHD.TMM_PWMActiveLevel = ActiveLevel;//TMM_PWMActiveLevel_Low;//TMM_PWMActiveLevel_High;// TIMM_InitStructure[counter].TMM_PWM.TMM_CHD.TMM_PWMActiveLevel = ActiveLevel;//TMM_PWMActiveLevel_Low;//TMM_PWMActiveLevel_High;//
if (counter == TIMERM_COUNTER0) if (counter == TIMERM_COUNTER0)
...@@ -250,13 +227,15 @@ uint8_t TimerM_PWM_CH_Output_init(TIMERM_PWM_Counter_en_t counter, TIMERM_PWM_Ch ...@@ -250,13 +227,15 @@ uint8_t TimerM_PWM_CH_Output_init(TIMERM_PWM_Counter_en_t counter, TIMERM_PWM_Ch
return 1; return 1;
//break; //break;
} }
TMM_Init(&TIMM_InitStructure[counter]);
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStruct.GPIO_Level = GPIO_Level_LOW; GPIO_InitStruct.GPIO_Level = GPIO_Level_LOW;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIO_PORT1,&GPIO_InitStruct);
TMM_Init(&TIMM_InitStructure[counter]);
if (counter == TIMERM_COUNTER0) if (counter == TIMERM_COUNTER0)
{ {
TMM0_Start(ENABLE); TMM0_Start(ENABLE);
...@@ -270,7 +249,7 @@ uint8_t TimerM_PWM_CH_Output_init(TIMERM_PWM_Counter_en_t counter, TIMERM_PWM_Ch ...@@ -270,7 +249,7 @@ uint8_t TimerM_PWM_CH_Output_init(TIMERM_PWM_Counter_en_t counter, TIMERM_PWM_Ch
return 1; return 1;
} }
GPIO_Init(GPIO_PORT1,&GPIO_InitStruct);
high_level_Pulse[counter][ch] = ((cycle_pulse[counter]) ) & 0x0FFFF; high_level_Pulse[counter][ch] = ((cycle_pulse[counter]) ) & 0x0FFFF;
pwm_duty[counter][ch] = 1000; pwm_duty[counter][ch] = 1000;
...@@ -287,7 +266,7 @@ extern void TMM1_Set_Counter(uint8_t ch,uint16_t value); ...@@ -287,7 +266,7 @@ extern void TMM1_Set_Counter(uint8_t ch,uint16_t value);
* *
* @param counter 定时器x * @param counter 定时器x
* @param ch 通道x * @param ch 通道x
* @param duty 占空�? 千分之一 * @param duty 占空 千分之一
* @return uint8_t 返回0成功,非0失败 * @return uint8_t 返回0成功,非0失败
*/ */
uint8_t TimerM_PWM_set_duty(TIMERM_PWM_Counter_en_t counter, TIMERM_PWM_Channel_en_t ch, uint16_t duty ) uint8_t TimerM_PWM_set_duty(TIMERM_PWM_Counter_en_t counter, TIMERM_PWM_Channel_en_t ch, uint16_t duty )
...@@ -325,11 +304,11 @@ uint8_t TimerM_PWM_set_duty(TIMERM_PWM_Counter_en_t counter, TIMERM_PWM_Channel_ ...@@ -325,11 +304,11 @@ uint8_t TimerM_PWM_set_duty(TIMERM_PWM_Counter_en_t counter, TIMERM_PWM_Channel_
* *
* @param counter 定时器x * @param counter 定时器x
* @param freq PWM频率 * @param freq PWM频率
* @return uint8_t 0成功 �?0失败 * @return uint8_t 0成功 0失败
* *
* @note 频率范围有两种,50~2000 2001~最大,如果初始话的频率和目标频率在一个区间可以使用TimerM_PWM_set_freq2函数来优雅的切换频率�? * @note 频率范围有两种,50~2000 2001~最大,如果初始话的频率和目标频率在一个区间可以使用TimerM_PWM_set_freq2函数来优雅的切换频率
* 如果不在一个频率区间就需要使用TimerM_PWM_set_freq来不优雅的切换频率, * 如果不在一个频率区间就需要使用TimerM_PWM_set_freq来不优雅的切换频率,
* 如果看不懂注释也使用TimerM_PWM_set_freq来切换频率�? * 如果看不懂注释也使用TimerM_PWM_set_freq来切换频率
*/ */
uint8_t TimerM_PWM_set_freq(TIMERM_PWM_Counter_en_t counter, uint16_t freq ) uint8_t TimerM_PWM_set_freq(TIMERM_PWM_Counter_en_t counter, uint16_t freq )
{ {
......
...@@ -40,6 +40,7 @@ void Sys_10ms_Tasks(void) ...@@ -40,6 +40,7 @@ void Sys_10ms_Tasks(void)
Key_TimeOut_Service(); Key_TimeOut_Service();
Fuel_R_Cal(10u); Fuel_R_Cal(10u);
Coolant_R_Cal(10u); Coolant_R_Cal(10u);
Data_Light_Res_service(10);
} }
void Sys_20ms_Tasks(void) void Sys_20ms_Tasks(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment