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