Rev 36 | Rev 39 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 36 | Rev 37 | ||
|---|---|---|---|
| Line 2... | Line 2... | ||
| 2 | * misc.c |
2 | * misc.c |
| 3 | * |
3 | * |
| 4 | * Created on: 21 Sep 2016 |
4 | * Created on: 21 Sep 2016 |
| 5 | * Author: Mike |
5 | * Author: Mike |
| 6 | */ |
6 | */ |
| 7 | #include "stm32l1xx_hal.h" |
7 | #include "stm32f1xx_hal.h" |
| 8 | #include "misc.h" |
8 | #include "misc.h" |
| 9 | #include "main.h" |
9 | #include "main.h" |
| 10 | 10 | ||
| 11 | extern TIM_HandleTypeDef htim2; |
- | |
| 12 | extern TIM_HandleTypeDef htim3; |
- | |
| 13 | extern TIM_HandleTypeDef htim6; |
- | |
| 14 | 11 | ||
| 15 | unsigned volatile long RPM_Time[RPM_SAMPLES]; // sampled on both edges |
12 | unsigned volatile long RPM_Time[RPM_SAMPLES]; // sampled on both edges |
| 16 | unsigned volatile char RPM_Level[RPM_SAMPLES]; // active level when sampled |
13 | unsigned volatile char RPM_Level[RPM_SAMPLES]; // active level when sampled |
| 17 | unsigned volatile long RPM_Count; // incremented every reading |
14 | unsigned volatile long RPM_Count; // incremented every reading |
| 18 | 15 | ||
| Line 45... | Line 42... | ||
| 45 | triggerTim3 (); |
42 | triggerTim3 (); |
| 46 | } |
43 | } |
| 47 | } |
44 | } |
| 48 | } |
45 | } |
| 49 | 46 | ||
| 50 | char chtTimer = 0; |
- | |
| 51 | char blink = 0; |
- | |
| 52 | // 100mS periodic sampler handler |
- | |
| 53 | void |
- | |
| 54 | TIM6_IRQHandler (void) |
- | |
| 55 | { |
- | |
| 56 | if (__HAL_TIM_GET_FLAG(&htim6, TIM_FLAG_UPDATE)) |
- | |
| 57 | { |
- | |
| 58 | __HAL_TIM_CLEAR_FLAG(&htim6, TIM_FLAG_UPDATE); |
- | |
| 59 | - | ||
| 60 | blink = !blink; |
- | |
| 61 | HAL_GPIO_WritePin (LED_Blink_GPIO_Port, LED_Blink_Pin, |
- | |
| 62 | blink ? GPIO_PIN_SET : GPIO_PIN_RESET); |
- | |
| 63 | - | ||
| 64 | TimerFlag = 1; |
- | |
| 65 | if (NoSerialInCTR < 5) |
- | |
| 66 | { |
- | |
| 67 | NoSerialInCTR++; |
- | |
| 68 | if (NoSerialInCTR == 5) |
- | |
| 69 | { |
- | |
| 70 | NoSerialIn = 1; |
- | |
| 71 | } |
- | |
| 72 | } |
- | |
| 73 | - | ||
| 74 | if (periodPulse == 1) |
- | |
| 75 | { |
- | |
| 76 | triggerTim3 (); |
- | |
| 77 | - | ||
| 78 | } |
- | |
| 79 | periodPulse = 1; |
- | |
| 80 | - | ||
| 81 | - | ||
| 82 | chtTimer++; |
- | |
| 83 | } |
- | |
| 84 | 47 | ||
| 85 | } |
- | |
| - | 48 | // timer variable shared between TIM3 and TIM4 handler. |
|
| - | 49 | static char chtTimer = 0; |
|
| 86 | 50 | ||
| 87 | void |
51 | void |
| 88 | TIM3_IRQHandler (void) |
52 | TIM3_IRQHandler (void) |
| 89 | { |
53 | { |
| 90 | if (__HAL_TIM_GET_FLAG(&htim3, TIM_FLAG_UPDATE)) |
54 | if (__HAL_TIM_GET_FLAG(&htim3, TIM_FLAG_UPDATE)) |
| Line 122... | Line 86... | ||
| 122 | } |
86 | } |
| 123 | } |
87 | } |
| 124 | } |
88 | } |
| 125 | } |
89 | } |
| 126 | 90 | ||
| - | 91 | // 100mS periodic sampler handler |
|
| - | 92 | void |
|
| - | 93 | TIM4_IRQHandler (void) |
|
| - | 94 | { |
|
| - | 95 | static char blink = 0; |
|
| - | 96 | if (__HAL_TIM_GET_FLAG(&htim4, TIM_FLAG_UPDATE)) |
|
| - | 97 | { |
|
| - | 98 | __HAL_TIM_CLEAR_FLAG(&htim4, TIM_FLAG_UPDATE); |
|
| - | 99 | ||
| - | 100 | blink = !blink; |
|
| - | 101 | HAL_GPIO_WritePin (LED_Blink_GPIO_Port, LED_Blink_Pin, |
|
| - | 102 | blink ? GPIO_PIN_SET : GPIO_PIN_RESET); |
|
| - | 103 | ||
| - | 104 | TimerFlag = 1; |
|
| - | 105 | if (NoSerialInCTR < 5) |
|
| - | 106 | { |
|
| - | 107 | NoSerialInCTR++; |
|
| - | 108 | if (NoSerialInCTR == 5) |
|
| - | 109 | { |
|
| - | 110 | NoSerialIn = 1; |
|
| - | 111 | } |
|
| - | 112 | } |
|
| - | 113 | ||
| - | 114 | if (periodPulse == 1) |
|
| - | 115 | { |
|
| - | 116 | triggerTim3 (); |
|
| - | 117 | ||
| - | 118 | } |
|
| - | 119 | periodPulse = 1; |
|
| - | 120 | ||
| - | 121 | ||
| - | 122 | chtTimer++; |
|
| - | 123 | } |
|
| - | 124 | ||
| - | 125 | } |
|
| - | 126 | ||
| - | 127 | ||
| 127 | void |
128 | void |
| 128 | resetSerialTimeout (void) |
129 | resetSerialTimeout (void) |
| 129 | { |
130 | { |
| 130 | __disable_irq (); |
131 | __disable_irq (); |
| 131 | NoSerialInCTR = 0; |
132 | NoSerialInCTR = 0; |