![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
fork
Fork of LG by
MTimer.c@207:d1ce992f5d17, 2017-01-13 (annotated)
- Committer:
- Kovalev_D
- Date:
- Fri Jan 13 08:27:28 2017 +0000
- Revision:
- 207:d1ce992f5d17
- Parent:
- 205:775d54fdf646
- Child:
- 208:19150d2b528f
4566
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 | 197:7a05523bf588 | 13 | unsigned int f; |
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 | 124:9ae09249f842 | 25 | { |
Kovalev_D | 203:3a6615de9581 | 26 | |
Kovalev_D | 124:9ae09249f842 | 27 | Gyro.Rate1_Event = 1; |
Kovalev_D | 122:fbacb932a30b | 28 | Event1Hz--; |
Kovalev_D | 122:fbacb932a30b | 29 | Time1Hz++; |
Kovalev_D | 117:eefe61968528 | 30 | Discharg (); |
Kovalev_D | 193:a0fe8bfc97e4 | 31 | BackLight(); |
Kovalev_D | 196:f76dbc081e63 | 32 | } |
Kovalev_D | 88:b5c1d9d338d1 | 33 | } |
Kovalev_D | 89:a0d344db227e | 34 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 35 | ///////////////////// 1kHz ////////////////////////// |
Kovalev_D | 197:7a05523bf588 | 36 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 37 | void Event_1KHz(void)// событие раз в 1 кГц |
Kovalev_D | 88:b5c1d9d338d1 | 38 | { |
Kovalev_D | 116:66f1f0ff2dab | 39 | if (Event1K) |
Kovalev_D | 116:66f1f0ff2dab | 40 | { |
Kovalev_D | 88:b5c1d9d338d1 | 41 | Event1K --; |
Kovalev_D | 116:66f1f0ff2dab | 42 | Time1K++;//первый ++ работает каждые 125 (event100kHz)второй был в 100 кГц |
Kovalev_D | 193:a0fe8bfc97e4 | 43 | |
Kovalev_D | 116:66f1f0ff2dab | 44 | if (Time1K == 1000) |
Kovalev_D | 115:e5a230e5af52 | 45 | { |
Kovalev_D | 88:b5c1d9d338d1 | 46 | Time1K = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 47 | Event1Hz ++; |
Kovalev_D | 88:b5c1d9d338d1 | 48 | } |
Kovalev_D | 88:b5c1d9d338d1 | 49 | } |
Kovalev_D | 88:b5c1d9d338d1 | 50 | } |
Kovalev_D | 124:9ae09249f842 | 51 | void Event_500Hz(void)// событие раз в 500 Гц |
Kovalev_D | 124:9ae09249f842 | 52 | { |
Kovalev_D | 124:9ae09249f842 | 53 | if(Event500Hz) |
Kovalev_D | 205:775d54fdf646 | 54 | { |
Kovalev_D | 205:775d54fdf646 | 55 | |
Kovalev_D | 205:775d54fdf646 | 56 | Event500Hz--; |
Kovalev_D | 197:7a05523bf588 | 57 | Gyro.Event_500Hz=1;// Event 500Гц выдачи данных для постройки графика управления вибро |
Kovalev_D | 205:775d54fdf646 | 58 | //CMD_Rate2(); |
Kovalev_D | 197:7a05523bf588 | 59 | } |
Kovalev_D | 197:7a05523bf588 | 60 | } |
Kovalev_D | 197:7a05523bf588 | 61 | |
Kovalev_D | 205:775d54fdf646 | 62 | /* |
Kovalev_D | 197:7a05523bf588 | 63 | void Event_250Hz(void)// событие раз в 500 Гц |
Kovalev_D | 197:7a05523bf588 | 64 | { |
Kovalev_D | 197:7a05523bf588 | 65 | if(Event250Hz) |
Kovalev_D | 193:a0fe8bfc97e4 | 66 | { |
Kovalev_D | 197:7a05523bf588 | 67 | Event250Hz--; |
Kovalev_D | 197:7a05523bf588 | 68 | Gyro.EventMOD=1;// Event 500Гц выдачи данных для постройки графика управления вибро |
Kovalev_D | 124:9ae09249f842 | 69 | } |
Kovalev_D | 205:775d54fdf646 | 70 | }*/ |
Kovalev_D | 89:a0d344db227e | 71 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 72 | ///////////////////// 100kHz ////////////////////////// |
Kovalev_D | 89:a0d344db227e | 73 | ///////////////////////////////////////////////////// |
Kovalev_D | 193:a0fe8bfc97e4 | 74 | void Event_100KHz(void)// событие раз в 100 кГц |
Kovalev_D | 88:b5c1d9d338d1 | 75 | { |
Kovalev_D | 162:44e4ded32c6a | 76 | |
Kovalev_D | 88:b5c1d9d338d1 | 77 | if (Event100K) { |
Kovalev_D | 197:7a05523bf588 | 78 | |
Kovalev_D | 88:b5c1d9d338d1 | 79 | Event100K --; |
Kovalev_D | 197:7a05523bf588 | 80 | |
Kovalev_D | 124:9ae09249f842 | 81 | if (OutBufCon1Count)OutBufCon1Count--; // обратный отсчет для управления ногой и формирование задержки на выдачу |
Kovalev_D | 124:9ae09249f842 | 82 | |
Kovalev_D | 124:9ae09249f842 | 83 | PinCheng(); // чтение регистра состояния выводов(вибро, полсветка, поджиг, LED) и управление выводами. |
Kovalev_D | 88:b5c1d9d338d1 | 84 | } |
Kovalev_D | 88:b5c1d9d338d1 | 85 | } |
Kovalev_D | 89:a0d344db227e | 86 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 87 | //////////////////vibro EVENT//////////////////////// |
Kovalev_D | 89:a0d344db227e | 88 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 89 | void Event_Vibro(void)// событие от вибр |
Kovalev_D | 88:b5c1d9d338d1 | 90 | { |
Kovalev_D | 88:b5c1d9d338d1 | 91 | if (EventVibro) { |
Kovalev_D | 88:b5c1d9d338d1 | 92 | EventVibro --; |
Kovalev_D | 88:b5c1d9d338d1 | 93 | } |
Kovalev_D | 88:b5c1d9d338d1 | 94 | } |
Kovalev_D | 89:a0d344db227e | 95 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 96 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 97 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 98 | |
Kovalev_D | 88:b5c1d9d338d1 | 99 | |
Kovalev_D | 112:4a96133a1311 | 100 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 101 | ////////////////////////////////////////////////////////TIMER1//////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 102 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 103 | |
Kovalev_D | 112:4a96133a1311 | 104 | ////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 105 | /////////////////////инициализация таймера 1 ///////////////////////// |
Kovalev_D | 112:4a96133a1311 | 106 | ////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 107 | |
Kovalev_D | 112:4a96133a1311 | 108 | unsigned int Init_TIM1 (unsigned int TimerInterval ) |
Kovalev_D | 112:4a96133a1311 | 109 | { |
Kovalev_D | 112:4a96133a1311 | 110 | LPC_TIM1->MR0 = TimerInterval; |
Kovalev_D | 112:4a96133a1311 | 111 | LPC_TIM1->MCR = 3; /* Interrupt and Reset on MR1 */ |
Kovalev_D | 112:4a96133a1311 | 112 | NVIC_EnableIRQ(TIMER1_IRQn); |
Kovalev_D | 112:4a96133a1311 | 113 | } |
Kovalev_D | 112:4a96133a1311 | 114 | |
Kovalev_D | 112:4a96133a1311 | 115 | |
igor_v | 0:8ad47e2b6f00 | 116 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 117 | /////////////////////////включение таймера 1////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 118 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 119 | void enable_timer1( void ) |
igor_v | 21:bc8c1cec3da6 | 120 | { |
igor_v | 21:bc8c1cec3da6 | 121 | LPC_TIM1->TCR = 1; |
igor_v | 21:bc8c1cec3da6 | 122 | return; |
igor_v | 21:bc8c1cec3da6 | 123 | } |
igor_v | 0:8ad47e2b6f00 | 124 | |
igor_v | 0:8ad47e2b6f00 | 125 | |
igor_v | 0:8ad47e2b6f00 | 126 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 127 | /////////////////////////////////////////////////TIMER2////////////////////////////////////////////////////////////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 128 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 129 | |
igor_v | 0:8ad47e2b6f00 | 130 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 131 | /////////////////////инициализация таймера 2 ///////////////////////// |
igor_v | 0:8ad47e2b6f00 | 132 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 133 | unsigned int Init_TIM2 (void) |
igor_v | 21:bc8c1cec3da6 | 134 | { |
Kovalev_D | 124:9ae09249f842 | 135 | LPC_TIM2->MR0 = 257; |
igor_v | 21:bc8c1cec3da6 | 136 | LPC_TIM2->MCR = 3; /* Interrupt and Reset on MR0 */ |
igor_v | 21:bc8c1cec3da6 | 137 | NVIC_EnableIRQ(TIMER2_IRQn); |
igor_v | 21:bc8c1cec3da6 | 138 | return 1; |
igor_v | 21:bc8c1cec3da6 | 139 | } |
igor_v | 0:8ad47e2b6f00 | 140 | |
igor_v | 21:bc8c1cec3da6 | 141 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 142 | /////////////////////////включение таймера 2////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 143 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 144 | void enable_timer2(void) |
igor_v | 21:bc8c1cec3da6 | 145 | { |
igor_v | 21:bc8c1cec3da6 | 146 | LPC_TIM2->TCR = 1; |
igor_v | 21:bc8c1cec3da6 | 147 | LPC_TIM2->TCR = 0x01; |
igor_v | 21:bc8c1cec3da6 | 148 | } |
igor_v | 21:bc8c1cec3da6 | 149 | |
igor_v | 21:bc8c1cec3da6 | 150 | |
Kovalev_D | 112:4a96133a1311 | 151 | ////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 152 | /////////////////////////прерывание таймера 1////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 153 | ////////////////////////////////////////////////////////////////////// |
Kovalev_D | 183:7e200f4d9b16 | 154 | __irq void TIMER1_IRQHandler (void)//13.27 kHz |
Kovalev_D | 205:775d54fdf646 | 155 | { |
igor_v | 114:5cc38a53d8a7 | 156 | ResetCS(ADC); //prepare ADC for sampling |
Kovalev_D | 112:4a96133a1311 | 157 | SetDAC(DAC); |
Kovalev_D | 207:d1ce992f5d17 | 158 | Global_Time++; |
igor_v | 114:5cc38a53d8a7 | 159 | CountV255++; // инкремент счеттчика |
Kovalev_D | 164:6f43f85fdd8d | 160 | CountV255 &= 0xff; // ОБРЕЗАНИЕ СЧЕТЧИКА |
Kovalev_D | 197:7a05523bf588 | 161 | CountV64 = CountV255 & 0x3f; |
Kovalev_D | 197:7a05523bf588 | 162 | CountV31 = CountV255 & 0x1f; // малый счетчик |
Kovalev_D | 197:7a05523bf588 | 163 | |
Kovalev_D | 112:4a96133a1311 | 164 | D_QEI(); //чтение данных по счетчику |
Kovalev_D | 143:2b15794a6cd2 | 165 | cheng(); // выставление флагов в 32 тактном цикле. |
Kovalev_D | 116:66f1f0ff2dab | 166 | |
Kovalev_D | 116:66f1f0ff2dab | 167 | |
Kovalev_D | 116:66f1f0ff2dab | 168 | SetCS(ADC); //start ADC sampling |
Kovalev_D | 116:66f1f0ff2dab | 169 | ResetDAC(DAC); |
Kovalev_D | 197:7a05523bf588 | 170 | SPI_Exchange(); //Чтение ADC_SPI |
igor_v | 114:5cc38a53d8a7 | 171 | |
Kovalev_D | 112:4a96133a1311 | 172 | LPC_TIM1->IR = 1; |
Kovalev_D | 193:a0fe8bfc97e4 | 173 | |
Kovalev_D | 205:775d54fdf646 | 174 | |
Kovalev_D | 112:4a96133a1311 | 175 | } |
Kovalev_D | 112:4a96133a1311 | 176 | |
igor_v | 21:bc8c1cec3da6 | 177 | /////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 178 | /////////////////////////прерывание таймера 2////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 179 | /////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 180 | __irq void TIMER2_IRQHandler (void) |
Kovalev_D | 207:d1ce992f5d17 | 181 | { LoopOn |
igor_v | 21:bc8c1cec3da6 | 182 | LPC_TIM2->IR = 1; |
Kovalev_D | 207:d1ce992f5d17 | 183 | |
Kovalev_D | 190:289514f730ee | 184 | if(Time_UART) Time_UART--; |
igor_v | 21:bc8c1cec3da6 | 185 | Time_vibro++; |
Kovalev_D | 203:3a6615de9581 | 186 | VibroOut(); |
Kovalev_D | 112:4a96133a1311 | 187 | Gyro.VibroOutF=1; |
Kovalev_D | 190:289514f730ee | 188 | Event100K ++; |
Kovalev_D | 197:7a05523bf588 | 189 | Time500Hz++; |
Kovalev_D | 197:7a05523bf588 | 190 | Time100K++; |
Kovalev_D | 205:775d54fdf646 | 191 | // Time250Hz++; |
Kovalev_D | 197:7a05523bf588 | 192 | if (Time100K == 100) |
Kovalev_D | 197:7a05523bf588 | 193 | { |
Kovalev_D | 197:7a05523bf588 | 194 | Time100K = 0; |
Kovalev_D | 197:7a05523bf588 | 195 | Event1K ++; |
Kovalev_D | 197:7a05523bf588 | 196 | } |
Kovalev_D | 197:7a05523bf588 | 197 | if (Time500Hz > 200) |
Kovalev_D | 197:7a05523bf588 | 198 | { |
Kovalev_D | 197:7a05523bf588 | 199 | Time500Hz -= 200; |
Kovalev_D | 197:7a05523bf588 | 200 | Event500Hz ++; |
Kovalev_D | 197:7a05523bf588 | 201 | |
Kovalev_D | 197:7a05523bf588 | 202 | } |
Kovalev_D | 205:775d54fdf646 | 203 | /* if (Time250Hz > 400) |
Kovalev_D | 197:7a05523bf588 | 204 | { |
Kovalev_D | 197:7a05523bf588 | 205 | Time250Hz -= 400; |
Kovalev_D | 197:7a05523bf588 | 206 | Event250Hz ++; |
Kovalev_D | 205:775d54fdf646 | 207 | }*/ |
Kovalev_D | 203:3a6615de9581 | 208 | LoopOff |
igor_v | 21:bc8c1cec3da6 | 209 | } |