123
Fork of LG by
MTimer.c@89:a0d344db227e, 2016-03-24 (annotated)
- Committer:
- Kovalev_D
- Date:
- Thu Mar 24 12:57:10 2016 +0000
- Revision:
- 89:a0d344db227e
- Parent:
- 88:b5c1d9d338d1
- Child:
- 92:c892f0311aa7
.
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 | 88:b5c1d9d338d1 | 43 | { |
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 | 88:b5c1d9d338d1 | 48 | } |
Kovalev_D | 88:b5c1d9d338d1 | 49 | } |
Kovalev_D | 89:a0d344db227e | 50 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 51 | ///////////////////// 1kHz ////////////////////////// |
Kovalev_D | 89:a0d344db227e | 52 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 53 | void Event_1KHz(void)// событие раз в 1 кГц |
Kovalev_D | 88:b5c1d9d338d1 | 54 | { |
Kovalev_D | 88:b5c1d9d338d1 | 55 | if (Event1K) { |
Kovalev_D | 88:b5c1d9d338d1 | 56 | Event1K --; |
Kovalev_D | 88:b5c1d9d338d1 | 57 | Time1K++; |
Kovalev_D | 88:b5c1d9d338d1 | 58 | if (Time1K == 1000) { |
Kovalev_D | 88:b5c1d9d338d1 | 59 | Time1K = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 60 | Event1Hz ++; |
Kovalev_D | 88:b5c1d9d338d1 | 61 | Time1Hz++; |
Kovalev_D | 88:b5c1d9d338d1 | 62 | } |
Kovalev_D | 88:b5c1d9d338d1 | 63 | } |
Kovalev_D | 88:b5c1d9d338d1 | 64 | } |
Kovalev_D | 89:a0d344db227e | 65 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 66 | ///////////////////// 100kHz ////////////////////////// |
Kovalev_D | 89:a0d344db227e | 67 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 68 | void Event_100KHz(void)// событие раз в 100 кГц |
Kovalev_D | 88:b5c1d9d338d1 | 69 | { |
Kovalev_D | 88:b5c1d9d338d1 | 70 | if (Event100K) { |
Kovalev_D | 88:b5c1d9d338d1 | 71 | Event100K --; |
Kovalev_D | 88:b5c1d9d338d1 | 72 | Time100K++; |
Kovalev_D | 88:b5c1d9d338d1 | 73 | PinCheng(); // чтение регистра состояния выводов(вибро, полсветка, поджиг, LED) и управление выводами. |
Kovalev_D | 88:b5c1d9d338d1 | 74 | if (OutBufCon1Count) { |
Kovalev_D | 88:b5c1d9d338d1 | 75 | OutBufCon1Count--; // обратный отсчет для управления ногой и формирование задержки на выдачу |
Kovalev_D | 88:b5c1d9d338d1 | 76 | } |
Kovalev_D | 88:b5c1d9d338d1 | 77 | if (Time100K == 100) { |
Kovalev_D | 88:b5c1d9d338d1 | 78 | Time100K = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 79 | Event1K ++; |
Kovalev_D | 88:b5c1d9d338d1 | 80 | } |
Kovalev_D | 88:b5c1d9d338d1 | 81 | } |
Kovalev_D | 88:b5c1d9d338d1 | 82 | } |
Kovalev_D | 89:a0d344db227e | 83 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 84 | //////////////////vibro EVENT//////////////////////// |
Kovalev_D | 89:a0d344db227e | 85 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 86 | void Event_Vibro(void)// событие от вибр |
Kovalev_D | 88:b5c1d9d338d1 | 87 | { |
Kovalev_D | 88:b5c1d9d338d1 | 88 | if (EventVibro) { |
Kovalev_D | 88:b5c1d9d338d1 | 89 | EventVibro --; |
Kovalev_D | 88:b5c1d9d338d1 | 90 | } |
Kovalev_D | 88:b5c1d9d338d1 | 91 | } |
Kovalev_D | 89:a0d344db227e | 92 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 93 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 94 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 95 | |
Kovalev_D | 88:b5c1d9d338d1 | 96 | |
Kovalev_D | 88:b5c1d9d338d1 | 97 | |
Kovalev_D | 88:b5c1d9d338d1 | 98 | |
Kovalev_D | 88:b5c1d9d338d1 | 99 | |
igor_v | 0:8ad47e2b6f00 | 100 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 101 | /////////////////////////включение таймера 1////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 102 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 103 | void enable_timer1( void ) |
igor_v | 21:bc8c1cec3da6 | 104 | { |
igor_v | 21:bc8c1cec3da6 | 105 | LPC_TIM1->TCR = 1; |
igor_v | 21:bc8c1cec3da6 | 106 | return; |
igor_v | 21:bc8c1cec3da6 | 107 | } |
igor_v | 0:8ad47e2b6f00 | 108 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 109 | /////////////////////////прерывание таймера 1////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 110 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 111 | __irq void TIMER1_IRQHandler (void) |
igor_v | 21:bc8c1cec3da6 | 112 | { |
igor_v | 21:bc8c1cec3da6 | 113 | ResetCS(ADC); //prepare ADC for sampling |
igor_v | 21:bc8c1cec3da6 | 114 | SetDAC(DAC); |
igor_v | 21:bc8c1cec3da6 | 115 | |
igor_v | 21:bc8c1cec3da6 | 116 | CountV255++; |
igor_v | 21:bc8c1cec3da6 | 117 | CountV255 &= 0xff; |
igor_v | 21:bc8c1cec3da6 | 118 | CountV31 =CountV255 & 0x1f; |
igor_v | 21:bc8c1cec3da6 | 119 | CountV64 = CountV255 & 0x3f; |
igor_v | 42:6fc307c4963e | 120 | |
igor_v | 21:bc8c1cec3da6 | 121 | SetCS(ADC); //start ADC sampling |
igor_v | 21:bc8c1cec3da6 | 122 | ResetDAC(DAC); |
igor_v | 21:bc8c1cec3da6 | 123 | |
igor_v | 42:6fc307c4963e | 124 | D_QEI(); //чтение данных по счетчику |
igor_v | 42:6fc307c4963e | 125 | cheng(); // расчет вибропривода |
igor_v | 21:bc8c1cec3da6 | 126 | |
igor_v | 0:8ad47e2b6f00 | 127 | // CuruAngle = CuruAngle + Buff_32Point [CountVf] - 0xffff; |
igor_v | 21:bc8c1cec3da6 | 128 | CuruAngle = CuruAngle + Buff_32Point [CountV255] - 0xffff; |
igor_v | 21:bc8c1cec3da6 | 129 | |
igor_v | 42:6fc307c4963e | 130 | SPI_Exchange(); //Чтение ADS_SPI |
igor_v | 21:bc8c1cec3da6 | 131 | LPC_TIM1->IR = 1; |
igor_v | 21:bc8c1cec3da6 | 132 | |
igor_v | 21:bc8c1cec3da6 | 133 | } |
igor_v | 0:8ad47e2b6f00 | 134 | |
igor_v | 0:8ad47e2b6f00 | 135 | |
igor_v | 0:8ad47e2b6f00 | 136 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 137 | /////////////////////////////////////////////////TIMER2////////////////////////////////////////////////////////////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 138 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 139 | |
igor_v | 0:8ad47e2b6f00 | 140 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 141 | /////////////////////инициализация таймера 2 ///////////////////////// |
igor_v | 0:8ad47e2b6f00 | 142 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 143 | unsigned int Init_TIM2 (void) |
igor_v | 21:bc8c1cec3da6 | 144 | { |
igor_v | 21:bc8c1cec3da6 | 145 | LPC_TIM2->MR0 = 250; |
igor_v | 21:bc8c1cec3da6 | 146 | LPC_TIM2->MCR = 3; /* Interrupt and Reset on MR0 */ |
igor_v | 21:bc8c1cec3da6 | 147 | NVIC_EnableIRQ(TIMER2_IRQn); |
igor_v | 21:bc8c1cec3da6 | 148 | return 1; |
igor_v | 21:bc8c1cec3da6 | 149 | } |
igor_v | 0:8ad47e2b6f00 | 150 | |
igor_v | 15:f5191a1c3805 | 151 | |
igor_v | 15:f5191a1c3805 | 152 | |
igor_v | 21:bc8c1cec3da6 | 153 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 154 | /////////////////////////включение таймера 2////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 155 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 156 | void enable_timer2(void) |
igor_v | 21:bc8c1cec3da6 | 157 | { |
igor_v | 21:bc8c1cec3da6 | 158 | LPC_TIM2->TCR = 1; |
igor_v | 21:bc8c1cec3da6 | 159 | LPC_TIM2->TCR = 0x01; |
igor_v | 21:bc8c1cec3da6 | 160 | } |
igor_v | 21:bc8c1cec3da6 | 161 | |
igor_v | 21:bc8c1cec3da6 | 162 | |
igor_v | 21:bc8c1cec3da6 | 163 | |
igor_v | 21:bc8c1cec3da6 | 164 | /////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 165 | /////////////////////////прерывание таймера 2////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 166 | /////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 167 | __irq void TIMER2_IRQHandler (void) |
igor_v | 21:bc8c1cec3da6 | 168 | { |
igor_v | 21:bc8c1cec3da6 | 169 | LPC_TIM2->IR = 1; |
igor_v | 21:bc8c1cec3da6 | 170 | |
igor_v | 21:bc8c1cec3da6 | 171 | Global_Time++; |
igor_v | 21:bc8c1cec3da6 | 172 | |
igor_v | 21:bc8c1cec3da6 | 173 | Time_UART++; |
igor_v | 21:bc8c1cec3da6 | 174 | |
igor_v | 21:bc8c1cec3da6 | 175 | Time_vibro++; |
igor_v | 21:bc8c1cec3da6 | 176 | |
igor_v | 21:bc8c1cec3da6 | 177 | Time_1kHz++; |
igor_v | 21:bc8c1cec3da6 | 178 | |
igor_v | 21:bc8c1cec3da6 | 179 | VibroOut(); |
igor_v | 21:bc8c1cec3da6 | 180 | |
Kovalev_D | 88:b5c1d9d338d1 | 181 | Event100K --; |
igor_v | 21:bc8c1cec3da6 | 182 | |
igor_v | 21:bc8c1cec3da6 | 183 | } |