![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
fork
Fork of LG by
vibro.c@210:b02fa166315d, 2017-04-24 (annotated)
- Committer:
- Kovalev_D
- Date:
- Mon Apr 24 05:43:54 2017 +0000
- Revision:
- 210:b02fa166315d
- Parent:
- 209:224e7331a061
- Child:
- 211:ac8251b067d2
123
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
igor_v | 0:8ad47e2b6f00 | 1 | #include "Global.h" |
igor_v | 30:17c84ed091b3 | 2 | GyroT Gyro; |
Kovalev_D | 129:406995a91322 | 3 | GyroParam GyroP; |
Kovalev_D | 112:4a96133a1311 | 4 | volatile unsigned int Cheng_AMP_Flag=0; |
Kovalev_D | 190:289514f730ee | 5 | //int reper=0; |
Kovalev_D | 193:a0fe8bfc97e4 | 6 | int Rate2VibFlag,countA=0,tempDP,vibrot=0,fnoize=0,Znak=0,tempy,ttempo; |
Kovalev_D | 209:224e7331a061 | 7 | unsigned int OldMaxAmp=0,countFras=0; |
Kovalev_D | 207:d1ce992f5d17 | 8 | int z=25; |
Kovalev_D | 208:19150d2b528f | 9 | int i=16,tempi=0,klk=0; |
Kovalev_D | 193:a0fe8bfc97e4 | 10 | __irq void EINT3_IRQHandler() |
Kovalev_D | 208:19150d2b528f | 11 | { |
Kovalev_D | 208:19150d2b528f | 12 | Gyro.EXT_Latch=1; |
Kovalev_D | 205:775d54fdf646 | 13 | // Gyro.DeltaEXT_Event=1; |
Kovalev_D | 205:775d54fdf646 | 14 | // Gyro.B_Delta_EventEXT=1; |
Kovalev_D | 193:a0fe8bfc97e4 | 15 | LPC_GPIOINT->IO0IntClr |= (1<<1); |
Kovalev_D | 193:a0fe8bfc97e4 | 16 | // CMD_Delta_Bins(); |
Kovalev_D | 193:a0fe8bfc97e4 | 17 | } |
Kovalev_D | 193:a0fe8bfc97e4 | 18 | |
Kovalev_D | 193:a0fe8bfc97e4 | 19 | |
igor_v | 114:5cc38a53d8a7 | 20 | void VibroOut(void) // выставка ног вибро |
igor_v | 0:8ad47e2b6f00 | 21 | { |
Kovalev_D | 190:289514f730ee | 22 | if(CountV31>=16) |
Kovalev_D | 190:289514f730ee | 23 | {//первая нога вибро |
Kovalev_D | 89:a0d344db227e | 24 | // левая граница вЫкл вибро 1 > Time_vibro <ПРАВАЯ граница вЫкл вибро 1 |
Kovalev_D | 190:289514f730ee | 25 | if((Time_vibro>Gyro.AmpN1) && (Time_vibro<Gyro.AmpN2)) |
Kovalev_D | 190:289514f730ee | 26 | { |
Kovalev_D | 203:3a6615de9581 | 27 | SetV1//установить в регистре PinReg бит "вибро 1" в "0" |
Kovalev_D | 190:289514f730ee | 28 | } |
Kovalev_D | 190:289514f730ee | 29 | else |
Kovalev_D | 190:289514f730ee | 30 | { |
Kovalev_D | 207:d1ce992f5d17 | 31 | ClrV1 //установить в регистре PinReg бит "вибро 1" в "1" |
igor_v | 21:bc8c1cec3da6 | 32 | } |
Kovalev_D | 85:0466ee8cdfc8 | 33 | |
Kovalev_D | 190:289514f730ee | 34 | } |
Kovalev_D | 190:289514f730ee | 35 | else {//вторая нога вибро |
Kovalev_D | 190:289514f730ee | 36 | if((Time_vibro>Gyro.AmpN1)&&(Time_vibro<Gyro.AmpN2)) |
Kovalev_D | 190:289514f730ee | 37 | { |
Kovalev_D | 207:d1ce992f5d17 | 38 | SetV2 //установить в регистре PinReg бит "вибро 2" в "0" |
Kovalev_D | 190:289514f730ee | 39 | } |
Kovalev_D | 190:289514f730ee | 40 | else |
Kovalev_D | 190:289514f730ee | 41 | { |
Kovalev_D | 203:3a6615de9581 | 42 | ClrV2//установить в регистре PinReg бит "вибро 2" в "1" |
igor_v | 21:bc8c1cec3da6 | 43 | } |
igor_v | 21:bc8c1cec3da6 | 44 | } |
igor_v | 0:8ad47e2b6f00 | 45 | } |
igor_v | 0:8ad47e2b6f00 | 46 | |
Kovalev_D | 193:a0fe8bfc97e4 | 47 | |
Kovalev_D | 193:a0fe8bfc97e4 | 48 | void OLDCalcAmpN(void)//расчет точек старта и стопа импульса вибропривода и расчет частоты ошумления. |
Kovalev_D | 207:d1ce992f5d17 | 49 | { |
Kovalev_D | 207:d1ce992f5d17 | 50 | static int PeriodCount = 0,Period=0; |
Kovalev_D | 210:b02fa166315d | 51 | unsigned int Nmax=0, lowper=1; |
Kovalev_D | 209:224e7331a061 | 52 | Gyro.FrqHZ=Gyro.Frq>>16; |
Kovalev_D | 209:224e7331a061 | 53 | if(PeriodCount>= Gyro.AmpT) |
Kovalev_D | 209:224e7331a061 | 54 | { //если количество заходов в прерывание больше либо равно частоте ошумления. |
Kovalev_D | 209:224e7331a061 | 55 | PeriodCount=0;//сбрасываем таймер |
Kovalev_D | 210:b02fa166315d | 56 | /* sprintf((Time),"%d %d %d\r\n", Gyro.AmpN1, Gyro.AmpN2-Gyro.AmpN1, Gyro.AmpPer); |
Kovalev_D | 210:b02fa166315d | 57 | WriteCon(Time);*/ |
Kovalev_D | 210:b02fa166315d | 58 | |
Kovalev_D | 209:224e7331a061 | 59 | if(Cheng_AMP_Flag==0) |
Kovalev_D | 209:224e7331a061 | 60 | { |
Kovalev_D | 209:224e7331a061 | 61 | if((Gyro.AmpPer+Gyro.AmpPerDel)>90) |
Kovalev_D | 209:224e7331a061 | 62 | { |
Kovalev_D | 193:a0fe8bfc97e4 | 63 | Gyro.AmpPer=90-Gyro.AmpPerDel; //проверка верхней граници амплитуды |
Kovalev_D | 210:b02fa166315d | 64 | } //26214400 |
Kovalev_D | 210:b02fa166315d | 65 | Nmax = (unsigned int)((100000/(Gyro.Frq>>16))-1);//256 // |
Kovalev_D | 210:b02fa166315d | 66 | Gyro.AmpN1=(unsigned int)((Nmax*(100-Gyro.AmpPer))/Gyro.FrqHZ); //левая граница амплитуды 63 |
Kovalev_D | 210:b02fa166315d | 67 | Gyro.AmpN2=(unsigned int)((Nmax/2)-Gyro.AmpN1); //правая граница амплитуды 65 |
Kovalev_D | 210:b02fa166315d | 68 | Gyro.L_vibro=Gyro.AmpPer*208; |
Kovalev_D | 210:b02fa166315d | 69 | /* sprintf((Time),"%d %d %d \r\n",Gyro.L_vibro,Gyro.AmpPer,Cheng_AMP_Flag); |
Kovalev_D | 210:b02fa166315d | 70 | WriteCon(Time);*/ |
Kovalev_D | 209:224e7331a061 | 71 | Cheng_AMP_Flag=1; |
Kovalev_D | 209:224e7331a061 | 72 | } |
Kovalev_D | 210:b02fa166315d | 73 | else |
Kovalev_D | 210:b02fa166315d | 74 | { |
Kovalev_D | 210:b02fa166315d | 75 | if((Gyro.AmpPer+Gyro.AmpPerDel)>90) Gyro.AmpPer=90-Gyro.AmpPerDel; //проверка верхней граници амплитуды |
Kovalev_D | 210:b02fa166315d | 76 | if((Gyro.RgConA&0x20)) |
Kovalev_D | 210:b02fa166315d | 77 | { |
Kovalev_D | 210:b02fa166315d | 78 | Nmax =(unsigned int)((100000/(Gyro.Frq>>16))-1);//256 |
Kovalev_D | 210:b02fa166315d | 79 | Gyro.AmpN1=(unsigned int)((Nmax*(100-Gyro.AmpPer-Gyro.AmpPerDel))/Gyro.FrqHZ); //левая граница амплитуды 61 |
Kovalev_D | 210:b02fa166315d | 80 | Gyro.AmpN2=(unsigned int)((Nmax/2)-Gyro.AmpN1); //правая граница амплитуды 67 |
Kovalev_D | 210:b02fa166315d | 81 | Gyro.L_vibro=(Gyro.AmpPer+Gyro.AmpPerDel)*208; |
Kovalev_D | 210:b02fa166315d | 82 | /*sprintf((Time),"%d %d %d \r\n",Gyro.L_vibro,Gyro.AmpPer,Cheng_AMP_Flag); |
Kovalev_D | 210:b02fa166315d | 83 | WriteCon(Time); */ |
Kovalev_D | 210:b02fa166315d | 84 | } |
Kovalev_D | 210:b02fa166315d | 85 | Cheng_AMP_Flag=0; |
Kovalev_D | 210:b02fa166315d | 86 | } |
Kovalev_D | 210:b02fa166315d | 87 | if(Gyro.AmpN2<(Gyro.AmpN1+2))Gyro.AmpN2=Gyro.AmpN1+2; |
Kovalev_D | 210:b02fa166315d | 88 | |
Kovalev_D | 207:d1ce992f5d17 | 89 | srand(Global_Time);//инициализация функции rand() для получения новых случайных велечин. |
Kovalev_D | 210:b02fa166315d | 90 | Gyro.AmpT = (rand() % Gyro.AmpTD+Gyro.AmpMin);// ОШУМЛЕНИЕ amp |
Kovalev_D | 210:b02fa166315d | 91 | // Gyro.L_vibro= ((Gyro.AmpN2-Gyro.AmpN1))*(16383/Nmax); |
Kovalev_D | 210:b02fa166315d | 92 | // Gyro.L_vibro=((16000 *(Gyro.AmpN2-Gyro.AmpN1))/(Nmax/2)); |
Kovalev_D | 193:a0fe8bfc97e4 | 93 | } else { |
Kovalev_D | 193:a0fe8bfc97e4 | 94 | PeriodCount++;//таймер амплитуды |
Kovalev_D | 193:a0fe8bfc97e4 | 95 | } |
Kovalev_D | 208:19150d2b528f | 96 | |
Kovalev_D | 192:d32c8cf7bcd9 | 97 | } |
Kovalev_D | 207:d1ce992f5d17 | 98 | |
Kovalev_D | 112:4a96133a1311 | 99 | void VibroAMPRegul(void) //подстройка амплитуды ВП |
Kovalev_D | 208:19150d2b528f | 100 | { |
Kovalev_D | 209:224e7331a061 | 101 | |
Kovalev_D | 208:19150d2b528f | 102 | int temp=0; |
Kovalev_D | 209:224e7331a061 | 103 | |
Kovalev_D | 189:8a16378724c4 | 104 | Gyro.CaunPlus = CaunAddPlus;//амплитуда по модулю из востановленного синиуса Buff_Restored_sin |
Kovalev_D | 210:b02fa166315d | 105 | // Gyro.CaunPlus = Gyro.CaunPlusReper; |
Kovalev_D | 112:4a96133a1311 | 106 | CaunAddPlus = 0; |
Kovalev_D | 209:224e7331a061 | 107 | Gyro.CaunMin = CaunAddMin; //амплитуда по модулю из востановленного синиуса Buff_Restored_sin |
Kovalev_D | 210:b02fa166315d | 108 | //Gyro.CaunMin=Gyro.CaunMinReper; |
Kovalev_D | 112:4a96133a1311 | 109 | CaunAddMin = 0; |
Kovalev_D | 208:19150d2b528f | 110 | Gyro.MaxAmp = Gyro.CaunPlus + Gyro.CaunMin; |
Kovalev_D | 209:224e7331a061 | 111 | |
Kovalev_D | 209:224e7331a061 | 112 | |
Kovalev_D | 209:224e7331a061 | 113 | if(countFras<512) |
Kovalev_D | 209:224e7331a061 | 114 | { |
Kovalev_D | 209:224e7331a061 | 115 | countFras++; |
Kovalev_D | 210:b02fa166315d | 116 | Gyro.F_rasAdd += Gyro.MaxAmp/32*Gyro.FrqHZ/40; |
Kovalev_D | 209:224e7331a061 | 117 | } |
Kovalev_D | 209:224e7331a061 | 118 | else |
Kovalev_D | 210:b02fa166315d | 119 | { |
Kovalev_D | 210:b02fa166315d | 120 | sprintf((Time)," %d %d %d\r\n",Gyro.F_ras, Gyro.MaxAmp, Gyro.AmpTarget/((Gyro.Frq)>>16)); |
Kovalev_D | 210:b02fa166315d | 121 | WriteCon(Time); |
Kovalev_D | 210:b02fa166315d | 122 | Gyro.F_rasAdd += Gyro.MaxAmp/32*Gyro.FrqHZ/40; |
Kovalev_D | 210:b02fa166315d | 123 | Gyro.F_ras=Gyro.F_rasAdd>>8; |
Kovalev_D | 209:224e7331a061 | 124 | Gyro.F_rasAdd=0; |
Kovalev_D | 209:224e7331a061 | 125 | countFras=0; |
Kovalev_D | 209:224e7331a061 | 126 | } |
Kovalev_D | 209:224e7331a061 | 127 | |
Kovalev_D | 209:224e7331a061 | 128 | |
Kovalev_D | 208:19150d2b528f | 129 | if(Gyro.RgConA&0x20) |
Kovalev_D | 208:19150d2b528f | 130 | { |
Kovalev_D | 209:224e7331a061 | 131 | //расчет максимальной амплитуды из востановленного синуса р-р. |
Kovalev_D | 210:b02fa166315d | 132 | temp=(int)(((Gyro.MaxAmp -Gyro.AmpTarget/((Gyro.Frq)>>16)) * Gyro.AmpSpeed)); |
Kovalev_D | 210:b02fa166315d | 133 | temp=temp>>6; |
Kovalev_D | 208:19150d2b528f | 134 | Gyro.Amp -= temp; // расчет амплитуды ВП с учетом разници |
Kovalev_D | 209:224e7331a061 | 135 | if((Gyro.Amp>>16) > Gyro.AmpPerMax) {Gyro.Amp = (Gyro.AmpPerMax << 16);} // временное ограничение роста амплитуды ВП в случае неподоженного гироскопа////////// |
Kovalev_D | 209:224e7331a061 | 136 | if((Gyro.Amp>>16) < Gyro.AmpPerMin) {Gyro.Amp = (Gyro.AmpPerMin << 16);} // временное ограничение роста амплитуды ВП в случае неподоженного гироскопа////////// |
Kovalev_D | 208:19150d2b528f | 137 | Gyro.AmpPer = Gyro.Amp>>16; //приведение амплитуды ВП к виду 0%-100% |
Kovalev_D | 208:19150d2b528f | 138 | } |
Kovalev_D | 208:19150d2b528f | 139 | } |
Kovalev_D | 112:4a96133a1311 | 140 | |
Kovalev_D | 191:40028201ddad | 141 | |
Kovalev_D | 191:40028201ddad | 142 | |
Kovalev_D | 112:4a96133a1311 | 143 | void VibroFrqRegul(void)// расчет Фазы с учетор разници(подстройка частоты) |
Kovalev_D | 196:f76dbc081e63 | 144 | { |
Kovalev_D | 112:4a96133a1311 | 145 | static int TempFaza, CountFaza; |
Kovalev_D | 112:4a96133a1311 | 146 | TempFaza = -4; |
Kovalev_D | 209:224e7331a061 | 147 | Gyro.FrqPhaseEror=0; |
Kovalev_D | 209:224e7331a061 | 148 | for (CountFaza = 0; CountFaza <8; CountFaza++ ) {if (Buff_Restored_sin [(CountV31 - Gyro.FrqPhase + CountFaza) & 0x1f] > 0 ) TempFaza++;} //резонанс когда CountV31 = 8 => Buff_Restored_sin = 0 |
Kovalev_D | 209:224e7331a061 | 149 | for (CountFaza = 0; CountFaza <8; CountFaza++ ) {Gyro.FrqPhaseEror += Buff_Restored_sin [(CountV31 - Gyro.FrqPhase + CountFaza) & 0x1f];} |
Kovalev_D | 208:19150d2b528f | 150 | if(Gyro.RgConA&0x40) |
Kovalev_D | 208:19150d2b528f | 151 | { //12 |
Kovalev_D | 209:224e7331a061 | 152 | Gyro.Frq += TempFaza*Gyro.FrqChengSpeed; |
Kovalev_D | 208:19150d2b528f | 153 | } |
Kovalev_D | 209:224e7331a061 | 154 | // Gyro.FrqPhaseEror = TempFaza<<10; |
Kovalev_D | 189:8a16378724c4 | 155 | if (Gyro.Frq < Gyro.FrqHZmin) Gyro.Frq=Gyro.FrqHZmin;//нижнее ограничение частоты |
Kovalev_D | 189:8a16378724c4 | 156 | else if(Gyro.Frq > Gyro.FrqHZmax) Gyro.Frq=Gyro.FrqHZmax;//верхнее ограничение частоты |
Kovalev_D | 208:19150d2b528f | 157 | LPC_TIM1->MR0 =(unsigned int)(103000000/((Gyro.Frq)>>11));//запись в таймер нового значение частоты вибро |
igor_v | 0:8ad47e2b6f00 | 158 | } |
igor_v | 0:8ad47e2b6f00 | 159 | |
igor_v | 0:8ad47e2b6f00 | 160 | ////////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 190:289514f730ee | 161 | /////////////////////////основного 32 тактного цикла////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 162 | ////////////////////////////////////////////////////////////////////////////// |
igor_v | 0:8ad47e2b6f00 | 163 | void cheng(void) |
Kovalev_D | 99:3d8f206ceac2 | 164 | { |
Kovalev_D | 107:4d178bcc9d8a | 165 | switch(CountV31) { |
Kovalev_D | 112:4a96133a1311 | 166 | case 0: |
Kovalev_D | 196:f76dbc081e63 | 167 | Gyro.VibroAMPRegulF=1; |
Kovalev_D | 112:4a96133a1311 | 168 | Time_vibro=0; |
Kovalev_D | 207:d1ce992f5d17 | 169 | Gyro.VibroNoiseF++;//расчет и установка нового заначения частоты ошумления и запись в таймер частоты ошумления. |
Kovalev_D | 112:4a96133a1311 | 170 | break; |
Kovalev_D | 196:f76dbc081e63 | 171 | |
Kovalev_D | 112:4a96133a1311 | 172 | case 16: |
Kovalev_D | 209:224e7331a061 | 173 | // Gyro.Reper_Event=1; |
Kovalev_D | 112:4a96133a1311 | 174 | Time_vibro=0; |
Kovalev_D | 191:40028201ddad | 175 | Gyro.VibroFrqRegulF=1; // |
Kovalev_D | 112:4a96133a1311 | 176 | break; |
Kovalev_D | 207:d1ce992f5d17 | 177 | } |
Kovalev_D | 191:40028201ddad | 178 | } |
Kovalev_D | 191:40028201ddad | 179 | void AllRegul (void) |
Kovalev_D | 191:40028201ddad | 180 | { ///////////////////////////контуры регулировки///////////////////////////// |
Kovalev_D | 191:40028201ddad | 181 | |
Kovalev_D | 191:40028201ddad | 182 | if (Spi.ADC_NewData == 1) {ADS_Acum(); } // был приход новых данных по ацп сдесь сделать обработку информации и подготовку для выдачи делается 1 раз за вибро |
Kovalev_D | 191:40028201ddad | 183 | if (Gyro.ADF_NewData == 1) {Gyro.ADF_NewData = 0; } // был приход новых данных После быстрого фильтра AD |
Kovalev_D | 197:7a05523bf588 | 184 | |
Kovalev_D | 197:7a05523bf588 | 185 | |
Kovalev_D | 197:7a05523bf588 | 186 | |
Kovalev_D | 197:7a05523bf588 | 187 | /*if (Gyro.ADS_NewData == 1) |
Kovalev_D | 197:7a05523bf588 | 188 | { Gyro.ADS_NewData = 0; |
Kovalev_D | 196:f76dbc081e63 | 189 | switch(Gyro.LogPLC) { |
Kovalev_D | 196:f76dbc081e63 | 190 | case 0: PlcRegul(); break; |
Kovalev_D | 196:f76dbc081e63 | 191 | case 1: PlcRegul(); break; |
Kovalev_D | 196:f76dbc081e63 | 192 | case 2: ShowMod(); break; |
Kovalev_D | 196:f76dbc081e63 | 193 | } |
Kovalev_D | 197:7a05523bf588 | 194 | }*/// был приход новых данных После Медленного фильтра AD (гдето раз в 0.63 секунды )//регулировка периметра. |
Kovalev_D | 197:7a05523bf588 | 195 | |
Kovalev_D | 197:7a05523bf588 | 196 | |
Kovalev_D | 197:7a05523bf588 | 197 | |
Kovalev_D | 191:40028201ddad | 198 | if (Gyro.VibroFrqRegulF == 1) {Gyro.VibroFrqRegulF = 0; VibroFrqRegul(); } // Регулеровка частоты виброподвеса |
Kovalev_D | 209:224e7331a061 | 199 | if (Gyro.VibroAMPRegulF == 1) |
Kovalev_D | 209:224e7331a061 | 200 | { |
Kovalev_D | 209:224e7331a061 | 201 | Gyro.VibroAMPRegulF = 0; |
Kovalev_D | 209:224e7331a061 | 202 | VibroAMPRegul(); |
Kovalev_D | 209:224e7331a061 | 203 | if(!MODFlag)PLCRegul(); |
Kovalev_D | 209:224e7331a061 | 204 | |
Kovalev_D | 209:224e7331a061 | 205 | } // Регулеровка Амплитуды виброподвеса |
Kovalev_D | 209:224e7331a061 | 206 | if (Gyro.VibroNoiseF == 1) {Gyro.VibroNoiseF = 0; OLDCalcAmpN();} |
Kovalev_D | 205:775d54fdf646 | 207 | /* { |
Kovalev_D | 197:7a05523bf588 | 208 | switch(Gyro.flag) { |
Kovalev_D | 197:7a05523bf588 | 209 | case 1: Gyro.VibroNoiseF = 0; OLDCalcAmpN(); break; |
Kovalev_D | 197:7a05523bf588 | 210 | case 2: Gyro.AmpMin =3;Gyro.AmpTD =10;Gyro.VibroNoiseF = 0;Calc2AmpN(); break; |
Kovalev_D | 197:7a05523bf588 | 211 | case 3: Gyro.AmpMin =1;Gyro.AmpTD =10;Gyro.VibroNoiseF = 0;CalcAmpD(); break; |
Kovalev_D | 205:775d54fdf646 | 212 | } |
Kovalev_D | 205:775d54fdf646 | 213 | } */// регулеровка ошумления, наверно нужно объеденить с регулеровкой ампитуды |
Kovalev_D | 203:3a6615de9581 | 214 | //if (Gyro.VibroOutF == 1) {Gyro.VibroOutF = 0; VibroOut();} // установка ног в регисторе тоже подумать , зачем отделный флаг? наверно |
Kovalev_D | 196:f76dbc081e63 | 215 | } |