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