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