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