1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include "Data_EngineSpeed.h"
#include "CAN_Communication_Matrix.h"
#include "GaugesInterface.h"
#include "RTE_PWM_OUT.h"
//-------------------------------------------
//转速数据处理
//-------------------------------------------
//断码显示
//-------------------------------------------
// 342 - 3.2. 行驶记录仪
//-------------------------------------------
static struct
{
uint16_t Value;
uint16_t Valid;
uint8_t CurSeg;
} TachoVariable;
static uint8_t CalTacho_CurSeg(uint8_t Valid, uint16_t Value);
/*-------------------------------------------------------------------------
* Function Name : Tacho_KL30_Init
* Description : 转速KL30初始化
* Input : None
* Output : None
* Return : None
* onther : None
--------------------------------------------------------------------------*/
void Tacho_KL30_Init(void)
{
TachoVariable.Value = 0u;
TachoVariable.Valid = 0u;
TachoVariable.CurSeg = 0u;
}
void Tacho_KL15_ON_Init(void)
{
TachoVariable.Value = 0u;
TachoVariable.Valid = 0u;
TachoVariable.CurSeg = 0u;
}
void Tacho_KL15_OFF_Init(void)
{
TachoVariable.Value = 0u;
TachoVariable.Valid = 0u;
TachoVariable.CurSeg = 0u;
}
void Tacho_Wakeup_Init(void)
{
TachoVariable.Value = 0u;
TachoVariable.Valid = 0u;
TachoVariable.CurSeg = 0u;
}
void Tacho_Sleep_Init(void)
{
TachoVariable.Value = 0u;
TachoVariable.Valid = 0u;
TachoVariable.CurSeg = 0u;
}
/*-------------------------------------------------------------------------
* Function Name : Tacho_Processing_Service
* Description : 转速
* Input : None
* Output : None
* Return : None
* onther : None
--------------------------------------------------------------------------*/
void Tacho_Processing_Service(void)
{
uint16_t Msg_Epm_nEng = 0u;
uint32_t u32Result = 0u;
uint16_t Fre = 0u;
Msg_Epm_nEng = Get_ID_CF00400_Sig_Engine_speed();
if (Msg_Epm_nEng > 0xFAFFu)
{
TachoVariable.Valid = 0u;
u32Result = 0u;
}
else
{
TachoVariable.Valid = 1u;
u32Result = Msg_Epm_nEng;
u32Result *= 125u;
u32Result += 500u;
u32Result /= 1000u;
if (u32Result < 330u)
{
u32Result = 0u;
}
else if (u32Result > 3000u)
{
u32Result = 3000u;
}
}
TachoVariable.Value = RevSpeedManage((uint16_t)u32Result);
TachoVariable.CurSeg = CalTacho_CurSeg(TachoVariable.Valid, TachoVariable.Value);
//转*每转脉冲数/60=频率
u32Result *= 4u;
u32Result /= 60u;
Fre = (uint16_t)u32Result;
RTE_PWM_Set_Tacho_Out(Fre, 500u);
}
/*-------------------------------------------------------------------------
* Function Name : Tacho_Display
* Description : 计算转速当前格
* Input : None
* Output : None
* Return : None
* onther : None
--------------------------------------------------------------------------*/
static uint8_t CalTacho_CurSeg(uint8_t Valid, uint16_t Value)
{
uint8_t u8Result = 0u;
if (Valid)
{
}
else
{
//范围外/CAN中断
}
SetGaugesPara(RevGauges, Value);
u8Result = GetGaugesCurrentPos(RevGauges);
return u8Result;
}
/*-------------------------------------------------------------------------
* Function Name : Tacho_Get_ActualValue
* Description : 1倍转速
* Input : None
* Output : None
* Return : None
* onther : None
--------------------------------------------------------------------------*/
uint16_t Tacho_Get_ActualValue(void)
{
uint16_t u16Result = 0u;
u16Result = TachoVariable.Value;
return u16Result;
}
/*-------------------------------------------------------------------------
* Function Name : Tacho_Get_Valid
* Description :
* Input : None
* Output : None
* Return : None
* onther : None
--------------------------------------------------------------------------*/
uint8_t Tacho_Get_Valid(void)
{
uint8_t u8Result = 0u;
u8Result = TachoVariable.Valid;
return u8Result;
}
/*-------------------------------------------------------------------------
* Function Name : Tacho_Get_CurSeg
* Description : 转速当前格
* Input : None
* Output : None
* Return : None
* onther : 应用于断码
--------------------------------------------------------------------------*/
uint8_t Tacho_Get_CurSeg(void)
{
return TachoVariable.CurSeg;
}