Subversion Repositories EngineBay2

Rev

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

Rev 37 Rev 39
Line 8... Line 8...
8
#include "misc.h"
8
#include "misc.h"
9
#include "main.h"
9
#include "main.h"
10
 
10
 
11
 
11
 
12
unsigned volatile long RPM_Time[RPM_SAMPLES];  // sampled on both  edges
12
unsigned volatile long RPM_Time[RPM_SAMPLES];  // sampled on both  edges
13
unsigned volatile char RPM_Level[RPM_SAMPLES]; // active level when sampled
-
 
14
unsigned volatile long RPM_Count; // incremented every reading
13
unsigned volatile long RPM_Count; // incremented every reading
15
 
14
 
16
// this is set if there is a timer timeout interrupt
15
// this is set if there is a timer timeout interrupt
17
unsigned char volatile periodPulse = 0;
16
unsigned char volatile periodPulse = 0;
18
 
17
 
-
 
18
unsigned char volatile tim3triggered = 0;
-
 
19
 
19
static void
20
static void
20
triggerTim3 (void)
21
triggerTim3 (void)
21
{
22
{
22
  htim3.Instance->CNT = 0;
23
  htim3.Instance->CNT = 0;
23
  htim3.Instance->CR1 |= TIM_CR1_CEN;
24
  htim3.Instance->CR1 |= TIM_CR1_CEN;
Line 29... Line 30...
29
{
30
{
30
  if (__HAL_TIM_GET_FLAG(&htim2, TIM_FLAG_CC1))
31
  if (__HAL_TIM_GET_FLAG(&htim2, TIM_FLAG_CC1))
31
    {
32
    {
32
      __HAL_TIM_CLEAR_FLAG(&htim2, TIM_FLAG_CC1);
33
      __HAL_TIM_CLEAR_FLAG(&htim2, TIM_FLAG_CC1);
33
      RPM_Time[RPM_Count] = __HAL_TIM_GET_COMPARE(&htim2, TIM_CHANNEL_1);
34
      RPM_Time[RPM_Count] = __HAL_TIM_GET_COMPARE(&htim2, TIM_CHANNEL_1);
34
      int CB_level = HAL_GPIO_ReadPin (CB_Pulse_GPIO_Port,
-
 
35
                                       CB_Pulse_Pin);
-
 
36
      RPM_Level[RPM_Count] = CB_level;
-
 
37
      RPM_Count = (RPM_Count + 1) % RPM_SAMPLES;
35
      RPM_Count = (RPM_Count + 1) % RPM_SAMPLES;
38
 
36
 
39
      if ( CB_level == 0)
37
      if ( tim3triggered == 0)
40
        {
38
        {
-
 
39
          tim3triggered = 1; // make it a monostable
41
          periodPulse = 0;
40
          periodPulse = 0;
42
          triggerTim3 ();
41
          triggerTim3 ();
43
        }
42
        }
44
    }
43
    }
45
}
44
}
Line 53... Line 52...
53
{
52
{
54
  if (__HAL_TIM_GET_FLAG(&htim3, TIM_FLAG_UPDATE))
53
  if (__HAL_TIM_GET_FLAG(&htim3, TIM_FLAG_UPDATE))
55
    {
54
    {
56
      __HAL_TIM_CLEAR_FLAG(&htim3, TIM_FLAG_UPDATE);
55
      __HAL_TIM_CLEAR_FLAG(&htim3, TIM_FLAG_UPDATE);
57
 
56
 
-
 
57
      tim3triggered = 0;
58
      if (chtTimer >= 3)  // every 300mS
58
      if (chtTimer >= 3)  // every 300mS
59
        {
59
        {
60
          chtTimer = 0;
60
          chtTimer = 0;
61
 
61
 
62
          for (int instance = 0; instance < 2; instance++)
62
          for (int instance = 0; instance < 2; instance++)