![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
forkd
Fork of LG2 by
MTimer.c@49:53277d871197, 2016-02-11 (annotated)
- Committer:
- Diletant
- Date:
- Thu Feb 11 02:55:35 2016 +0000
- Revision:
- 49:53277d871197
- Parent:
- 47:d902ef6f7564
- Child:
- 88:b5c1d9d338d1
More comments
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; |
igor_v | 21:bc8c1cec3da6 | 21 | unsigned int init_timer (unsigned int TimerInterval ) |
igor_v | 21:bc8c1cec3da6 | 22 | { |
igor_v | 21:bc8c1cec3da6 | 23 | //start DAC prepearing for writing |
Diletant | 49:53277d871197 | 24 | //Match Register 0 |
igor_v | 21:bc8c1cec3da6 | 25 | LPC_TIM1->MR0 = TimerInterval; |
Diletant | 49:53277d871197 | 26 | //Match Control Register. The MCR is used to control if an interrupt is generated and if the TC is reset when a Match occurs |
igor_v | 21:bc8c1cec3da6 | 27 | LPC_TIM1->MCR = 3; /* Interrupt and Reset on MR1 */ |
igor_v | 21:bc8c1cec3da6 | 28 | NVIC_EnableIRQ(TIMER1_IRQn); |
igor_v | 21:bc8c1cec3da6 | 29 | //LPC_GPIO0->FIOSET |= (1<<5); |
igor_v | 21:bc8c1cec3da6 | 30 | |
igor_v | 21:bc8c1cec3da6 | 31 | return 0; |
igor_v | 21:bc8c1cec3da6 | 32 | } |
igor_v | 21:bc8c1cec3da6 | 33 | |
igor_v | 21:bc8c1cec3da6 | 34 | |
igor_v | 0:8ad47e2b6f00 | 35 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 36 | /////////////////////////включение таймера 1////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 37 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 38 | void enable_timer1( void ) |
igor_v | 21:bc8c1cec3da6 | 39 | { |
igor_v | 21:bc8c1cec3da6 | 40 | LPC_TIM1->TCR = 1; |
igor_v | 21:bc8c1cec3da6 | 41 | return; |
igor_v | 21:bc8c1cec3da6 | 42 | } |
igor_v | 21:bc8c1cec3da6 | 43 | |
igor_v | 21:bc8c1cec3da6 | 44 | |
igor_v | 0:8ad47e2b6f00 | 45 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 46 | /////////////////////////прерывание таймера 1////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 47 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 48 | __irq void TIMER1_IRQHandler (void) |
igor_v | 21:bc8c1cec3da6 | 49 | { |
igor_v | 21:bc8c1cec3da6 | 50 | //LoopOn |
igor_v | 21:bc8c1cec3da6 | 51 | |
igor_v | 21:bc8c1cec3da6 | 52 | // Init_SPI_Exchange();// CS |
igor_v | 21:bc8c1cec3da6 | 53 | ResetCS(ADC); //prepare ADC for sampling |
igor_v | 21:bc8c1cec3da6 | 54 | SetDAC(DAC); |
igor_v | 21:bc8c1cec3da6 | 55 | |
igor_v | 21:bc8c1cec3da6 | 56 | CountV255++; |
igor_v | 21:bc8c1cec3da6 | 57 | CountV255 &= 0xff; |
igor_v | 21:bc8c1cec3da6 | 58 | CountV31 =CountV255 & 0x1f; |
igor_v | 21:bc8c1cec3da6 | 59 | CountV64 = CountV255 & 0x3f; |
igor_v | 42:6fc307c4963e | 60 | |
igor_v | 21:bc8c1cec3da6 | 61 | SetCS(ADC); //start ADC sampling |
igor_v | 21:bc8c1cec3da6 | 62 | ResetDAC(DAC); |
igor_v | 21:bc8c1cec3da6 | 63 | |
igor_v | 42:6fc307c4963e | 64 | D_QEI(); //чтение данных по счетчику |
igor_v | 42:6fc307c4963e | 65 | cheng(); // расчет вибропривода |
igor_v | 21:bc8c1cec3da6 | 66 | |
igor_v | 0:8ad47e2b6f00 | 67 | // CuruAngle = CuruAngle + Buff_32Point [CountVf] - 0xffff; |
igor_v | 21:bc8c1cec3da6 | 68 | CuruAngle = CuruAngle + Buff_32Point [CountV255] - 0xffff; |
igor_v | 21:bc8c1cec3da6 | 69 | |
igor_v | 42:6fc307c4963e | 70 | SPI_Exchange(); //Чтение ADS_SPI |
igor_v | 21:bc8c1cec3da6 | 71 | LPC_TIM1->IR = 1; |
igor_v | 21:bc8c1cec3da6 | 72 | |
igor_v | 21:bc8c1cec3da6 | 73 | } |
igor_v | 0:8ad47e2b6f00 | 74 | |
igor_v | 0:8ad47e2b6f00 | 75 | |
igor_v | 0:8ad47e2b6f00 | 76 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 77 | /////////////////////////////////////////////////TIMER2////////////////////////////////////////////////////////////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 78 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 79 | |
igor_v | 0:8ad47e2b6f00 | 80 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 81 | /////////////////////инициализация таймера 2 ///////////////////////// |
igor_v | 0:8ad47e2b6f00 | 82 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 83 | unsigned int Init_TIM2 (void) |
igor_v | 21:bc8c1cec3da6 | 84 | { |
igor_v | 21:bc8c1cec3da6 | 85 | LPC_TIM2->MR0 = 250; |
igor_v | 21:bc8c1cec3da6 | 86 | LPC_TIM2->MCR = 3; /* Interrupt and Reset on MR0 */ |
igor_v | 21:bc8c1cec3da6 | 87 | NVIC_EnableIRQ(TIMER2_IRQn); |
igor_v | 21:bc8c1cec3da6 | 88 | return 1; |
igor_v | 21:bc8c1cec3da6 | 89 | } |
igor_v | 0:8ad47e2b6f00 | 90 | |
igor_v | 15:f5191a1c3805 | 91 | |
igor_v | 15:f5191a1c3805 | 92 | |
igor_v | 21:bc8c1cec3da6 | 93 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 94 | /////////////////////////включение таймера 2////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 95 | ////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 96 | void enable_timer2(void) |
igor_v | 21:bc8c1cec3da6 | 97 | { |
igor_v | 21:bc8c1cec3da6 | 98 | LPC_TIM2->TCR = 1; |
igor_v | 21:bc8c1cec3da6 | 99 | LPC_TIM2->TCR = 0x01; |
igor_v | 21:bc8c1cec3da6 | 100 | } |
igor_v | 21:bc8c1cec3da6 | 101 | |
igor_v | 21:bc8c1cec3da6 | 102 | |
igor_v | 21:bc8c1cec3da6 | 103 | |
igor_v | 21:bc8c1cec3da6 | 104 | /////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 105 | /////////////////////////прерывание таймера 2////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 106 | /////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 107 | __irq void TIMER2_IRQHandler (void) |
igor_v | 21:bc8c1cec3da6 | 108 | { |
igor_v | 21:bc8c1cec3da6 | 109 | LPC_TIM2->IR = 1; |
igor_v | 21:bc8c1cec3da6 | 110 | |
igor_v | 21:bc8c1cec3da6 | 111 | Global_Time++; |
igor_v | 21:bc8c1cec3da6 | 112 | |
igor_v | 21:bc8c1cec3da6 | 113 | Time_UART++; |
igor_v | 21:bc8c1cec3da6 | 114 | |
igor_v | 21:bc8c1cec3da6 | 115 | Time_vibro++; |
igor_v | 21:bc8c1cec3da6 | 116 | |
igor_v | 21:bc8c1cec3da6 | 117 | Time_1kHz++; |
igor_v | 21:bc8c1cec3da6 | 118 | |
igor_v | 21:bc8c1cec3da6 | 119 | VibroOut(); |
igor_v | 21:bc8c1cec3da6 | 120 | |
Kovalev_D | 47:d902ef6f7564 | 121 | Event100K --; |
igor_v | 21:bc8c1cec3da6 | 122 | |
igor_v | 21:bc8c1cec3da6 | 123 | } |