123
Fork of LG by
MTimer.c@196:f76dbc081e63, 2016-09-23 (annotated)
- Committer:
- Kovalev_D
- Date:
- Fri Sep 23 05:34:50 2016 +0000
- Revision:
- 196:f76dbc081e63
- Parent:
- 193:a0fe8bfc97e4
- Child:
- 197:7a05523bf588
???
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 ; |
Kovalev_D | 124:9ae09249f842 | 16 | int loop=0; |
Kovalev_D | 112:4a96133a1311 | 17 | |
Kovalev_D | 88:b5c1d9d338d1 | 18 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 19 | /////////////////////EVENT/////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 20 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 21 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 22 | ///////////////////// 1Hz /////////////////////////// |
Kovalev_D | 89:a0d344db227e | 23 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 24 | void Event_1Hz(void)// событие раз в 1 Гц |
Kovalev_D | 92:c892f0311aa7 | 25 | { int i,t; |
Kovalev_D | 115:e5a230e5af52 | 26 | if (Event1Hz) |
Kovalev_D | 124:9ae09249f842 | 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 | 196:f76dbc081e63 | 33 | } |
Kovalev_D | 88:b5c1d9d338d1 | 34 | } |
Kovalev_D | 89:a0d344db227e | 35 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 36 | ///////////////////// 1kHz ////////////////////////// |
Kovalev_D | 193:a0fe8bfc97e4 | 37 | /////////////////////////////////////////////////////LoopOn LPC_GPIO1->FIOSET = (1<<30); |
Kovalev_D | 193:a0fe8bfc97e4 | 38 | //#define LoopOff LPC_GPIO1->FIOCLR = (1<<30); |
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 | 193:a0fe8bfc97e4 | 45 | |
Kovalev_D | 116:66f1f0ff2dab | 46 | if (Time1K == 1000) |
Kovalev_D | 115:e5a230e5af52 | 47 | { |
Kovalev_D | 88:b5c1d9d338d1 | 48 | Time1K = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 49 | Event1Hz ++; |
Kovalev_D | 88:b5c1d9d338d1 | 50 | } |
Kovalev_D | 88:b5c1d9d338d1 | 51 | } |
Kovalev_D | 88:b5c1d9d338d1 | 52 | } |
Kovalev_D | 124:9ae09249f842 | 53 | void Event_500Hz(void)// событие раз в 500 Гц |
Kovalev_D | 124:9ae09249f842 | 54 | { |
Kovalev_D | 124:9ae09249f842 | 55 | if(Event500Hz) |
Kovalev_D | 193:a0fe8bfc97e4 | 56 | { |
Kovalev_D | 124:9ae09249f842 | 57 | Event500Hz--; |
Kovalev_D | 196:f76dbc081e63 | 58 | //Gyro.Delta500_Event=1; |
Kovalev_D | 143:2b15794a6cd2 | 59 | Gyro.Event_500Hz=1;// Event 500Гц выдачи данных для постройки графика управления вибро |
Kovalev_D | 196:f76dbc081e63 | 60 | //Gyro.Delta_Bins_Event500=1; |
Kovalev_D | 196:f76dbc081e63 | 61 | //Gyro.B_Delta_Event500=1; |
Kovalev_D | 124:9ae09249f842 | 62 | } |
Kovalev_D | 124:9ae09249f842 | 63 | } |
Kovalev_D | 89:a0d344db227e | 64 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 65 | ///////////////////// 100kHz ////////////////////////// |
Kovalev_D | 89:a0d344db227e | 66 | ///////////////////////////////////////////////////// |
Kovalev_D | 193:a0fe8bfc97e4 | 67 | void Event_100KHz(void)// событие раз в 100 кГц |
Kovalev_D | 88:b5c1d9d338d1 | 68 | { |
Kovalev_D | 162:44e4ded32c6a | 69 | |
Kovalev_D | 88:b5c1d9d338d1 | 70 | if (Event100K) { |
Kovalev_D | 88:b5c1d9d338d1 | 71 | Event100K --; |
Kovalev_D | 162:44e4ded32c6a | 72 | Time500Hz++; |
Kovalev_D | 116:66f1f0ff2dab | 73 | |
Kovalev_D | 124:9ae09249f842 | 74 | if (OutBufCon1Count)OutBufCon1Count--; // обратный отсчет для управления ногой и формирование задержки на выдачу |
Kovalev_D | 124:9ae09249f842 | 75 | |
Kovalev_D | 124:9ae09249f842 | 76 | PinCheng(); // чтение регистра состояния выводов(вибро, полсветка, поджиг, LED) и управление выводами. |
Kovalev_D | 116:66f1f0ff2dab | 77 | |
Kovalev_D | 116:66f1f0ff2dab | 78 | Time100K++; |
Kovalev_D | 124:9ae09249f842 | 79 | if (Time100K == 100) |
Kovalev_D | 124:9ae09249f842 | 80 | { |
Kovalev_D | 88:b5c1d9d338d1 | 81 | Time100K = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 82 | Event1K ++; |
Kovalev_D | 124:9ae09249f842 | 83 | } |
Kovalev_D | 162:44e4ded32c6a | 84 | if (Time500Hz > 200) |
Kovalev_D | 190:289514f730ee | 85 | { |
Kovalev_D | 162:44e4ded32c6a | 86 | Time500Hz -= 200; |
Kovalev_D | 162:44e4ded32c6a | 87 | Event500Hz ++; |
Kovalev_D | 190:289514f730ee | 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 | |
igor_v | 0:8ad47e2b6f00 | 121 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 122 | /////////////////////////включение таймера 1////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 123 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 124 | void enable_timer1( void ) |
igor_v | 21:bc8c1cec3da6 | 125 | { |
igor_v | 21:bc8c1cec3da6 | 126 | LPC_TIM1->TCR = 1; |
igor_v | 21:bc8c1cec3da6 | 127 | return; |
igor_v | 21:bc8c1cec3da6 | 128 | } |
igor_v | 0:8ad47e2b6f00 | 129 | |
igor_v | 0:8ad47e2b6f00 | 130 | |
igor_v | 0:8ad47e2b6f00 | 131 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 132 | /////////////////////////////////////////////////TIMER2////////////////////////////////////////////////////////////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 133 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 134 | |
igor_v | 0:8ad47e2b6f00 | 135 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 136 | /////////////////////инициализация таймера 2 ///////////////////////// |
igor_v | 0:8ad47e2b6f00 | 137 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 138 | unsigned int Init_TIM2 (void) |
igor_v | 21:bc8c1cec3da6 | 139 | { |
Kovalev_D | 124:9ae09249f842 | 140 | LPC_TIM2->MR0 = 257; |
igor_v | 21:bc8c1cec3da6 | 141 | LPC_TIM2->MCR = 3; /* Interrupt and Reset on MR0 */ |
igor_v | 21:bc8c1cec3da6 | 142 | NVIC_EnableIRQ(TIMER2_IRQn); |
igor_v | 21:bc8c1cec3da6 | 143 | return 1; |
igor_v | 21:bc8c1cec3da6 | 144 | } |
igor_v | 0:8ad47e2b6f00 | 145 | |
igor_v | 15:f5191a1c3805 | 146 | |
igor_v | 15:f5191a1c3805 | 147 | |
igor_v | 21:bc8c1cec3da6 | 148 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 149 | /////////////////////////включение таймера 2////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 150 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 151 | void enable_timer2(void) |
igor_v | 21:bc8c1cec3da6 | 152 | { |
igor_v | 21:bc8c1cec3da6 | 153 | LPC_TIM2->TCR = 1; |
igor_v | 21:bc8c1cec3da6 | 154 | LPC_TIM2->TCR = 0x01; |
igor_v | 21:bc8c1cec3da6 | 155 | } |
igor_v | 21:bc8c1cec3da6 | 156 | |
igor_v | 21:bc8c1cec3da6 | 157 | |
Kovalev_D | 112:4a96133a1311 | 158 | ////////////////////////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 159 | /////////////////////////прерывание таймера 1////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 160 | ////////////////////////////////////////////////////////////////////// |
Kovalev_D | 185:7e200f4d9b16 | 161 | __irq void TIMER1_IRQHandler (void)//13.27 kHz |
Kovalev_D | 193:a0fe8bfc97e4 | 162 | { |
igor_v | 114:5cc38a53d8a7 | 163 | ResetCS(ADC); //prepare ADC for sampling |
Kovalev_D | 112:4a96133a1311 | 164 | SetDAC(DAC); |
Kovalev_D | 112:4a96133a1311 | 165 | |
igor_v | 114:5cc38a53d8a7 | 166 | CountV255++; // инкремент счеттчика |
Kovalev_D | 164:6f43f85fdd8d | 167 | CountV255 &= 0xff; // ОБРЕЗАНИЕ СЧЕТЧИКА |
igor_v | 114:5cc38a53d8a7 | 168 | CountV31 =CountV255 & 0x1f; // малый счетчик |
Kovalev_D | 121:bbae560cdd43 | 169 | |
Kovalev_D | 112:4a96133a1311 | 170 | D_QEI(); //чтение данных по счетчику |
Kovalev_D | 143:2b15794a6cd2 | 171 | cheng(); // выставление флагов в 32 тактном цикле. |
Kovalev_D | 116:66f1f0ff2dab | 172 | |
Kovalev_D | 116:66f1f0ff2dab | 173 | |
Kovalev_D | 116:66f1f0ff2dab | 174 | SetCS(ADC); //start ADC sampling |
Kovalev_D | 116:66f1f0ff2dab | 175 | ResetDAC(DAC); |
igor_v | 114:5cc38a53d8a7 | 176 | SPI_Exchange(); //Чтение ADS_SPI |
igor_v | 114:5cc38a53d8a7 | 177 | |
Kovalev_D | 112:4a96133a1311 | 178 | LPC_TIM1->IR = 1; |
Kovalev_D | 193:a0fe8bfc97e4 | 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 | |
Kovalev_D | 112:4a96133a1311 | 186 | |
igor_v | 21:bc8c1cec3da6 | 187 | /////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 188 | /////////////////////////прерывание таймера 2////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 189 | /////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 190 | __irq void TIMER2_IRQHandler (void) |
Kovalev_D | 193:a0fe8bfc97e4 | 191 | { |
igor_v | 21:bc8c1cec3da6 | 192 | LPC_TIM2->IR = 1; |
igor_v | 21:bc8c1cec3da6 | 193 | Global_Time++; |
Kovalev_D | 190:289514f730ee | 194 | if(Time_UART) Time_UART--; |
igor_v | 21:bc8c1cec3da6 | 195 | Time_vibro++; |
Kovalev_D | 112:4a96133a1311 | 196 | Gyro.VibroOutF=1; |
Kovalev_D | 190:289514f730ee | 197 | Event100K ++; |
Kovalev_D | 193:a0fe8bfc97e4 | 198 | |
igor_v | 21:bc8c1cec3da6 | 199 | } |