Subversion Repositories EngineBay2

Rev

Rev 28 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 28 Rev 29
Line 17... Line 17...
17
unsigned volatile long RPM_Time[RPM_SAMPLES];  // sampled on both  edges
17
unsigned volatile long RPM_Time[RPM_SAMPLES];  // sampled on both  edges
18
unsigned volatile char RPM_Level[RPM_SAMPLES]; // active level when sampled
18
unsigned volatile char RPM_Level[RPM_SAMPLES]; // active level when sampled
19
unsigned volatile long RPM_Count; // incremented every reading
19
unsigned volatile long RPM_Count; // incremented every reading
20
 
20
 
21
 
21
 
-
 
22
// this is set if there is an ignition pulse interrupt
-
 
23
unsigned char volatile ignitionPulse = 0;
-
 
24
// this is set if there is a timer timeout interrupt
-
 
25
unsigned char volatile periodPulse  = 0;
-
 
26
 
-
 
27
static void triggerTim3(void)
-
 
28
{
-
 
29
   htim3.Instance->CNT = 0;
-
 
30
   htim3.Instance->CR1|= TIM_CR1_CEN;
-
 
31
 
-
 
32
}
-
 
33
 
22
void TIM2_IRQHandler(void)
34
void TIM2_IRQHandler(void)
23
{
35
{
24
        if(__HAL_TIM_GET_FLAG(&htim2, TIM_FLAG_CC1))
36
        if(__HAL_TIM_GET_FLAG(&htim2, TIM_FLAG_CC1))
25
        {
37
        {
26
                  __HAL_TIM_CLEAR_FLAG(&htim2, TIM_FLAG_CC1) ;
38
                  __HAL_TIM_CLEAR_FLAG(&htim2, TIM_FLAG_CC1) ;
27
                        RPM_Time[RPM_Count] = __HAL_TIM_GET_COMPARE(&htim2,TIM_CHANNEL_1);
39
                        RPM_Time[RPM_Count] = __HAL_TIM_GET_COMPARE(&htim2,TIM_CHANNEL_1);
28
                        RPM_Level[RPM_Count]  =
40
                        RPM_Level[RPM_Count]  =
29
                                HAL_GPIO_ReadPin(CB_Pulse_GPIO_Port, CB_Pulse_Pin);
41
                                HAL_GPIO_ReadPin(CB_Pulse_GPIO_Port, CB_Pulse_Pin);
30
                        RPM_Count = (RPM_Count+1) % RPM_SAMPLES ;
42
                        RPM_Count = (RPM_Count+1) % RPM_SAMPLES ;
31
 
43
 
-
 
44
                        if(periodPulse == 1)
-
 
45
                          {
-
 
46
                            periodPulse = 0;
32
                        __HAL_TIM_SET_COUNTER(&htim3,0); // trigger timer 3 by setting the count to zero
47
                            triggerTim3();
33
 
48
                          }
-
 
49
                ignitionPulse = 1;
34
        }
50
        }
35
}
51
}
36
 
52
 
37
 
53
 
38
char blink = 0;
54
char blink = 0;
Line 51... Line 67...
51
            NoSerialInCTR++;
67
            NoSerialInCTR++;
52
                if (NoSerialInCTR == 5) {
68
                if (NoSerialInCTR == 5) {
53
                  NoSerialIn = 1;
69
                  NoSerialIn = 1;
54
                }
70
                }
55
          }
71
          }
-
 
72
 
-
 
73
          if(ignitionPulse == 0)
-
 
74
            triggerTim3();
-
 
75
 
-
 
76
          periodPulse = 1;
56
        }
77
        }
57
 
78
 
58
}
79
}
59
 
80
 
60
void resetSerialTimeout(void)
81
void resetSerialTimeout(void)