123
Fork of LG by
MTimer.c@112:4a96133a1311, 2016-04-04 (annotated)
- Committer:
- Kovalev_D
- Date:
- Mon Apr 04 11:09:56 2016 +0000
- Revision:
- 112:4a96133a1311
- Parent:
- 108:030cdde08314
- Child:
- 113:8be429494918
IRQ
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; |
igor_v | 21:bc8c1cec3da6 | 15 | unsigned int CountV255=0 ; |
igor_v | 21:bc8c1cec3da6 | 16 | unsigned int CountV64 = 0; |
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 | 88:b5c1d9d338d1 | 35 | if (Event1Hz) { |
Kovalev_D | 88:b5c1d9d338d1 | 36 | Event1Hz--; |
Kovalev_D | 88:b5c1d9d338d1 | 37 | Discharg (); |
Kovalev_D | 88:b5c1d9d338d1 | 38 | BackLight (); |
Kovalev_D | 112:4a96133a1311 | 39 | |
Kovalev_D | 112:4a96133a1311 | 40 | if(Rate_Flag)CMD_Rate(); |
Kovalev_D | 88:b5c1d9d338d1 | 41 | } |
Kovalev_D | 88:b5c1d9d338d1 | 42 | } |
Kovalev_D | 89:a0d344db227e | 43 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 44 | ///////////////////// 1kHz ////////////////////////// |
Kovalev_D | 89:a0d344db227e | 45 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 46 | void Event_1KHz(void)// событие раз в 1 кГц |
Kovalev_D | 88:b5c1d9d338d1 | 47 | { |
Kovalev_D | 88:b5c1d9d338d1 | 48 | if (Event1K) { |
Kovalev_D | 88:b5c1d9d338d1 | 49 | Event1K --; |
Kovalev_D | 88:b5c1d9d338d1 | 50 | Time1K++; |
Kovalev_D | 88:b5c1d9d338d1 | 51 | if (Time1K == 1000) { |
Kovalev_D | 88:b5c1d9d338d1 | 52 | Time1K = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 53 | Event1Hz ++; |
Kovalev_D | 88:b5c1d9d338d1 | 54 | Time1Hz++; |
Kovalev_D | 88:b5c1d9d338d1 | 55 | } |
Kovalev_D | 106:250ddd8629c6 | 56 | |
Kovalev_D | 88:b5c1d9d338d1 | 57 | } |
Kovalev_D | 88:b5c1d9d338d1 | 58 | } |
Kovalev_D | 89:a0d344db227e | 59 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 60 | ///////////////////// 100kHz ////////////////////////// |
Kovalev_D | 89:a0d344db227e | 61 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 62 | void Event_100KHz(void)// событие раз в 100 кГц |
Kovalev_D | 88:b5c1d9d338d1 | 63 | { |
Kovalev_D | 88:b5c1d9d338d1 | 64 | if (Event100K) { |
Kovalev_D | 88:b5c1d9d338d1 | 65 | Event100K --; |
Kovalev_D | 88:b5c1d9d338d1 | 66 | Time100K++; |
Kovalev_D | 88:b5c1d9d338d1 | 67 | PinCheng(); // чтение регистра состояния выводов(вибро, полсветка, поджиг, LED) и управление выводами. |
Kovalev_D | 88:b5c1d9d338d1 | 68 | if (OutBufCon1Count) { |
Kovalev_D | 88:b5c1d9d338d1 | 69 | OutBufCon1Count--; // обратный отсчет для управления ногой и формирование задержки на выдачу |
Kovalev_D | 88:b5c1d9d338d1 | 70 | } |
Kovalev_D | 88:b5c1d9d338d1 | 71 | if (Time100K == 100) { |
Kovalev_D | 88:b5c1d9d338d1 | 72 | Time100K = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 73 | Event1K ++; |
Kovalev_D | 88:b5c1d9d338d1 | 74 | } |
Kovalev_D | 88:b5c1d9d338d1 | 75 | } |
Kovalev_D | 88:b5c1d9d338d1 | 76 | } |
Kovalev_D | 89:a0d344db227e | 77 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 78 | //////////////////vibro EVENT//////////////////////// |
Kovalev_D | 89:a0d344db227e | 79 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 80 | void Event_Vibro(void)// событие от вибр |
Kovalev_D | 88:b5c1d9d338d1 | 81 | { |
Kovalev_D | 88:b5c1d9d338d1 | 82 | if (EventVibro) { |
Kovalev_D | 88:b5c1d9d338d1 | 83 | EventVibro --; |
Kovalev_D | 88:b5c1d9d338d1 | 84 | } |
Kovalev_D | 88:b5c1d9d338d1 | 85 | } |
Kovalev_D | 89:a0d344db227e | 86 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 87 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 88 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 89 | |
Kovalev_D | 88:b5c1d9d338d1 | 90 | |
Kovalev_D | 112:4a96133a1311 | 91 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 92 | ////////////////////////////////////////////////////////TIMER1//////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 93 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 94 | |
Kovalev_D | 112:4a96133a1311 | 95 | ////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 96 | /////////////////////инициализация таймера 1 ///////////////////////// |
Kovalev_D | 112:4a96133a1311 | 97 | ////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 98 | |
Kovalev_D | 112:4a96133a1311 | 99 | unsigned int Init_TIM1 (unsigned int TimerInterval ) |
Kovalev_D | 112:4a96133a1311 | 100 | { |
Kovalev_D | 112:4a96133a1311 | 101 | LPC_TIM1->MR0 = TimerInterval; |
Kovalev_D | 112:4a96133a1311 | 102 | LPC_TIM1->MCR = 3; /* Interrupt and Reset on MR1 */ |
Kovalev_D | 112:4a96133a1311 | 103 | NVIC_EnableIRQ(TIMER1_IRQn); |
Kovalev_D | 112:4a96133a1311 | 104 | } |
Kovalev_D | 112:4a96133a1311 | 105 | |
Kovalev_D | 112:4a96133a1311 | 106 | |
Kovalev_D | 112:4a96133a1311 | 107 | |
Kovalev_D | 112:4a96133a1311 | 108 | |
Kovalev_D | 112:4a96133a1311 | 109 | |
Kovalev_D | 112:4a96133a1311 | 110 | |
Kovalev_D | 112:4a96133a1311 | 111 | |
Kovalev_D | 112:4a96133a1311 | 112 | |
Kovalev_D | 88:b5c1d9d338d1 | 113 | |
Kovalev_D | 88:b5c1d9d338d1 | 114 | |
Kovalev_D | 88:b5c1d9d338d1 | 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 | { |
igor_v | 21:bc8c1cec3da6 | 135 | LPC_TIM2->MR0 = 250; |
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 | 15:f5191a1c3805 | 141 | |
igor_v | 15:f5191a1c3805 | 142 | |
igor_v | 21:bc8c1cec3da6 | 143 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 144 | /////////////////////////включение таймера 2////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 145 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 146 | void enable_timer2(void) |
igor_v | 21:bc8c1cec3da6 | 147 | { |
igor_v | 21:bc8c1cec3da6 | 148 | LPC_TIM2->TCR = 1; |
igor_v | 21:bc8c1cec3da6 | 149 | LPC_TIM2->TCR = 0x01; |
igor_v | 21:bc8c1cec3da6 | 150 | } |
igor_v | 21:bc8c1cec3da6 | 151 | |
igor_v | 21:bc8c1cec3da6 | 152 | |
igor_v | 21:bc8c1cec3da6 | 153 | |
Kovalev_D | 112:4a96133a1311 | 154 | |
Kovalev_D | 112:4a96133a1311 | 155 | ////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 156 | /////////////////////////прерывание таймера 1////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 157 | ////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 158 | __irq void TIMER1_IRQHandler (void) |
Kovalev_D | 112:4a96133a1311 | 159 | { |
Kovalev_D | 112:4a96133a1311 | 160 | ResetCS(ADC); //prepare ADC for sampling |
Kovalev_D | 112:4a96133a1311 | 161 | SetDAC(DAC); |
Kovalev_D | 112:4a96133a1311 | 162 | |
Kovalev_D | 112:4a96133a1311 | 163 | CountV255++; |
Kovalev_D | 112:4a96133a1311 | 164 | CountV255 &= 0xff; |
Kovalev_D | 112:4a96133a1311 | 165 | CountV31 =CountV255 & 0x1f; |
Kovalev_D | 112:4a96133a1311 | 166 | CountV64 = CountV255 & 0x3f; |
Kovalev_D | 112:4a96133a1311 | 167 | |
Kovalev_D | 112:4a96133a1311 | 168 | SetCS(ADC); //start ADC sampling |
Kovalev_D | 112:4a96133a1311 | 169 | ResetDAC(DAC); |
Kovalev_D | 112:4a96133a1311 | 170 | |
Kovalev_D | 112:4a96133a1311 | 171 | D_QEI(); //чтение данных по счетчику |
Kovalev_D | 112:4a96133a1311 | 172 | cheng(); // расчет вибропривода |
Kovalev_D | 112:4a96133a1311 | 173 | |
Kovalev_D | 112:4a96133a1311 | 174 | |
Kovalev_D | 112:4a96133a1311 | 175 | |
Kovalev_D | 112:4a96133a1311 | 176 | Spi.SpiFlag=1; |
Kovalev_D | 112:4a96133a1311 | 177 | LPC_TIM1->IR = 1; |
Kovalev_D | 112:4a96133a1311 | 178 | |
Kovalev_D | 112:4a96133a1311 | 179 | } |
Kovalev_D | 112:4a96133a1311 | 180 | |
Kovalev_D | 112:4a96133a1311 | 181 | |
Kovalev_D | 112:4a96133a1311 | 182 | |
Kovalev_D | 112:4a96133a1311 | 183 | |
Kovalev_D | 112:4a96133a1311 | 184 | |
Kovalev_D | 112:4a96133a1311 | 185 | |
igor_v | 21:bc8c1cec3da6 | 186 | /////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 187 | /////////////////////////прерывание таймера 2////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 188 | /////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 189 | __irq void TIMER2_IRQHandler (void) |
igor_v | 21:bc8c1cec3da6 | 190 | { |
igor_v | 21:bc8c1cec3da6 | 191 | LPC_TIM2->IR = 1; |
igor_v | 21:bc8c1cec3da6 | 192 | |
igor_v | 21:bc8c1cec3da6 | 193 | Global_Time++; |
igor_v | 21:bc8c1cec3da6 | 194 | |
igor_v | 21:bc8c1cec3da6 | 195 | Time_UART++; |
igor_v | 21:bc8c1cec3da6 | 196 | |
igor_v | 21:bc8c1cec3da6 | 197 | Time_vibro++; |
igor_v | 21:bc8c1cec3da6 | 198 | |
igor_v | 21:bc8c1cec3da6 | 199 | Time_1kHz++; |
Kovalev_D | 112:4a96133a1311 | 200 | |
Kovalev_D | 112:4a96133a1311 | 201 | Gyro.VibroOutF=1; |
Kovalev_D | 112:4a96133a1311 | 202 | |
Kovalev_D | 88:b5c1d9d338d1 | 203 | Event100K --; |
igor_v | 21:bc8c1cec3da6 | 204 | |
igor_v | 21:bc8c1cec3da6 | 205 | } |