Rev 50 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 50 | Rev 57 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #include "stm32l1xx_hal.h" |
1 | #include "stm32l1xx_hal.h" |
2 | 2 | ||
3 | #include "switches.h" |
3 | #include "switches.h" |
4 | #include "main.h" |
4 | #include "main.h" |
5 | 5 | ||
- | 6 | const int SHIFT = 1; |
|
6 | typedef enum |
7 | typedef enum |
7 | { |
8 | { |
8 | PH_00 = 0, PH_10 = 2, PH_11 = 3, PH_01 = 1, |
9 | PH_00 = 0, PH_10 = 2, PH_11 = 3, PH_01 = 1, |
9 | } eGreyCode; |
10 | } eGreyCode; |
10 | 11 | ||
Line 43... | Line 44... | ||
43 | // reset the dial positions |
44 | // reset the dial positions |
44 | for (i = 0; i < MAX_DIALS; i++) |
45 | for (i = 0; i < MAX_DIALS; i++) |
45 | { |
46 | { |
46 | dial_pos[i] = 0; |
47 | dial_pos[i] = 0; |
47 | } |
48 | } |
48 | dial_count[0] = __HAL_TIM_GET_COUNTER(&htim9) >> 2; |
49 | dial_count[0] = __HAL_TIM_GET_COUNTER(&htim9) >> SHIFT; |
49 | dial_count[1] = __HAL_TIM_GET_COUNTER(&htim3) >> 2; |
50 | dial_count[1] = __HAL_TIM_GET_COUNTER(&htim3) >> SHIFT; |
50 | } |
51 | } |
51 | 52 | ||
52 | // this is the interrupt handler , dealling with the switches |
53 | // this is the interrupt handler , dealling with the switches |
53 | void |
54 | void |
54 | HandleSwitches (void) |
55 | HandleSwitches (void) |
Line 82... | Line 83... | ||
82 | } |
83 | } |
83 | } |
84 | } |
84 | push_pos[0] = sw_newstate[0]; |
85 | push_pos[0] = sw_newstate[0]; |
85 | push_pos[1] = sw_newstate[1]; |
86 | push_pos[1] = sw_newstate[1]; |
86 | 87 | ||
- | 88 | // use the modulus counters from the timer counters |
|
87 | int cnt0 = __HAL_TIM_GET_COUNTER(&htim9) >> 2; // counts 4 per step |
89 | int cnt0 = __HAL_TIM_GET_COUNTER(&htim9) >> SHIFT; // counts 4 per step |
88 | int cnt1 = __HAL_TIM_GET_COUNTER(&htim3) >> 2; // counts 4 per step |
90 | int cnt1 = __HAL_TIM_GET_COUNTER(&htim3) >> SHIFT; // counts 4 per step |
89 | 91 | ||
90 | // always count up, or count down to zero but dont wrap |
92 | // always count up, or count down to zero but dont wrap |
91 | 93 | ||
92 | if ((dial_pos[0] != 0) || (cnt0 > dial_count[0])) |
94 | if ((dial_pos[0] != 0) || (cnt0 > dial_count[0])) |
93 | dial_pos[0] += cnt0 - dial_count[0]; |
95 | dial_pos[0] += cnt0 - dial_count[0]; |