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