![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
forkd
Fork of LG2 by
QEI.c@0:8ad47e2b6f00, 2016-01-30 (annotated)
- Committer:
- igor_v
- Date:
- Sat Jan 30 13:00:39 2016 +0000
- Revision:
- 0:8ad47e2b6f00
- Child:
- 1:f2adcae3d304
2016_01_30;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
igor_v | 0:8ad47e2b6f00 | 1 | #include "lpc17xx.h" |
igor_v | 0:8ad47e2b6f00 | 2 | #include "QEI.h" |
igor_v | 0:8ad47e2b6f00 | 3 | #include "vibro.h" |
igor_v | 0:8ad47e2b6f00 | 4 | #include "MTimer.h" |
igor_v | 0:8ad47e2b6f00 | 5 | |
igor_v | 0:8ad47e2b6f00 | 6 | int Pulse_midl = 0; |
igor_v | 0:8ad47e2b6f00 | 7 | int PulseHalf = 0; |
igor_v | 0:8ad47e2b6f00 | 8 | int CuruAngle = 0; |
igor_v | 0:8ad47e2b6f00 | 9 | int Dif_QEI; |
igor_v | 0:8ad47e2b6f00 | 10 | int FFF=0;//äëÿ çàïëàòêè |
igor_v | 0:8ad47e2b6f00 | 11 | |
igor_v | 0:8ad47e2b6f00 | 12 | int Pulse_8Point = 0; |
igor_v | 0:8ad47e2b6f00 | 13 | int Pulse_16Point = 0; |
igor_v | 0:8ad47e2b6f00 | 14 | int Pulse_32Point = 0; |
igor_v | 0:8ad47e2b6f00 | 15 | int Pulse_16PointD = 0; |
igor_v | 0:8ad47e2b6f00 | 16 | unsigned int Iras=0,Temp_F_ras=0; |
igor_v | 0:8ad47e2b6f00 | 17 | int yy = 0; |
igor_v | 0:8ad47e2b6f00 | 18 | |
igor_v | 0:8ad47e2b6f00 | 19 | |
igor_v | 0:8ad47e2b6f00 | 20 | unsigned int Buff_32Point [256]; |
igor_v | 0:8ad47e2b6f00 | 21 | unsigned int Buff_16Point [256]; |
igor_v | 0:8ad47e2b6f00 | 22 | unsigned int Buff_16PointD [256]; |
igor_v | 0:8ad47e2b6f00 | 23 | unsigned int Buff_8Point [256]; |
igor_v | 0:8ad47e2b6f00 | 24 | unsigned int Buff_1Point [256]; |
igor_v | 0:8ad47e2b6f00 | 25 | unsigned int Buff_Restored_sin [256]; |
igor_v | 0:8ad47e2b6f00 | 26 | int unsigned Cur_QEI = 0, Last_QEI=0; |
igor_v | 0:8ad47e2b6f00 | 27 | |
igor_v | 0:8ad47e2b6f00 | 28 | |
igor_v | 0:8ad47e2b6f00 | 29 | void D_QEI(void) |
igor_v | 0:8ad47e2b6f00 | 30 | { |
igor_v | 0:8ad47e2b6f00 | 31 | Dif_QEI=0; |
igor_v | 0:8ad47e2b6f00 | 32 | |
igor_v | 0:8ad47e2b6f00 | 33 | |
igor_v | 0:8ad47e2b6f00 | 34 | Cur_QEI = LPC_QEI->POS & 0xFFFF; // ñ÷èòûâàíèå òåêóùåãî çíà÷åíèÿ ýíêîäåðà. |
igor_v | 0:8ad47e2b6f00 | 35 | Dif_QEI = (Cur_QEI - Last_QEI); // ïîëó÷åíèå ïðèðàùåíèÿ.() |
igor_v | 0:8ad47e2b6f00 | 36 | Last_QEI = Cur_QEI; // çàïèñü òåêóùåãî çíà÷åíèÿ ýíêîäåðà â ðåãèñòð ïðåäûäóùåãî çíà÷åíèÿ. |
igor_v | 0:8ad47e2b6f00 | 37 | |
igor_v | 0:8ad47e2b6f00 | 38 | |
igor_v | 0:8ad47e2b6f00 | 39 | if (Dif_QEI < -0xfff) Dif_QEI += 0x10000; // îáðàáîòêà ïðîõîäà çíà÷åíèÿ ÷åðåç íîëü |
igor_v | 0:8ad47e2b6f00 | 40 | if (Dif_QEI > 0xfff) Dif_QEI -= 0x10000; // îáðàáîòêà ïðîõîäà çíà÷åíèÿ ÷åðåç íîëü |
igor_v | 0:8ad47e2b6f00 | 41 | |
igor_v | 0:8ad47e2b6f00 | 42 | |
igor_v | 0:8ad47e2b6f00 | 43 | Buff_1Point[CountV255] = (unsigned int) (Dif_QEI + 0xffff);// íàêîïëåíèå â áóôåð åäåíè÷íûõ çíà÷åíèé ïðèðàùåíèÿ ïî êàæäîìó òàêòó. |
igor_v | 0:8ad47e2b6f00 | 44 | |
igor_v | 0:8ad47e2b6f00 | 45 | //////////////////////////////////////////////////////////////////////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 46 | /////////////////////////////////////////////////////////////////////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 47 | |
igor_v | 0:8ad47e2b6f00 | 48 | if (LPC_QEI->STAT) //e. "+" direction //r. ñòàëè âðàùàòüñÿ â "+" ñòîðîíó |
igor_v | 0:8ad47e2b6f00 | 49 | { |
igor_v | 0:8ad47e2b6f00 | 50 | Main.Cnt_Mns = Dif_QEI; |
igor_v | 0:8ad47e2b6f00 | 51 | } |
igor_v | 0:8ad47e2b6f00 | 52 | else |
igor_v | 0:8ad47e2b6f00 | 53 | { |
igor_v | 0:8ad47e2b6f00 | 54 | Main.Cnt_Pls = -Dif_QEI; |
igor_v | 0:8ad47e2b6f00 | 55 | } |
igor_v | 0:8ad47e2b6f00 | 56 | ////////// ???? Çàïëàòêà |
igor_v | 0:8ad47e2b6f00 | 57 | ////////// ???? Ïðîáëåìà íà÷àëüíîãî çàïîëíåíèÿ áóôåðîâ |
igor_v | 0:8ad47e2b6f00 | 58 | ////////////////////////////////////////////////////////////////////////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 59 | if(FFF==1) // åñëè ïðîøëî 32 òàêòà âèáðî ïîäâåñà íà÷àòü çàïîëíÿòü îñòàëüíûå áóâåðû. |
igor_v | 0:8ad47e2b6f00 | 60 | { |
igor_v | 0:8ad47e2b6f00 | 61 | Pulse_8Point += Buff_1Point[CountV255]; |
igor_v | 0:8ad47e2b6f00 | 62 | Pulse_8Point -= Buff_1Point[(CountV255-8) & 0xff]; // çàïîëíåíèå áóôåðà íàêîïëåíûõ ïðèðàùåíèé çà 8 òàêòîâ |
igor_v | 0:8ad47e2b6f00 | 63 | Buff_8Point[CountV255] = (unsigned int) (Pulse_8Point + 0xffff); |
igor_v | 0:8ad47e2b6f00 | 64 | |
igor_v | 0:8ad47e2b6f00 | 65 | Pulse_16Point += Buff_1Point[CountV255]; |
igor_v | 0:8ad47e2b6f00 | 66 | Pulse_16Point -= Buff_1Point[(CountV255-16) & 0xff]; // çàïîëíåíèå áóôåðà íàêîïëåíûõ ïðèðàùåíèé çà 16 òàêòîâ |
igor_v | 0:8ad47e2b6f00 | 67 | Buff_16Point[CountV255] = (unsigned int) (Pulse_16Point + 0xffff); |
igor_v | 0:8ad47e2b6f00 | 68 | |
igor_v | 0:8ad47e2b6f00 | 69 | Pulse_32Point += Buff_1Point[CountV255]; |
igor_v | 0:8ad47e2b6f00 | 70 | Pulse_32Point -= Buff_1Point[(CountV255-32) & 0xff]; // çàïîëíåíèå áóôåðà íàêîïëåíûõ ïðèðàùåíèé çà 32 òàêòîâ |
igor_v | 0:8ad47e2b6f00 | 71 | Main.Cnt_Dif = (Pulse_32Point+ 0xffff); |
igor_v | 0:8ad47e2b6f00 | 72 | Buff_32Point[CountV255] = (unsigned int) (Pulse_32Point + 0xffff); |
igor_v | 0:8ad47e2b6f00 | 73 | |
igor_v | 0:8ad47e2b6f00 | 74 | Pulse_16PointD += Buff_1Point[CountV255]; |
igor_v | 0:8ad47e2b6f00 | 75 | Pulse_16PointD -= Buff_1Point[(CountV255-16) & 0xff]; // çàïîëíåíèå áóôåðà íàêîïëåíûõ ïðèðàùåíèé çà 16 òàêòîâ Äâîéíûç |
igor_v | 0:8ad47e2b6f00 | 76 | Pulse_16PointD += Buff_1Point[(CountV255-32) & 0xff]; // |
igor_v | 0:8ad47e2b6f00 | 77 | Pulse_16PointD -= Buff_1Point[(CountV255-48) & 0xff]; // ç |
igor_v | 0:8ad47e2b6f00 | 78 | |
igor_v | 0:8ad47e2b6f00 | 79 | Buff_16PointD[CountV255] = (unsigned int) (Pulse_16PointD + 0xffff); |
igor_v | 0:8ad47e2b6f00 | 80 | |
igor_v | 0:8ad47e2b6f00 | 81 | |
igor_v | 0:8ad47e2b6f00 | 82 | // Buff_Restored_sin [CountVf]= (unsigned int)( ((Buff_16Point[CountVf]*2)) - Buff_32Point[CountVf] ); |
igor_v | 0:8ad47e2b6f00 | 83 | |
igor_v | 0:8ad47e2b6f00 | 84 | Buff_Restored_sin [CountV255]= (unsigned int)( Buff_16PointD [ CountV255] + 65536 - Buff_32Point[CountV255] ); |
igor_v | 0:8ad47e2b6f00 | 85 | |
igor_v | 0:8ad47e2b6f00 | 86 | |
igor_v | 0:8ad47e2b6f00 | 87 | |
igor_v | 0:8ad47e2b6f00 | 88 | if(Buff_32Point[CountV255]>0) |
igor_v | 0:8ad47e2b6f00 | 89 | { |
igor_v | 0:8ad47e2b6f00 | 90 | Temp_F_ras += Buff_32Point[CountV255]; |
igor_v | 0:8ad47e2b6f00 | 91 | } |
igor_v | 0:8ad47e2b6f00 | 92 | else if ((CountV255 & 0x1f)==0) |
igor_v | 0:8ad47e2b6f00 | 93 | { |
igor_v | 0:8ad47e2b6f00 | 94 | Main.F_ras=Temp_F_ras; |
igor_v | 0:8ad47e2b6f00 | 95 | Temp_F_ras=0; |
igor_v | 0:8ad47e2b6f00 | 96 | } |
igor_v | 0:8ad47e2b6f00 | 97 | else |
igor_v | 0:8ad47e2b6f00 | 98 | { |
igor_v | 0:8ad47e2b6f00 | 99 | Temp_F_ras -= Buff_32Point[CountV255]; |
igor_v | 0:8ad47e2b6f00 | 100 | } |
igor_v | 0:8ad47e2b6f00 | 101 | |
igor_v | 0:8ad47e2b6f00 | 102 | //unsigned int T_Vib; |
igor_v | 0:8ad47e2b6f00 | 103 | |
igor_v | 0:8ad47e2b6f00 | 104 | } |
igor_v | 0:8ad47e2b6f00 | 105 | else if(CountV255 == 255) |
igor_v | 0:8ad47e2b6f00 | 106 | { |
igor_v | 0:8ad47e2b6f00 | 107 | FFF=1;//âðåìåííàÿ çàïëàòêà äëÿ ïàóçû ïåðåä çàïîëíåíèåì îñòàëüíûõ áóôåðîâ |
igor_v | 0:8ad47e2b6f00 | 108 | for (yy = 0; yy < 256; yy++ ) |
igor_v | 0:8ad47e2b6f00 | 109 | { |
igor_v | 0:8ad47e2b6f00 | 110 | Buff_1Point [yy] = 0xffff; |
igor_v | 0:8ad47e2b6f00 | 111 | Buff_16Point [yy] = 0xffff; |
igor_v | 0:8ad47e2b6f00 | 112 | Buff_32Point [yy] = 0xffff; |
igor_v | 0:8ad47e2b6f00 | 113 | Buff_16PointD [yy] = 0xffff; |
igor_v | 0:8ad47e2b6f00 | 114 | } |
igor_v | 0:8ad47e2b6f00 | 115 | |
igor_v | 0:8ad47e2b6f00 | 116 | } |
igor_v | 0:8ad47e2b6f00 | 117 | } |
igor_v | 0:8ad47e2b6f00 | 118 |