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