![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
fork
Fork of LG by
MTimer.c@134:caf4c9cd5052, 2016-04-14 (annotated)
- Committer:
- Kovalev_D
- Date:
- Thu Apr 14 14:13:18 2016 +0000
- Revision:
- 134:caf4c9cd5052
- Parent:
- 124:9ae09249f842
- Child:
- 143:2b15794a6cd2
kjhg
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 | 124:9ae09249f842 | 55 | Time500Hz++; |
Kovalev_D | 124:9ae09249f842 | 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 | 124:9ae09249f842 | 63 | if (Time500Hz == 2) |
Kovalev_D | 124:9ae09249f842 | 64 | { |
Kovalev_D | 124:9ae09249f842 | 65 | Time500Hz = 0; |
Kovalev_D | 124:9ae09249f842 | 66 | Event500Hz ++; |
Kovalev_D | 124:9ae09249f842 | 67 | } |
Kovalev_D | 124:9ae09249f842 | 68 | LoopOff |
Kovalev_D | 106:250ddd8629c6 | 69 | |
Kovalev_D | 88:b5c1d9d338d1 | 70 | } |
Kovalev_D | 88:b5c1d9d338d1 | 71 | } |
Kovalev_D | 124:9ae09249f842 | 72 | void Event_500Hz(void)// событие раз в 500 Гц |
Kovalev_D | 124:9ae09249f842 | 73 | { |
Kovalev_D | 124:9ae09249f842 | 74 | if(Event500Hz) |
Kovalev_D | 124:9ae09249f842 | 75 | { // if(loop=0)BackLightON |
Kovalev_D | 124:9ae09249f842 | 76 | // else {BackLightOFF loop=1;} |
Kovalev_D | 124:9ae09249f842 | 77 | BackLightON |
Kovalev_D | 124:9ae09249f842 | 78 | Event500Hz--; |
Kovalev_D | 124:9ae09249f842 | 79 | Gyro.Delta500_Event=1; |
Kovalev_D | 124:9ae09249f842 | 80 | BackLightOFF |
Kovalev_D | 124:9ae09249f842 | 81 | |
Kovalev_D | 124:9ae09249f842 | 82 | } |
Kovalev_D | 124:9ae09249f842 | 83 | } |
Kovalev_D | 89:a0d344db227e | 84 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 85 | ///////////////////// 100kHz ////////////////////////// |
Kovalev_D | 89:a0d344db227e | 86 | ///////////////////////////////////////////////////// |
Kovalev_D | 116:66f1f0ff2dab | 87 | void Event_100KHz(void)// событие раз в 100 кГц(каждые 5-6 фронтов шум) |
Kovalev_D | 88:b5c1d9d338d1 | 88 | { |
Kovalev_D | 88:b5c1d9d338d1 | 89 | if (Event100K) { |
Kovalev_D | 88:b5c1d9d338d1 | 90 | Event100K --; |
Kovalev_D | 124:9ae09249f842 | 91 | //BackLightON |
Kovalev_D | 116:66f1f0ff2dab | 92 | |
Kovalev_D | 124:9ae09249f842 | 93 | if (OutBufCon1Count)OutBufCon1Count--; // обратный отсчет для управления ногой и формирование задержки на выдачу |
Kovalev_D | 124:9ae09249f842 | 94 | |
Kovalev_D | 124:9ae09249f842 | 95 | PinCheng(); // чтение регистра состояния выводов(вибро, полсветка, поджиг, LED) и управление выводами. |
Kovalev_D | 116:66f1f0ff2dab | 96 | |
Kovalev_D | 116:66f1f0ff2dab | 97 | Time100K++; |
Kovalev_D | 124:9ae09249f842 | 98 | if (Time100K == 100) |
Kovalev_D | 124:9ae09249f842 | 99 | { |
Kovalev_D | 88:b5c1d9d338d1 | 100 | Time100K = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 101 | Event1K ++; |
Kovalev_D | 124:9ae09249f842 | 102 | } |
Kovalev_D | 124:9ae09249f842 | 103 | //BackLightOFF |
Kovalev_D | 88:b5c1d9d338d1 | 104 | } |
Kovalev_D | 88:b5c1d9d338d1 | 105 | } |
Kovalev_D | 89:a0d344db227e | 106 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 107 | //////////////////vibro EVENT//////////////////////// |
Kovalev_D | 89:a0d344db227e | 108 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 109 | void Event_Vibro(void)// событие от вибр |
Kovalev_D | 88:b5c1d9d338d1 | 110 | { |
Kovalev_D | 88:b5c1d9d338d1 | 111 | if (EventVibro) { |
Kovalev_D | 88:b5c1d9d338d1 | 112 | EventVibro --; |
Kovalev_D | 88:b5c1d9d338d1 | 113 | } |
Kovalev_D | 88:b5c1d9d338d1 | 114 | } |
Kovalev_D | 89:a0d344db227e | 115 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 116 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 117 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 118 | |
Kovalev_D | 88:b5c1d9d338d1 | 119 | |
Kovalev_D | 112:4a96133a1311 | 120 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 121 | ////////////////////////////////////////////////////////TIMER1//////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 122 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 123 | |
Kovalev_D | 112:4a96133a1311 | 124 | ////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 125 | /////////////////////инициализация таймера 1 ///////////////////////// |
Kovalev_D | 112:4a96133a1311 | 126 | ////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 127 | |
Kovalev_D | 112:4a96133a1311 | 128 | unsigned int Init_TIM1 (unsigned int TimerInterval ) |
Kovalev_D | 112:4a96133a1311 | 129 | { |
Kovalev_D | 112:4a96133a1311 | 130 | LPC_TIM1->MR0 = TimerInterval; |
Kovalev_D | 112:4a96133a1311 | 131 | LPC_TIM1->MCR = 3; /* Interrupt and Reset on MR1 */ |
Kovalev_D | 112:4a96133a1311 | 132 | NVIC_EnableIRQ(TIMER1_IRQn); |
Kovalev_D | 134:caf4c9cd5052 | 133 | // NVIC_DisableIRQ(TIMER1_IRQn); |
Kovalev_D | 112:4a96133a1311 | 134 | } |
Kovalev_D | 112:4a96133a1311 | 135 | |
Kovalev_D | 112:4a96133a1311 | 136 | |
igor_v | 0:8ad47e2b6f00 | 137 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 138 | /////////////////////////включение таймера 1////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 139 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 140 | void enable_timer1( void ) |
igor_v | 21:bc8c1cec3da6 | 141 | { |
igor_v | 21:bc8c1cec3da6 | 142 | LPC_TIM1->TCR = 1; |
igor_v | 21:bc8c1cec3da6 | 143 | return; |
igor_v | 21:bc8c1cec3da6 | 144 | } |
igor_v | 0:8ad47e2b6f00 | 145 | |
igor_v | 0:8ad47e2b6f00 | 146 | |
igor_v | 0:8ad47e2b6f00 | 147 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 148 | /////////////////////////////////////////////////TIMER2////////////////////////////////////////////////////////////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 149 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 150 | |
igor_v | 0:8ad47e2b6f00 | 151 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 152 | /////////////////////инициализация таймера 2 ///////////////////////// |
igor_v | 0:8ad47e2b6f00 | 153 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 154 | unsigned int Init_TIM2 (void) |
igor_v | 21:bc8c1cec3da6 | 155 | { |
Kovalev_D | 124:9ae09249f842 | 156 | LPC_TIM2->MR0 = 257; |
igor_v | 21:bc8c1cec3da6 | 157 | LPC_TIM2->MCR = 3; /* Interrupt and Reset on MR0 */ |
igor_v | 21:bc8c1cec3da6 | 158 | NVIC_EnableIRQ(TIMER2_IRQn); |
Kovalev_D | 134:caf4c9cd5052 | 159 | // NVIC_DisableIRQ(TIMER2_IRQn); |
igor_v | 21:bc8c1cec3da6 | 160 | return 1; |
igor_v | 21:bc8c1cec3da6 | 161 | } |
igor_v | 0:8ad47e2b6f00 | 162 | |
igor_v | 15:f5191a1c3805 | 163 | |
igor_v | 15:f5191a1c3805 | 164 | |
igor_v | 21:bc8c1cec3da6 | 165 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 166 | /////////////////////////включение таймера 2////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 167 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 168 | void enable_timer2(void) |
igor_v | 21:bc8c1cec3da6 | 169 | { |
igor_v | 21:bc8c1cec3da6 | 170 | LPC_TIM2->TCR = 1; |
igor_v | 21:bc8c1cec3da6 | 171 | LPC_TIM2->TCR = 0x01; |
igor_v | 21:bc8c1cec3da6 | 172 | } |
igor_v | 21:bc8c1cec3da6 | 173 | |
igor_v | 21:bc8c1cec3da6 | 174 | |
Kovalev_D | 112:4a96133a1311 | 175 | ////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 176 | /////////////////////////прерывание таймера 1////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 177 | ////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 178 | __irq void TIMER1_IRQHandler (void) |
Kovalev_D | 112:4a96133a1311 | 179 | { |
Kovalev_D | 117:eefe61968528 | 180 | |
Kovalev_D | 117:eefe61968528 | 181 | |
igor_v | 114:5cc38a53d8a7 | 182 | ResetCS(ADC); //prepare ADC for sampling |
Kovalev_D | 112:4a96133a1311 | 183 | SetDAC(DAC); |
Kovalev_D | 112:4a96133a1311 | 184 | |
igor_v | 114:5cc38a53d8a7 | 185 | CountV255++; // инкремент счеттчика |
igor_v | 114:5cc38a53d8a7 | 186 | CountV255 &= 0xff; // ОБРЕЗАНИЕ СЧЕТЧИКА ой |
igor_v | 114:5cc38a53d8a7 | 187 | CountV31 =CountV255 & 0x1f; // малый счетчик |
Kovalev_D | 121:bbae560cdd43 | 188 | |
Kovalev_D | 121:bbae560cdd43 | 189 | //if(CountV31==0) { BackLightON } |
Kovalev_D | 112:4a96133a1311 | 190 | |
Kovalev_D | 112:4a96133a1311 | 191 | D_QEI(); //чтение данных по счетчику |
Kovalev_D | 112:4a96133a1311 | 192 | cheng(); // расчет вибропривода |
Kovalev_D | 116:66f1f0ff2dab | 193 | |
Kovalev_D | 116:66f1f0ff2dab | 194 | |
Kovalev_D | 116:66f1f0ff2dab | 195 | SetCS(ADC); //start ADC sampling |
Kovalev_D | 116:66f1f0ff2dab | 196 | ResetDAC(DAC); |
igor_v | 114:5cc38a53d8a7 | 197 | SPI_Exchange(); //Чтение ADS_SPI |
igor_v | 114:5cc38a53d8a7 | 198 | |
Kovalev_D | 112:4a96133a1311 | 199 | LPC_TIM1->IR = 1; |
Kovalev_D | 121:bbae560cdd43 | 200 | //BackLightOFF |
Kovalev_D | 112:4a96133a1311 | 201 | } |
Kovalev_D | 112:4a96133a1311 | 202 | |
Kovalev_D | 112:4a96133a1311 | 203 | |
Kovalev_D | 112:4a96133a1311 | 204 | |
Kovalev_D | 112:4a96133a1311 | 205 | |
Kovalev_D | 112:4a96133a1311 | 206 | |
Kovalev_D | 112:4a96133a1311 | 207 | |
igor_v | 21:bc8c1cec3da6 | 208 | /////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 209 | /////////////////////////прерывание таймера 2////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 210 | /////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 211 | __irq void TIMER2_IRQHandler (void) |
igor_v | 21:bc8c1cec3da6 | 212 | { |
igor_v | 21:bc8c1cec3da6 | 213 | LPC_TIM2->IR = 1; |
igor_v | 21:bc8c1cec3da6 | 214 | |
Kovalev_D | 124:9ae09249f842 | 215 | |
igor_v | 21:bc8c1cec3da6 | 216 | Global_Time++; |
igor_v | 21:bc8c1cec3da6 | 217 | |
igor_v | 21:bc8c1cec3da6 | 218 | Time_UART++; |
igor_v | 21:bc8c1cec3da6 | 219 | |
igor_v | 21:bc8c1cec3da6 | 220 | Time_vibro++; |
Kovalev_D | 121:bbae560cdd43 | 221 | |
Kovalev_D | 112:4a96133a1311 | 222 | Gyro.VibroOutF=1; |
Kovalev_D | 112:4a96133a1311 | 223 | |
Kovalev_D | 116:66f1f0ff2dab | 224 | Event100K ++; |
Kovalev_D | 124:9ae09249f842 | 225 | |
igor_v | 21:bc8c1cec3da6 | 226 | } |