![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
forkd
Fork of LGstaandart by
MTimer.c@220:04c54405b82d, 2017-10-20 (annotated)
- Committer:
- Kovalev_D
- Date:
- Fri Oct 20 13:16:32 2017 +0000
- Revision:
- 220:04c54405b82d
- Parent:
- 218:b4067cac75c0
- Child:
- 222:7de7b3bf3a1d
ddd
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 | |
Kovalev_D | 197:7a05523bf588 | 10 | unsigned int CountV64=0; |
igor_v | 0:8ad47e2b6f00 | 11 | unsigned int CountV31=0; |
Kovalev_D | 197:7a05523bf588 | 12 | unsigned int CountV255=0; |
Kovalev_D | 215:b58b887fd367 | 13 | unsigned int CountV511=0; |
Kovalev_D | 209:224e7331a061 | 14 | unsigned int f,MODCount=0; |
Kovalev_D | 124:9ae09249f842 | 15 | int loop=0; |
Kovalev_D | 208:19150d2b528f | 16 | int t; |
Kovalev_D | 88:b5c1d9d338d1 | 17 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 18 | /////////////////////EVENT/////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 19 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 20 | ///////////////////////////////////////////////////// |
Kovalev_D | 214:4c70e452c491 | 21 | ///////////////////// 1250Hz /////////////////////////// |
Kovalev_D | 214:4c70e452c491 | 22 | ///////////////////////////////////////////////////// |
Kovalev_D | 214:4c70e452c491 | 23 | void Event_1250Hz(void)// событие раз в 1,25 КГц |
Kovalev_D | 214:4c70e452c491 | 24 | { |
Kovalev_D | 214:4c70e452c491 | 25 | if(Event1250Hz) |
Kovalev_D | 214:4c70e452c491 | 26 | { |
Kovalev_D | 214:4c70e452c491 | 27 | Gyro.EvenRate7=1; |
Kovalev_D | 215:b58b887fd367 | 28 | |
Kovalev_D | 214:4c70e452c491 | 29 | Event1250Hz--; |
Kovalev_D | 215:b58b887fd367 | 30 | |
Kovalev_D | 214:4c70e452c491 | 31 | } |
Kovalev_D | 214:4c70e452c491 | 32 | } |
Kovalev_D | 214:4c70e452c491 | 33 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 34 | ///////////////////// 1Hz /////////////////////////// |
Kovalev_D | 89:a0d344db227e | 35 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 36 | void Event_1Hz(void)// событие раз в 1 Гц |
Kovalev_D | 214:4c70e452c491 | 37 | { static int tempdac=0,tempdac1; |
Kovalev_D | 115:e5a230e5af52 | 38 | if (Event1Hz) |
Kovalev_D | 220:04c54405b82d | 39 | { /*sprintf((Time),"%d %d %d\r\n",Spi.DAC_B,AMPSUM_DESP,Spi.DAC_A); |
Kovalev_D | 220:04c54405b82d | 40 | WriteCon(Time);*/ |
Kovalev_D | 220:04c54405b82d | 41 | if(Gyro.ShowMod2) |
Kovalev_D | 220:04c54405b82d | 42 | { |
Kovalev_D | 220:04c54405b82d | 43 | sprintf((Time),"%d %d %d\r\n",Spi.DAC_B,AMPSUM_DESP,Spi.DAC_A); |
Kovalev_D | 220:04c54405b82d | 44 | WriteCon(Time); |
Kovalev_D | 220:04c54405b82d | 45 | Spi.DAC_B+=200; |
Kovalev_D | 220:04c54405b82d | 46 | } |
Kovalev_D | 208:19150d2b528f | 47 | Discharg(); |
Kovalev_D | 208:19150d2b528f | 48 | BackLight(); |
Kovalev_D | 208:19150d2b528f | 49 | Gyro.Rate1_Event = 1; |
Kovalev_D | 208:19150d2b528f | 50 | Event1Hz--; |
Kovalev_D | 208:19150d2b528f | 51 | Time1Hz++; |
Kovalev_D | 214:4c70e452c491 | 52 | // sprintf((Time),"%d \r\n",Gyro.ModeOut ); |
Kovalev_D | 214:4c70e452c491 | 53 | // WriteCon(Time); |
Kovalev_D | 214:4c70e452c491 | 54 | |
Kovalev_D | 214:4c70e452c491 | 55 | } |
Kovalev_D | 88:b5c1d9d338d1 | 56 | } |
Kovalev_D | 89:a0d344db227e | 57 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 58 | ///////////////////// 1kHz ////////////////////////// |
Kovalev_D | 197:7a05523bf588 | 59 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 60 | void Event_1KHz(void)// событие раз в 1 кГц |
Kovalev_D | 214:4c70e452c491 | 61 | { if (Event1K) |
Kovalev_D | 116:66f1f0ff2dab | 62 | { |
Kovalev_D | 214:4c70e452c491 | 63 | if(Gyro.PLCDelay) Gyro.PLCDelay--; |
Kovalev_D | 88:b5c1d9d338d1 | 64 | Event1K --; |
Kovalev_D | 215:b58b887fd367 | 65 | |
Kovalev_D | 116:66f1f0ff2dab | 66 | Time1K++;//первый ++ работает каждые 125 (event100kHz)второй был в 100 кГц |
Kovalev_D | 209:224e7331a061 | 67 | if (Time1K > 1000) |
Kovalev_D | 115:e5a230e5af52 | 68 | { |
Kovalev_D | 208:19150d2b528f | 69 | Time1K -=1000; |
Kovalev_D | 88:b5c1d9d338d1 | 70 | Event1Hz ++; |
Kovalev_D | 88:b5c1d9d338d1 | 71 | } |
Kovalev_D | 209:224e7331a061 | 72 | |
Kovalev_D | 214:4c70e452c491 | 73 | } |
Kovalev_D | 88:b5c1d9d338d1 | 74 | } |
Kovalev_D | 209:224e7331a061 | 75 | |
Kovalev_D | 209:224e7331a061 | 76 | void Event_2KHz(void)// событие раз в 1 кГц |
Kovalev_D | 218:b4067cac75c0 | 77 | { |
Kovalev_D | 218:b4067cac75c0 | 78 | int temp=0; |
Kovalev_D | 214:4c70e452c491 | 79 | |
Kovalev_D | 209:224e7331a061 | 80 | if (Event2K) |
Kovalev_D | 218:b4067cac75c0 | 81 | { |
Kovalev_D | 209:224e7331a061 | 82 | Event2K --; |
Kovalev_D | 209:224e7331a061 | 83 | } |
Kovalev_D | 209:224e7331a061 | 84 | } |
Kovalev_D | 124:9ae09249f842 | 85 | void Event_500Hz(void)// событие раз в 500 Гц |
Kovalev_D | 124:9ae09249f842 | 86 | { |
Kovalev_D | 124:9ae09249f842 | 87 | if(Event500Hz) |
Kovalev_D | 211:ac8251b067d2 | 88 | { |
Kovalev_D | 205:775d54fdf646 | 89 | Event500Hz--; |
Kovalev_D | 208:19150d2b528f | 90 | Gyro.Event_500Hz=1;// Event 500Гц выдачи данных для постройки графика управления вибро |
Kovalev_D | 197:7a05523bf588 | 91 | } |
Kovalev_D | 197:7a05523bf588 | 92 | } |
Kovalev_D | 209:224e7331a061 | 93 | void Event_250Hz(void) |
Kovalev_D | 209:224e7331a061 | 94 | { |
Kovalev_D | 209:224e7331a061 | 95 | if(Event250Hz) |
Kovalev_D | 209:224e7331a061 | 96 | { |
Kovalev_D | 218:b4067cac75c0 | 97 | |
Kovalev_D | 209:224e7331a061 | 98 | // Gyro.CuruAngle=0; |
Kovalev_D | 209:224e7331a061 | 99 | Event250Hz--; |
Kovalev_D | 209:224e7331a061 | 100 | MODCount++; |
Kovalev_D | 209:224e7331a061 | 101 | } |
Kovalev_D | 209:224e7331a061 | 102 | } |
Kovalev_D | 89:a0d344db227e | 103 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 104 | ///////////////////// 100kHz ////////////////////////// |
Kovalev_D | 89:a0d344db227e | 105 | ///////////////////////////////////////////////////// |
Kovalev_D | 193:a0fe8bfc97e4 | 106 | void Event_100KHz(void)// событие раз в 100 кГц |
Kovalev_D | 88:b5c1d9d338d1 | 107 | { |
Kovalev_D | 162:44e4ded32c6a | 108 | |
Kovalev_D | 88:b5c1d9d338d1 | 109 | if (Event100K) { |
Kovalev_D | 197:7a05523bf588 | 110 | |
Kovalev_D | 88:b5c1d9d338d1 | 111 | Event100K --; |
Kovalev_D | 197:7a05523bf588 | 112 | |
Kovalev_D | 124:9ae09249f842 | 113 | if (OutBufCon1Count)OutBufCon1Count--; // обратный отсчет для управления ногой и формирование задержки на выдачу |
Kovalev_D | 124:9ae09249f842 | 114 | |
Kovalev_D | 124:9ae09249f842 | 115 | PinCheng(); // чтение регистра состояния выводов(вибро, полсветка, поджиг, LED) и управление выводами. |
Kovalev_D | 88:b5c1d9d338d1 | 116 | } |
Kovalev_D | 88:b5c1d9d338d1 | 117 | } |
Kovalev_D | 89:a0d344db227e | 118 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 119 | //////////////////vibro EVENT//////////////////////// |
Kovalev_D | 89:a0d344db227e | 120 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 121 | void Event_Vibro(void)// событие от вибр |
Kovalev_D | 88:b5c1d9d338d1 | 122 | { |
Kovalev_D | 88:b5c1d9d338d1 | 123 | if (EventVibro) { |
Kovalev_D | 88:b5c1d9d338d1 | 124 | EventVibro --; |
Kovalev_D | 88:b5c1d9d338d1 | 125 | } |
Kovalev_D | 88:b5c1d9d338d1 | 126 | } |
Kovalev_D | 89:a0d344db227e | 127 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 128 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 129 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 130 | |
Kovalev_D | 88:b5c1d9d338d1 | 131 | |
Kovalev_D | 112:4a96133a1311 | 132 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 133 | ////////////////////////////////////////////////////////TIMER1//////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 134 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 135 | |
Kovalev_D | 112:4a96133a1311 | 136 | ////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 137 | /////////////////////инициализация таймера 1 ///////////////////////// |
Kovalev_D | 112:4a96133a1311 | 138 | ////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 139 | |
Kovalev_D | 112:4a96133a1311 | 140 | unsigned int Init_TIM1 (unsigned int TimerInterval ) |
Kovalev_D | 112:4a96133a1311 | 141 | { |
Kovalev_D | 214:4c70e452c491 | 142 | // LPC_SC->PCLKSEL0 |= (1<<4); |
Kovalev_D | 220:04c54405b82d | 143 | |
Kovalev_D | 112:4a96133a1311 | 144 | LPC_TIM1->MR0 = TimerInterval; |
Kovalev_D | 112:4a96133a1311 | 145 | LPC_TIM1->MCR = 3; /* Interrupt and Reset on MR1 */ |
Kovalev_D | 112:4a96133a1311 | 146 | NVIC_EnableIRQ(TIMER1_IRQn); |
Kovalev_D | 112:4a96133a1311 | 147 | } |
Kovalev_D | 112:4a96133a1311 | 148 | |
Kovalev_D | 112:4a96133a1311 | 149 | |
igor_v | 0:8ad47e2b6f00 | 150 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 151 | /////////////////////////включение таймера 1////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 152 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 153 | void enable_timer1( void ) |
igor_v | 21:bc8c1cec3da6 | 154 | { |
igor_v | 21:bc8c1cec3da6 | 155 | LPC_TIM1->TCR = 1; |
igor_v | 21:bc8c1cec3da6 | 156 | return; |
igor_v | 21:bc8c1cec3da6 | 157 | } |
igor_v | 0:8ad47e2b6f00 | 158 | |
igor_v | 0:8ad47e2b6f00 | 159 | |
igor_v | 0:8ad47e2b6f00 | 160 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 161 | /////////////////////////////////////////////////TIMER2////////////////////////////////////////////////////////////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 162 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 163 | |
igor_v | 0:8ad47e2b6f00 | 164 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 165 | /////////////////////инициализация таймера 2 ///////////////////////// |
igor_v | 0:8ad47e2b6f00 | 166 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 167 | unsigned int Init_TIM2 (void) |
igor_v | 21:bc8c1cec3da6 | 168 | { |
Kovalev_D | 124:9ae09249f842 | 169 | LPC_TIM2->MR0 = 257; |
igor_v | 21:bc8c1cec3da6 | 170 | LPC_TIM2->MCR = 3; /* Interrupt and Reset on MR0 */ |
igor_v | 21:bc8c1cec3da6 | 171 | NVIC_EnableIRQ(TIMER2_IRQn); |
igor_v | 21:bc8c1cec3da6 | 172 | return 1; |
igor_v | 21:bc8c1cec3da6 | 173 | } |
igor_v | 0:8ad47e2b6f00 | 174 | |
igor_v | 21:bc8c1cec3da6 | 175 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 176 | /////////////////////////включение таймера 2////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 177 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 178 | void enable_timer2(void) |
igor_v | 21:bc8c1cec3da6 | 179 | { |
igor_v | 21:bc8c1cec3da6 | 180 | LPC_TIM2->TCR = 1; |
igor_v | 21:bc8c1cec3da6 | 181 | LPC_TIM2->TCR = 0x01; |
igor_v | 21:bc8c1cec3da6 | 182 | } |
igor_v | 21:bc8c1cec3da6 | 183 | |
igor_v | 21:bc8c1cec3da6 | 184 | |
Kovalev_D | 112:4a96133a1311 | 185 | ////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 186 | /////////////////////////прерывание таймера 1////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 187 | ////////////////////////////////////////////////////////////////////// |
Kovalev_D | 215:b58b887fd367 | 188 | __irq void TIMER1_IRQHandler (void)//13.27 kHz(vibro*32) |
Kovalev_D | 205:775d54fdf646 | 189 | { |
Kovalev_D | 208:19150d2b528f | 190 | |
igor_v | 114:5cc38a53d8a7 | 191 | ResetCS(ADC); //prepare ADC for sampling |
Kovalev_D | 112:4a96133a1311 | 192 | SetDAC(DAC); |
Kovalev_D | 208:19150d2b528f | 193 | Global_Time++; |
igor_v | 114:5cc38a53d8a7 | 194 | CountV255++; // инкремент счеттчика |
Kovalev_D | 215:b58b887fd367 | 195 | CountV511++; |
Kovalev_D | 164:6f43f85fdd8d | 196 | CountV255 &= 0xff; // ОБРЕЗАНИЕ СЧЕТЧИКА |
Kovalev_D | 215:b58b887fd367 | 197 | CountV511 &= 0x1ff; |
Kovalev_D | 197:7a05523bf588 | 198 | CountV64 = CountV255 & 0x3f; |
Kovalev_D | 197:7a05523bf588 | 199 | CountV31 = CountV255 & 0x1f; // малый счетчик |
Kovalev_D | 197:7a05523bf588 | 200 | |
Kovalev_D | 112:4a96133a1311 | 201 | D_QEI(); //чтение данных по счетчику |
Kovalev_D | 143:2b15794a6cd2 | 202 | cheng(); // выставление флагов в 32 тактном цикле. |
Kovalev_D | 116:66f1f0ff2dab | 203 | |
Kovalev_D | 116:66f1f0ff2dab | 204 | |
Kovalev_D | 116:66f1f0ff2dab | 205 | SetCS(ADC); //start ADC sampling |
Kovalev_D | 116:66f1f0ff2dab | 206 | ResetDAC(DAC); |
Kovalev_D | 197:7a05523bf588 | 207 | SPI_Exchange(); //Чтение ADC_SPI |
igor_v | 114:5cc38a53d8a7 | 208 | |
Kovalev_D | 214:4c70e452c491 | 209 | LPC_TIM1->IR = 1; |
Kovalev_D | 208:19150d2b528f | 210 | |
Kovalev_D | 112:4a96133a1311 | 211 | } |
Kovalev_D | 112:4a96133a1311 | 212 | |
igor_v | 21:bc8c1cec3da6 | 213 | /////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 214 | /////////////////////////прерывание таймера 2////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 215 | /////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 216 | __irq void TIMER2_IRQHandler (void) |
Kovalev_D | 210:b02fa166315d | 217 | { |
Kovalev_D | 213:9953db9543d6 | 218 | /// LoopOn |
igor_v | 21:bc8c1cec3da6 | 219 | LPC_TIM2->IR = 1; |
Kovalev_D | 213:9953db9543d6 | 220 | if (Gyro.UARTFlag) |
Kovalev_D | 213:9953db9543d6 | 221 | { |
Kovalev_D | 213:9953db9543d6 | 222 | if(Time_UART) Time_UART--; |
Kovalev_D | 213:9953db9543d6 | 223 | } |
Kovalev_D | 214:4c70e452c491 | 224 | // |
Kovalev_D | 214:4c70e452c491 | 225 | |
igor_v | 21:bc8c1cec3da6 | 226 | Time_vibro++; |
Kovalev_D | 214:4c70e452c491 | 227 | // VibroOut(); |
Kovalev_D | 112:4a96133a1311 | 228 | Gyro.VibroOutF=1; |
Kovalev_D | 214:4c70e452c491 | 229 | Event100K ++; |
Kovalev_D | 214:4c70e452c491 | 230 | Time1250Hz++; |
Kovalev_D | 197:7a05523bf588 | 231 | Time500Hz++; |
Kovalev_D | 209:224e7331a061 | 232 | Time250Hz++; |
Kovalev_D | 197:7a05523bf588 | 233 | Time100K++; |
Kovalev_D | 209:224e7331a061 | 234 | Time2K++; |
Kovalev_D | 209:224e7331a061 | 235 | //Time2K++; |
Kovalev_D | 205:775d54fdf646 | 236 | // Time250Hz++; |
Kovalev_D | 214:4c70e452c491 | 237 | |
Kovalev_D | 214:4c70e452c491 | 238 | if (Time1250Hz > 79) |
Kovalev_D | 214:4c70e452c491 | 239 | { |
Kovalev_D | 214:4c70e452c491 | 240 | Time1250Hz -= 80; |
Kovalev_D | 214:4c70e452c491 | 241 | Event1250Hz ++; |
Kovalev_D | 214:4c70e452c491 | 242 | } |
Kovalev_D | 197:7a05523bf588 | 243 | if (Time100K == 100) |
Kovalev_D | 214:4c70e452c491 | 244 | { // LoopOn |
Kovalev_D | 197:7a05523bf588 | 245 | Time100K = 0; |
Kovalev_D | 197:7a05523bf588 | 246 | Event1K ++; |
Kovalev_D | 214:4c70e452c491 | 247 | // LoopOn |
Kovalev_D | 197:7a05523bf588 | 248 | } |
Kovalev_D | 209:224e7331a061 | 249 | |
Kovalev_D | 218:b4067cac75c0 | 250 | if (Time2K== 10000) |
Kovalev_D | 209:224e7331a061 | 251 | { Time2K=0; |
Kovalev_D | 209:224e7331a061 | 252 | //Time100K = 0; |
Kovalev_D | 209:224e7331a061 | 253 | Event2K ++; |
Kovalev_D | 209:224e7331a061 | 254 | } |
Kovalev_D | 209:224e7331a061 | 255 | |
Kovalev_D | 197:7a05523bf588 | 256 | if (Time500Hz > 200) |
Kovalev_D | 208:19150d2b528f | 257 | { // LoopOn |
Kovalev_D | 197:7a05523bf588 | 258 | Time500Hz -= 200; |
Kovalev_D | 208:19150d2b528f | 259 | Event500Hz ++; |
Kovalev_D | 197:7a05523bf588 | 260 | } |
Kovalev_D | 209:224e7331a061 | 261 | |
Kovalev_D | 209:224e7331a061 | 262 | if (Time250Hz > 6) |
Kovalev_D | 209:224e7331a061 | 263 | { // LoopOn |
Kovalev_D | 209:224e7331a061 | 264 | Time250Hz -= 6; |
Kovalev_D | 209:224e7331a061 | 265 | Event250Hz ++; |
Kovalev_D | 209:224e7331a061 | 266 | } |
Kovalev_D | 210:b02fa166315d | 267 | |
Kovalev_D | 213:9953db9543d6 | 268 | //LoopOff |
igor_v | 21:bc8c1cec3da6 | 269 | } |