![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
forkd
Fork of LGstaandart by
QEI.c@42:6fc307c4963e, 2016-02-07 (annotated)
- Committer:
- igor_v
- Date:
- Sun Feb 07 12:24:11 2016 +0000
- Revision:
- 42:6fc307c4963e
- Parent:
- 30:17c84ed091b3
- Child:
- 43:3f7c8a0ea59c
;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
igor_v | 1:f2adcae3d304 | 1 | #include "Global.h" |
igor_v | 0:8ad47e2b6f00 | 2 | |
igor_v | 21:bc8c1cec3da6 | 3 | |
igor_v | 21:bc8c1cec3da6 | 4 | int Pulse_midl = 0; |
igor_v | 21:bc8c1cec3da6 | 5 | int PulseHalf = 0; |
igor_v | 21:bc8c1cec3da6 | 6 | int CuruAngle = 0; |
igor_v | 21:bc8c1cec3da6 | 7 | int Dif_QEI; |
igor_v | 42:6fc307c4963e | 8 | |
igor_v | 21:bc8c1cec3da6 | 9 | int FFF=0;//для заплатки |
igor_v | 0:8ad47e2b6f00 | 10 | |
igor_v | 42:6fc307c4963e | 11 | |
igor_v | 21:bc8c1cec3da6 | 12 | int Pulse_8Point = 0; |
igor_v | 21:bc8c1cec3da6 | 13 | int Pulse_16Point = 0; |
igor_v | 21:bc8c1cec3da6 | 14 | int Pulse_32Point = 0; |
igor_v | 21:bc8c1cec3da6 | 15 | int Pulse_16PointD = 0; |
igor_v | 21:bc8c1cec3da6 | 16 | unsigned int Iras=0,Temp_F_ras=0; |
igor_v | 21:bc8c1cec3da6 | 17 | int yy = 0; |
igor_v | 0:8ad47e2b6f00 | 18 | |
igor_v | 0:8ad47e2b6f00 | 19 | |
igor_v | 42:6fc307c4963e | 20 | |
igor_v | 42:6fc307c4963e | 21 | |
igor_v | 42:6fc307c4963e | 22 | /* |
igor_v | 42:6fc307c4963e | 23 | unsigned int Buff_32Point [256]; |
igor_v | 42:6fc307c4963e | 24 | unsigned int Buff_16Point [256]; |
igor_v | 42:6fc307c4963e | 25 | unsigned int Buff_16PointD [256]; |
igor_v | 42:6fc307c4963e | 26 | unsigned int Buff_8Point [256]; |
igor_v | 42:6fc307c4963e | 27 | unsigned int Buff_1Point [256]; |
igor_v | 21:bc8c1cec3da6 | 28 | unsigned int Buff_Restored_sin [256]; |
igor_v | 42:6fc307c4963e | 29 | |
igor_v | 42:6fc307c4963e | 30 | */ |
igor_v | 42:6fc307c4963e | 31 | |
igor_v | 42:6fc307c4963e | 32 | int Buff_32Point [32]; // давай сделаем буфера поменьше |
igor_v | 42:6fc307c4963e | 33 | int Buff_16Point [32]; |
igor_v | 42:6fc307c4963e | 34 | int Buff_16PointD [32]; |
igor_v | 42:6fc307c4963e | 35 | int Buff_8Point [32]; |
igor_v | 42:6fc307c4963e | 36 | int Buff_Restored_sin [32]; |
igor_v | 42:6fc307c4963e | 37 | |
igor_v | 42:6fc307c4963e | 38 | int Buff_1Point [256]; // этот на 256 |
igor_v | 42:6fc307c4963e | 39 | |
igor_v | 42:6fc307c4963e | 40 | |
igor_v | 42:6fc307c4963e | 41 | |
igor_v | 21:bc8c1cec3da6 | 42 | int unsigned Cur_QEI = 0, Last_QEI=0; |
igor_v | 21:bc8c1cec3da6 | 43 | |
igor_v | 21:bc8c1cec3da6 | 44 | |
igor_v | 42:6fc307c4963e | 45 | |
igor_v | 42:6fc307c4963e | 46 | |
igor_v | 42:6fc307c4963e | 47 | |
igor_v | 42:6fc307c4963e | 48 | |
igor_v | 42:6fc307c4963e | 49 | |
igor_v | 42:6fc307c4963e | 50 | // ДАВАЙ попробуем сделать бушера в целых (знаковы) |
igor_v | 42:6fc307c4963e | 51 | void D_QEI_Int(void) |
igor_v | 42:6fc307c4963e | 52 | { |
igor_v | 42:6fc307c4963e | 53 | |
igor_v | 42:6fc307c4963e | 54 | Cur_QEI = LPC_QEI->POS & 0xFFFF; // считывание текущего значения энкодера. |
igor_v | 42:6fc307c4963e | 55 | Dif_QEI = (Cur_QEI - Last_QEI); // получение приращения.() |
igor_v | 42:6fc307c4963e | 56 | Last_QEI = Cur_QEI; // запись текущего значения энкодера в регистр предыдущего значения. |
igor_v | 42:6fc307c4963e | 57 | |
igor_v | 42:6fc307c4963e | 58 | if (Dif_QEI < -0xfff) Dif_QEI += 0x10000; // обработка прохода значения через ноль |
igor_v | 42:6fc307c4963e | 59 | if (Dif_QEI > 0xfff) Dif_QEI -= 0x10000; // обработка прохода значения через ноль |
igor_v | 42:6fc307c4963e | 60 | |
igor_v | 42:6fc307c4963e | 61 | |
igor_v | 42:6fc307c4963e | 62 | Buff_1Point[CountV255] = Dif_QEI;// накопление в буфер еденичных значений приращения по каждому такту. |
igor_v | 42:6fc307c4963e | 63 | |
igor_v | 42:6fc307c4963e | 64 | //////////////////////////////////////////////////////////////////////////////////////////// |
igor_v | 42:6fc307c4963e | 65 | /////////////////////////////////////////////////////////////////////////////////////////// |
igor_v | 42:6fc307c4963e | 66 | |
igor_v | 42:6fc307c4963e | 67 | // зачем это. мож к этому воремени стали вращатся назад |
igor_v | 42:6fc307c4963e | 68 | |
igor_v | 42:6fc307c4963e | 69 | if (LPC_QEI->STAT) { //e. "+" direction //r. стали вращаться в "+" |
igor_v | 42:6fc307c4963e | 70 | Gyro.Cnt_Mns = Dif_QEI; |
igor_v | 42:6fc307c4963e | 71 | } else { |
igor_v | 42:6fc307c4963e | 72 | Gyro.Cnt_Pls = -Dif_QEI; |
igor_v | 42:6fc307c4963e | 73 | } |
igor_v | 42:6fc307c4963e | 74 | |
igor_v | 42:6fc307c4963e | 75 | |
igor_v | 42:6fc307c4963e | 76 | |
igor_v | 42:6fc307c4963e | 77 | ////////// ???? Заплатка |
igor_v | 42:6fc307c4963e | 78 | ////////// ???? Проблема начального заполнения буферов |
igor_v | 42:6fc307c4963e | 79 | ////////////////////////////////////////////////////////////////////////////////////////////// |
igor_v | 42:6fc307c4963e | 80 | // если прошло 32 такта вибро подвеса начать заполнять остальные буверы. |
igor_v | 42:6fc307c4963e | 81 | Pulse_8Point += Buff_1Point[CountV255]; |
igor_v | 42:6fc307c4963e | 82 | Pulse_8Point -= Buff_1Point[(CountV255-8) & 0xff]; // заполнение буфера накопленых приращений за 8 тактов |
igor_v | 42:6fc307c4963e | 83 | Buff_8Point[CountV31] =Pulse_8Point; |
igor_v | 42:6fc307c4963e | 84 | |
igor_v | 42:6fc307c4963e | 85 | Pulse_16Point += Buff_1Point[CountV255]; |
igor_v | 42:6fc307c4963e | 86 | Pulse_16Point -= Buff_1Point[(CountV255-16) & 0xff]; // заполнение буфера накопленых приращений за 16 тактов |
igor_v | 42:6fc307c4963e | 87 | Buff_16Point[CountV31] = Pulse_16Point; |
igor_v | 42:6fc307c4963e | 88 | |
igor_v | 42:6fc307c4963e | 89 | Pulse_32Point += Buff_1Point[CountV255]; |
igor_v | 42:6fc307c4963e | 90 | Pulse_32Point -= Buff_1Point[(CountV255-32) & 0xff]; // заполнение буфера накопленых приращений за 32 тактов |
igor_v | 42:6fc307c4963e | 91 | Buff_32Point[CountV31] = Pulse_32Point; |
igor_v | 42:6fc307c4963e | 92 | |
igor_v | 42:6fc307c4963e | 93 | |
igor_v | 42:6fc307c4963e | 94 | |
igor_v | 42:6fc307c4963e | 95 | |
igor_v | 42:6fc307c4963e | 96 | Gyro.Cnt_Dif = (Pulse_32Point); |
igor_v | 42:6fc307c4963e | 97 | |
igor_v | 42:6fc307c4963e | 98 | Pulse_16PointD += Buff_1Point[CountV255]; |
igor_v | 42:6fc307c4963e | 99 | Pulse_16PointD -= Buff_1Point[(CountV255-16) & 0xff]; // заполнение буфера накопленых приращений за 16 тактов Двойныз |
igor_v | 42:6fc307c4963e | 100 | Pulse_16PointD += Buff_1Point[(CountV255-32) & 0xff]; // |
igor_v | 42:6fc307c4963e | 101 | Pulse_16PointD -= Buff_1Point[(CountV255-48) & 0xff]; // з |
igor_v | 42:6fc307c4963e | 102 | |
igor_v | 42:6fc307c4963e | 103 | Buff_16PointD[CountV31] = Pulse_16PointD; |
igor_v | 42:6fc307c4963e | 104 | |
igor_v | 42:6fc307c4963e | 105 | |
igor_v | 42:6fc307c4963e | 106 | // Buff_Restored_sin [CountVf]= (unsigned int)( ((Buff_16Point[CountVf]*2)) - Buff_32Point[CountVf] ); |
igor_v | 42:6fc307c4963e | 107 | |
igor_v | 42:6fc307c4963e | 108 | Buff_Restored_sin [CountV31]= Buff_16PointD [ CountV31] - Buff_32Point[CountV31]; |
igor_v | 42:6fc307c4963e | 109 | |
igor_v | 42:6fc307c4963e | 110 | |
igor_v | 42:6fc307c4963e | 111 | |
igor_v | 42:6fc307c4963e | 112 | if(Buff_32Point[CountV255]>0) { |
igor_v | 42:6fc307c4963e | 113 | Temp_F_ras += Buff_32Point[CountV255]; |
igor_v | 42:6fc307c4963e | 114 | } else if ((CountV255 & 0x1f)==0) { |
igor_v | 42:6fc307c4963e | 115 | Gyro.F_ras=Temp_F_ras; |
igor_v | 42:6fc307c4963e | 116 | Temp_F_ras=0; |
igor_v | 42:6fc307c4963e | 117 | } else { |
igor_v | 42:6fc307c4963e | 118 | Temp_F_ras -= Buff_32Point[CountV255]; |
igor_v | 42:6fc307c4963e | 119 | } |
igor_v | 42:6fc307c4963e | 120 | |
igor_v | 42:6fc307c4963e | 121 | //unsigned int T_Vib; |
igor_v | 42:6fc307c4963e | 122 | |
igor_v | 42:6fc307c4963e | 123 | } |
igor_v | 42:6fc307c4963e | 124 | |
igor_v | 42:6fc307c4963e | 125 | |
igor_v | 42:6fc307c4963e | 126 | |
igor_v | 42:6fc307c4963e | 127 | |
igor_v | 42:6fc307c4963e | 128 | |
igor_v | 42:6fc307c4963e | 129 | |
igor_v | 42:6fc307c4963e | 130 | |
igor_v | 42:6fc307c4963e | 131 | |
igor_v | 42:6fc307c4963e | 132 | |
igor_v | 42:6fc307c4963e | 133 | |
igor_v | 42:6fc307c4963e | 134 | |
igor_v | 21:bc8c1cec3da6 | 135 | void D_QEI(void) |
igor_v | 21:bc8c1cec3da6 | 136 | { |
igor_v | 21:bc8c1cec3da6 | 137 | Dif_QEI=0; |
igor_v | 21:bc8c1cec3da6 | 138 | Cur_QEI = LPC_QEI->POS & 0xFFFF; // считывание текущего значения энкодера. |
igor_v | 21:bc8c1cec3da6 | 139 | Dif_QEI = (Cur_QEI - Last_QEI); // получение приращения.() |
igor_v | 21:bc8c1cec3da6 | 140 | Last_QEI = Cur_QEI; // запись текущего значения энкодера в регистр предыдущего значения. |
igor_v | 21:bc8c1cec3da6 | 141 | |
igor_v | 21:bc8c1cec3da6 | 142 | if (Dif_QEI < -0xfff) Dif_QEI += 0x10000; // обработка прохода значения через ноль |
igor_v | 21:bc8c1cec3da6 | 143 | if (Dif_QEI > 0xfff) Dif_QEI -= 0x10000; // обработка прохода значения через ноль |
igor_v | 0:8ad47e2b6f00 | 144 | |
igor_v | 0:8ad47e2b6f00 | 145 | |
igor_v | 21:bc8c1cec3da6 | 146 | Buff_1Point[CountV255] = (unsigned int) (Dif_QEI + 0xffff);// накопление в буфер еденичных значений приращения по каждому такту. |
igor_v | 21:bc8c1cec3da6 | 147 | |
igor_v | 21:bc8c1cec3da6 | 148 | //////////////////////////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 149 | /////////////////////////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 150 | |
igor_v | 21:bc8c1cec3da6 | 151 | if (LPC_QEI->STAT) { //e. "+" direction //r. стали вращаться в "+" сторону |
igor_v | 30:17c84ed091b3 | 152 | Gyro.Cnt_Mns = Dif_QEI; |
igor_v | 21:bc8c1cec3da6 | 153 | } else { |
igor_v | 30:17c84ed091b3 | 154 | Gyro.Cnt_Pls = -Dif_QEI; |
igor_v | 21:bc8c1cec3da6 | 155 | } |
igor_v | 42:6fc307c4963e | 156 | |
igor_v | 21:bc8c1cec3da6 | 157 | ////////// ???? Заплатка |
igor_v | 21:bc8c1cec3da6 | 158 | ////////// ???? Проблема начального заполнения буферов |
igor_v | 21:bc8c1cec3da6 | 159 | ////////////////////////////////////////////////////////////////////////////////////////////// |
igor_v | 21:bc8c1cec3da6 | 160 | if(FFF==1) { // если прошло 32 такта вибро подвеса начать заполнять остальные буверы. |
igor_v | 21:bc8c1cec3da6 | 161 | Pulse_8Point += Buff_1Point[CountV255]; |
igor_v | 21:bc8c1cec3da6 | 162 | Pulse_8Point -= Buff_1Point[(CountV255-8) & 0xff]; // заполнение буфера накопленых приращений за 8 тактов |
igor_v | 21:bc8c1cec3da6 | 163 | Buff_8Point[CountV255] = (unsigned int) (Pulse_8Point + 0xffff); |
igor_v | 0:8ad47e2b6f00 | 164 | |
igor_v | 21:bc8c1cec3da6 | 165 | Pulse_16Point += Buff_1Point[CountV255]; |
igor_v | 21:bc8c1cec3da6 | 166 | Pulse_16Point -= Buff_1Point[(CountV255-16) & 0xff]; // заполнение буфера накопленых приращений за 16 тактов |
igor_v | 21:bc8c1cec3da6 | 167 | Buff_16Point[CountV255] = (unsigned int) (Pulse_16Point + 0xffff); |
igor_v | 21:bc8c1cec3da6 | 168 | |
igor_v | 21:bc8c1cec3da6 | 169 | Pulse_32Point += Buff_1Point[CountV255]; |
igor_v | 21:bc8c1cec3da6 | 170 | Pulse_32Point -= Buff_1Point[(CountV255-32) & 0xff]; // заполнение буфера накопленых приращений за 32 тактов |
igor_v | 30:17c84ed091b3 | 171 | Gyro.Cnt_Dif = (Pulse_32Point+ 0xffff); |
igor_v | 21:bc8c1cec3da6 | 172 | Buff_32Point[CountV255] = (unsigned int) (Pulse_32Point + 0xffff); |
igor_v | 0:8ad47e2b6f00 | 173 | |
igor_v | 21:bc8c1cec3da6 | 174 | Pulse_16PointD += Buff_1Point[CountV255]; |
igor_v | 21:bc8c1cec3da6 | 175 | Pulse_16PointD -= Buff_1Point[(CountV255-16) & 0xff]; // заполнение буфера накопленых приращений за 16 тактов Двойныз |
igor_v | 21:bc8c1cec3da6 | 176 | Pulse_16PointD += Buff_1Point[(CountV255-32) & 0xff]; // |
igor_v | 21:bc8c1cec3da6 | 177 | Pulse_16PointD -= Buff_1Point[(CountV255-48) & 0xff]; // з |
igor_v | 21:bc8c1cec3da6 | 178 | |
igor_v | 21:bc8c1cec3da6 | 179 | Buff_16PointD[CountV255] = (unsigned int) (Pulse_16PointD + 0xffff); |
igor_v | 21:bc8c1cec3da6 | 180 | |
igor_v | 21:bc8c1cec3da6 | 181 | |
igor_v | 0:8ad47e2b6f00 | 182 | // Buff_Restored_sin [CountVf]= (unsigned int)( ((Buff_16Point[CountVf]*2)) - Buff_32Point[CountVf] ); |
igor_v | 0:8ad47e2b6f00 | 183 | |
igor_v | 21:bc8c1cec3da6 | 184 | Buff_Restored_sin [CountV255]= (unsigned int)( Buff_16PointD [ CountV255] + 65536 - Buff_32Point[CountV255] ); |
igor_v | 21:bc8c1cec3da6 | 185 | |
igor_v | 0:8ad47e2b6f00 | 186 | |
igor_v | 0:8ad47e2b6f00 | 187 | |
igor_v | 21:bc8c1cec3da6 | 188 | if(Buff_32Point[CountV255]>0) { |
igor_v | 21:bc8c1cec3da6 | 189 | Temp_F_ras += Buff_32Point[CountV255]; |
igor_v | 21:bc8c1cec3da6 | 190 | } else if ((CountV255 & 0x1f)==0) { |
igor_v | 30:17c84ed091b3 | 191 | Gyro.F_ras=Temp_F_ras; |
igor_v | 21:bc8c1cec3da6 | 192 | Temp_F_ras=0; |
igor_v | 21:bc8c1cec3da6 | 193 | } else { |
igor_v | 21:bc8c1cec3da6 | 194 | Temp_F_ras -= Buff_32Point[CountV255]; |
igor_v | 21:bc8c1cec3da6 | 195 | } |
igor_v | 21:bc8c1cec3da6 | 196 | |
igor_v | 21:bc8c1cec3da6 | 197 | //unsigned int T_Vib; |
igor_v | 0:8ad47e2b6f00 | 198 | |
igor_v | 21:bc8c1cec3da6 | 199 | } else if(CountV255 == 255) { |
igor_v | 21:bc8c1cec3da6 | 200 | FFF=1;//временная заплатка для паузы перед заполнением остальных буферов |
igor_v | 21:bc8c1cec3da6 | 201 | for (yy = 0; yy < 256; yy++ ) { |
igor_v | 21:bc8c1cec3da6 | 202 | Buff_1Point [yy] = 0xffff; |
igor_v | 21:bc8c1cec3da6 | 203 | Buff_16Point [yy] = 0xffff; |
igor_v | 21:bc8c1cec3da6 | 204 | Buff_32Point [yy] = 0xffff; |
igor_v | 21:bc8c1cec3da6 | 205 | Buff_16PointD [yy] = 0xffff; |
igor_v | 21:bc8c1cec3da6 | 206 | } |
igor_v | 0:8ad47e2b6f00 | 207 | |
igor_v | 21:bc8c1cec3da6 | 208 | } |
igor_v | 21:bc8c1cec3da6 | 209 | } |