123
Fork of LG by
MTimer.c@181:0b022246c43c, 2016-07-08 (annotated)
- Committer:
- Kovalev_D
- Date:
- Fri Jul 08 14:58:17 2016 +0000
- Revision:
- 181:0b022246c43c
- Parent:
- 170:d099c3025f87
- Child:
- 185:7e200f4d9b16
????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
igor_v | 0:8ad47e2b6f00 | 1 | #include "MTimer.h" |
igor_v | 0:8ad47e2b6f00 | 2 | #include "LPC17xx.h" |
igor_v | 0:8ad47e2b6f00 | 3 | #include "MTimer.h" |
igor_v | 0:8ad47e2b6f00 | 4 | #include "vibro.h" |
igor_v | 0:8ad47e2b6f00 | 5 | #include "QEI.h" |
igor_v | 0:8ad47e2b6f00 | 6 | #include "Global.h" |
igor_v | 0:8ad47e2b6f00 | 7 | #include "SPI.h" |
igor_v | 0:8ad47e2b6f00 | 8 | #include "InputOutput.h" |
Kovalev_D | 112:4a96133a1311 | 9 | |
igor_v | 0:8ad47e2b6f00 | 10 | |
Kovalev_D | 112:4a96133a1311 | 11 | |
igor_v | 0:8ad47e2b6f00 | 12 | //unsigned int CountV=0; |
igor_v | 21:bc8c1cec3da6 | 13 | //unsigned int CountVf=0 ; |
igor_v | 0:8ad47e2b6f00 | 14 | unsigned int CountV31=0; |
Kovalev_D | 115:e5a230e5af52 | 15 | unsigned int CountV255=0,f ; |
Kovalev_D | 124:9ae09249f842 | 16 | int loop=0; |
Kovalev_D | 112:4a96133a1311 | 17 | |
igor_v | 21:bc8c1cec3da6 | 18 | |
igor_v | 21:bc8c1cec3da6 | 19 | |
Kovalev_D | 88:b5c1d9d338d1 | 20 | |
Kovalev_D | 88:b5c1d9d338d1 | 21 | |
Kovalev_D | 88:b5c1d9d338d1 | 22 | |
Kovalev_D | 88:b5c1d9d338d1 | 23 | |
Kovalev_D | 88:b5c1d9d338d1 | 24 | |
Kovalev_D | 88:b5c1d9d338d1 | 25 | |
Kovalev_D | 88:b5c1d9d338d1 | 26 | |
Kovalev_D | 88:b5c1d9d338d1 | 27 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 28 | /////////////////////EVENT/////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 29 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 30 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 31 | ///////////////////// 1Hz /////////////////////////// |
Kovalev_D | 89:a0d344db227e | 32 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 33 | void Event_1Hz(void)// событие раз в 1 Гц |
Kovalev_D | 92:c892f0311aa7 | 34 | { int i,t; |
Kovalev_D | 115:e5a230e5af52 | 35 | |
Kovalev_D | 115:e5a230e5af52 | 36 | if (Event1Hz) |
Kovalev_D | 124:9ae09249f842 | 37 | { |
Kovalev_D | 124:9ae09249f842 | 38 | Gyro.Rate1_Event = 1; |
Kovalev_D | 122:fbacb932a30b | 39 | Event1Hz--; |
Kovalev_D | 122:fbacb932a30b | 40 | Time1Hz++; |
Kovalev_D | 117:eefe61968528 | 41 | Discharg (); |
Kovalev_D | 117:eefe61968528 | 42 | BackLight (); |
Kovalev_D | 124:9ae09249f842 | 43 | |
Kovalev_D | 88:b5c1d9d338d1 | 44 | } |
Kovalev_D | 88:b5c1d9d338d1 | 45 | } |
Kovalev_D | 89:a0d344db227e | 46 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 47 | ///////////////////// 1kHz ////////////////////////// |
Kovalev_D | 89:a0d344db227e | 48 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 49 | void Event_1KHz(void)// событие раз в 1 кГц |
Kovalev_D | 88:b5c1d9d338d1 | 50 | { |
Kovalev_D | 116:66f1f0ff2dab | 51 | if (Event1K) |
Kovalev_D | 116:66f1f0ff2dab | 52 | { |
Kovalev_D | 88:b5c1d9d338d1 | 53 | Event1K --; |
Kovalev_D | 116:66f1f0ff2dab | 54 | Time1K++;//первый ++ работает каждые 125 (event100kHz)второй был в 100 кГц |
Kovalev_D | 162:44e4ded32c6a | 55 | |
Kovalev_D | 150:29c9f7671bac | 56 | //LoopOn |
Kovalev_D | 116:66f1f0ff2dab | 57 | if (Time1K == 1000) |
Kovalev_D | 115:e5a230e5af52 | 58 | { |
Kovalev_D | 88:b5c1d9d338d1 | 59 | Time1K = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 60 | Event1Hz ++; |
Kovalev_D | 124:9ae09249f842 | 61 | |
Kovalev_D | 88:b5c1d9d338d1 | 62 | } |
Kovalev_D | 162:44e4ded32c6a | 63 | // LoopOff |
Kovalev_D | 106:250ddd8629c6 | 64 | |
Kovalev_D | 88:b5c1d9d338d1 | 65 | } |
Kovalev_D | 88:b5c1d9d338d1 | 66 | } |
Kovalev_D | 124:9ae09249f842 | 67 | void Event_500Hz(void)// событие раз в 500 Гц |
Kovalev_D | 124:9ae09249f842 | 68 | { |
Kovalev_D | 124:9ae09249f842 | 69 | if(Event500Hz) |
Kovalev_D | 124:9ae09249f842 | 70 | { // if(loop=0)BackLightON |
Kovalev_D | 124:9ae09249f842 | 71 | // else {BackLightOFF loop=1;} |
Kovalev_D | 162:44e4ded32c6a | 72 | //BackLightON |
Kovalev_D | 124:9ae09249f842 | 73 | Event500Hz--; |
Kovalev_D | 124:9ae09249f842 | 74 | Gyro.Delta500_Event=1; |
Kovalev_D | 143:2b15794a6cd2 | 75 | Gyro.Event_500Hz=1;// Event 500Гц выдачи данных для постройки графика управления вибро |
Kovalev_D | 162:44e4ded32c6a | 76 | //BackLightOFF |
Kovalev_D | 124:9ae09249f842 | 77 | } |
Kovalev_D | 124:9ae09249f842 | 78 | } |
Kovalev_D | 89:a0d344db227e | 79 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 80 | ///////////////////// 100kHz ////////////////////////// |
Kovalev_D | 89:a0d344db227e | 81 | ///////////////////////////////////////////////////// |
Kovalev_D | 116:66f1f0ff2dab | 82 | void Event_100KHz(void)// событие раз в 100 кГц(каждые 5-6 фронтов шум) |
Kovalev_D | 88:b5c1d9d338d1 | 83 | { |
Kovalev_D | 162:44e4ded32c6a | 84 | |
Kovalev_D | 88:b5c1d9d338d1 | 85 | if (Event100K) { |
Kovalev_D | 88:b5c1d9d338d1 | 86 | Event100K --; |
Kovalev_D | 124:9ae09249f842 | 87 | //BackLightON |
Kovalev_D | 162:44e4ded32c6a | 88 | Time500Hz++; |
Kovalev_D | 116:66f1f0ff2dab | 89 | |
Kovalev_D | 124:9ae09249f842 | 90 | if (OutBufCon1Count)OutBufCon1Count--; // обратный отсчет для управления ногой и формирование задержки на выдачу |
Kovalev_D | 124:9ae09249f842 | 91 | |
Kovalev_D | 124:9ae09249f842 | 92 | PinCheng(); // чтение регистра состояния выводов(вибро, полсветка, поджиг, LED) и управление выводами. |
Kovalev_D | 116:66f1f0ff2dab | 93 | |
Kovalev_D | 116:66f1f0ff2dab | 94 | Time100K++; |
Kovalev_D | 124:9ae09249f842 | 95 | if (Time100K == 100) |
Kovalev_D | 124:9ae09249f842 | 96 | { |
Kovalev_D | 88:b5c1d9d338d1 | 97 | Time100K = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 98 | Event1K ++; |
Kovalev_D | 124:9ae09249f842 | 99 | } |
Kovalev_D | 162:44e4ded32c6a | 100 | if (Time500Hz > 200) |
Kovalev_D | 162:44e4ded32c6a | 101 | { |
Kovalev_D | 164:6f43f85fdd8d | 102 | // LoopOn |
Kovalev_D | 165:b2bd0c810a4f | 103 | //Gyro.ModeOut=3; |
Kovalev_D | 162:44e4ded32c6a | 104 | Time500Hz -= 200; |
Kovalev_D | 162:44e4ded32c6a | 105 | Event500Hz ++; |
Kovalev_D | 165:b2bd0c810a4f | 106 | |
Kovalev_D | 164:6f43f85fdd8d | 107 | // LoopOff |
Kovalev_D | 162:44e4ded32c6a | 108 | } |
Kovalev_D | 124:9ae09249f842 | 109 | //BackLightOFF |
Kovalev_D | 162:44e4ded32c6a | 110 | |
Kovalev_D | 88:b5c1d9d338d1 | 111 | } |
Kovalev_D | 88:b5c1d9d338d1 | 112 | } |
Kovalev_D | 89:a0d344db227e | 113 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 114 | //////////////////vibro EVENT//////////////////////// |
Kovalev_D | 89:a0d344db227e | 115 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 116 | void Event_Vibro(void)// событие от вибр |
Kovalev_D | 88:b5c1d9d338d1 | 117 | { |
Kovalev_D | 88:b5c1d9d338d1 | 118 | if (EventVibro) { |
Kovalev_D | 88:b5c1d9d338d1 | 119 | EventVibro --; |
Kovalev_D | 88:b5c1d9d338d1 | 120 | } |
Kovalev_D | 88:b5c1d9d338d1 | 121 | } |
Kovalev_D | 89:a0d344db227e | 122 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 123 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 124 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 125 | |
Kovalev_D | 88:b5c1d9d338d1 | 126 | |
Kovalev_D | 112:4a96133a1311 | 127 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 128 | ////////////////////////////////////////////////////////TIMER1//////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 129 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 130 | |
Kovalev_D | 112:4a96133a1311 | 131 | ////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 132 | /////////////////////инициализация таймера 1 ///////////////////////// |
Kovalev_D | 112:4a96133a1311 | 133 | ////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 134 | |
Kovalev_D | 112:4a96133a1311 | 135 | unsigned int Init_TIM1 (unsigned int TimerInterval ) |
Kovalev_D | 112:4a96133a1311 | 136 | { |
Kovalev_D | 112:4a96133a1311 | 137 | LPC_TIM1->MR0 = TimerInterval; |
Kovalev_D | 112:4a96133a1311 | 138 | LPC_TIM1->MCR = 3; /* Interrupt and Reset on MR1 */ |
Kovalev_D | 112:4a96133a1311 | 139 | NVIC_EnableIRQ(TIMER1_IRQn); |
Kovalev_D | 134:caf4c9cd5052 | 140 | // NVIC_DisableIRQ(TIMER1_IRQn); |
Kovalev_D | 112:4a96133a1311 | 141 | } |
Kovalev_D | 112:4a96133a1311 | 142 | |
Kovalev_D | 112:4a96133a1311 | 143 | |
igor_v | 0:8ad47e2b6f00 | 144 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 145 | /////////////////////////включение таймера 1////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 146 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 147 | void enable_timer1( void ) |
igor_v | 21:bc8c1cec3da6 | 148 | { |
igor_v | 21:bc8c1cec3da6 | 149 | LPC_TIM1->TCR = 1; |
igor_v | 21:bc8c1cec3da6 | 150 | return; |
igor_v | 21:bc8c1cec3da6 | 151 | } |
igor_v | 0:8ad47e2b6f00 | 152 | |
igor_v | 0:8ad47e2b6f00 | 153 | |
igor_v | 0:8ad47e2b6f00 | 154 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 155 | /////////////////////////////////////////////////TIMER2////////////////////////////////////////////////////////////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 156 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 157 | |
igor_v | 0:8ad47e2b6f00 | 158 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 159 | /////////////////////инициализация таймера 2 ///////////////////////// |
igor_v | 0:8ad47e2b6f00 | 160 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 161 | unsigned int Init_TIM2 (void) |
igor_v | 21:bc8c1cec3da6 | 162 | { |
Kovalev_D | 124:9ae09249f842 | 163 | LPC_TIM2->MR0 = 257; |
igor_v | 21:bc8c1cec3da6 | 164 | LPC_TIM2->MCR = 3; /* Interrupt and Reset on MR0 */ |
igor_v | 21:bc8c1cec3da6 | 165 | NVIC_EnableIRQ(TIMER2_IRQn); |
Kovalev_D | 134:caf4c9cd5052 | 166 | // NVIC_DisableIRQ(TIMER2_IRQn); |
igor_v | 21:bc8c1cec3da6 | 167 | return 1; |
igor_v | 21:bc8c1cec3da6 | 168 | } |
igor_v | 0:8ad47e2b6f00 | 169 | |
igor_v | 15:f5191a1c3805 | 170 | |
igor_v | 15:f5191a1c3805 | 171 | |
igor_v | 21:bc8c1cec3da6 | 172 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 173 | /////////////////////////включение таймера 2////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 174 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 175 | void enable_timer2(void) |
igor_v | 21:bc8c1cec3da6 | 176 | { |
Kovalev_D | 164:6f43f85fdd8d | 177 | |
igor_v | 21:bc8c1cec3da6 | 178 | LPC_TIM2->TCR = 1; |
igor_v | 21:bc8c1cec3da6 | 179 | LPC_TIM2->TCR = 0x01; |
Kovalev_D | 164:6f43f85fdd8d | 180 | |
igor_v | 21:bc8c1cec3da6 | 181 | } |
igor_v | 21:bc8c1cec3da6 | 182 | |
igor_v | 21:bc8c1cec3da6 | 183 | |
Kovalev_D | 112:4a96133a1311 | 184 | ////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 185 | /////////////////////////прерывание таймера 1////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 186 | ////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 187 | __irq void TIMER1_IRQHandler (void) |
Kovalev_D | 112:4a96133a1311 | 188 | { |
igor_v | 114:5cc38a53d8a7 | 189 | ResetCS(ADC); //prepare ADC for sampling |
Kovalev_D | 112:4a96133a1311 | 190 | SetDAC(DAC); |
Kovalev_D | 112:4a96133a1311 | 191 | |
igor_v | 114:5cc38a53d8a7 | 192 | CountV255++; // инкремент счеттчика |
Kovalev_D | 164:6f43f85fdd8d | 193 | CountV255 &= 0xff; // ОБРЕЗАНИЕ СЧЕТЧИКА |
igor_v | 114:5cc38a53d8a7 | 194 | CountV31 =CountV255 & 0x1f; // малый счетчик |
Kovalev_D | 121:bbae560cdd43 | 195 | |
Kovalev_D | 112:4a96133a1311 | 196 | D_QEI(); //чтение данных по счетчику |
Kovalev_D | 143:2b15794a6cd2 | 197 | cheng(); // выставление флагов в 32 тактном цикле. |
Kovalev_D | 116:66f1f0ff2dab | 198 | |
Kovalev_D | 116:66f1f0ff2dab | 199 | |
Kovalev_D | 116:66f1f0ff2dab | 200 | SetCS(ADC); //start ADC sampling |
Kovalev_D | 116:66f1f0ff2dab | 201 | ResetDAC(DAC); |
igor_v | 114:5cc38a53d8a7 | 202 | SPI_Exchange(); //Чтение ADS_SPI |
igor_v | 114:5cc38a53d8a7 | 203 | |
Kovalev_D | 112:4a96133a1311 | 204 | LPC_TIM1->IR = 1; |
Kovalev_D | 112:4a96133a1311 | 205 | } |
Kovalev_D | 112:4a96133a1311 | 206 | |
Kovalev_D | 112:4a96133a1311 | 207 | |
Kovalev_D | 112:4a96133a1311 | 208 | |
Kovalev_D | 112:4a96133a1311 | 209 | |
Kovalev_D | 112:4a96133a1311 | 210 | |
Kovalev_D | 112:4a96133a1311 | 211 | |
igor_v | 21:bc8c1cec3da6 | 212 | /////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 213 | /////////////////////////прерывание таймера 2////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 214 | /////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 215 | __irq void TIMER2_IRQHandler (void) |
Kovalev_D | 169:140743e3bb96 | 216 | { |
Kovalev_D | 181:0b022246c43c | 217 | LoopOn |
igor_v | 21:bc8c1cec3da6 | 218 | LPC_TIM2->IR = 1; |
igor_v | 21:bc8c1cec3da6 | 219 | |
igor_v | 21:bc8c1cec3da6 | 220 | Global_Time++; |
igor_v | 21:bc8c1cec3da6 | 221 | |
Kovalev_D | 181:0b022246c43c | 222 | if(Time_UART) Time_UART--; |
igor_v | 21:bc8c1cec3da6 | 223 | |
igor_v | 21:bc8c1cec3da6 | 224 | Time_vibro++; |
Kovalev_D | 121:bbae560cdd43 | 225 | |
Kovalev_D | 112:4a96133a1311 | 226 | Gyro.VibroOutF=1; |
Kovalev_D | 112:4a96133a1311 | 227 | |
Kovalev_D | 116:66f1f0ff2dab | 228 | Event100K ++; |
Kovalev_D | 181:0b022246c43c | 229 | LoopOff |
igor_v | 21:bc8c1cec3da6 | 230 | } |