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