Rev 9 | Rev 29 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 9 | Rev 28 | ||
---|---|---|---|
Line 6... | Line 6... | ||
6 | */ |
6 | */ |
7 | #include "stm32l1xx_hal.h" |
7 | #include "stm32l1xx_hal.h" |
8 | #include "misc.h" |
8 | #include "misc.h" |
9 | #include "main.h" |
9 | #include "main.h" |
10 | 10 | ||
11 | unsigned volatile long RPM_Time[RPM_SAMPLES]; // sampled on falling edge |
- | |
12 | unsigned volatile long RPM_Count; // incremented every reading |
- | |
13 | - | ||
14 | 11 | ||
- | 12 | extern TIM_HandleTypeDef htim2; |
|
- | 13 | extern TIM_HandleTypeDef htim3; |
|
- | 14 | extern TIM_HandleTypeDef htim6; |
|
15 | 15 | ||
16 | void _init(void) |
- | |
17 | { |
- | |
18 | 16 | ||
19 | } |
- | |
- | 17 | unsigned volatile long RPM_Time[RPM_SAMPLES]; // sampled on both edges |
|
- | 18 | unsigned volatile char RPM_Level[RPM_SAMPLES]; // active level when sampled |
|
- | 19 | unsigned volatile long RPM_Count; // incremented every reading |
|
20 | 20 | ||
21 | 21 | ||
22 | void TIM2_IRQHandler(void) |
22 | void TIM2_IRQHandler(void) |
23 | { |
23 | { |
24 | if(__HAL_TIM_GET_FLAG(&htim2, TIM_FLAG_CC1)) |
24 | if(__HAL_TIM_GET_FLAG(&htim2, TIM_FLAG_CC1)) |
25 | { |
25 | { |
26 | __HAL_TIM_CLEAR_FLAG(&htim2, TIM_FLAG_CC1) ; |
26 | __HAL_TIM_CLEAR_FLAG(&htim2, TIM_FLAG_CC1) ; |
27 | RPM_Time[RPM_Count++] = __HAL_TIM_GET_COMPARE(&htim2,TIM_CHANNEL_1); |
27 | RPM_Time[RPM_Count] = __HAL_TIM_GET_COMPARE(&htim2,TIM_CHANNEL_1); |
28 | if (RPM_Count == RPM_SAMPLES) { |
28 | RPM_Level[RPM_Count] = |
- | 29 | HAL_GPIO_ReadPin(CB_Pulse_GPIO_Port, CB_Pulse_Pin); |
|
29 | RPM_Count = 0; |
30 | RPM_Count = (RPM_Count+1) % RPM_SAMPLES ; |
- | 31 | ||
- | 32 | __HAL_TIM_SET_COUNTER(&htim3,0); // trigger timer 3 by setting the count to zero |
|
30 | } |
33 | |
31 | } |
34 | } |
32 | } |
35 | } |
33 | 36 | ||
34 | 37 | ||
35 | char blink = 0; |
38 | char blink = 0; |
Line 52... | Line 55... | ||
52 | } |
55 | } |
53 | } |
56 | } |
54 | 57 | ||
55 | } |
58 | } |
56 | 59 | ||
- | 60 | void resetSerialTimeout(void) |
|
57 | 61 | { |
|
- | 62 | __disable_irq(); |
|
- | 63 | NoSerialInCTR= 0 ; |
|
- | 64 | NoSerialIn = 0; |
|
- | 65 | __enable_irq(); |
|
- | 66 | } |
|
58 | 67 | ||
59 | #if OLD_ENGINEBAY |
68 | #if OLD_ENGINEBAY |
60 | //----------------------------------------------------------- |
69 | //----------------------------------------------------------- |
61 | // This is the 10Hz timer |
70 | // This is the 10Hz timer |
62 | 71 |