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