![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
fork
Fork of LG by
SPI.c
- Committer:
- Kovalev_D
- Date:
- 2017-07-03
- Revision:
- 211:ac8251b067d2
- Parent:
- 209:224e7331a061
- Child:
- 212:8d6784491bae
File content as of revision 211:ac8251b067d2:
#include "Global.h" struct SPI Spi; //unsigned int Temp_AMP; unsigned int Temp_AMP64P; int ttt=1; unsigned int Count_AMP, ADD_AMP, Cur_Amp; int Znak_Amp; int AD_Regul = 0; int temp9,tempADC5; int AD_MAX=0; int k=0,l=0,r=0,n=0;//счетчики для регулировки периметра int flagmod=0,Bdelta; int start=10; int dispersion=0,side=1,tempstrafe=15000; unsigned int Temp_ADC_2; unsigned int Temp_ADC_3; unsigned int Temp_ADC_4; unsigned int Temp_ADC_5; unsigned int TempA; unsigned int TempTermLM; unsigned int conuntPLS; int ADC5Old,ADCDIF=0; int DACModReg; int SinPls=0,SinMns=0; unsigned int ADC5New; unsigned int Buff_ADC_1 [32]; unsigned int Buff_ADC_2 [32]; unsigned int Buff_ADC_3 [32]; unsigned int Buff_ADC_4 [32]; int RegulADC,DeltaRegul; unsigned int Buff_ADC_5 [512]; unsigned int BuffADC_16Point [64]; unsigned int BuffADC_32Point [64]; unsigned int BuffADC_64Point [64]; unsigned int BuffADC_32PointD [64]; unsigned int Buff_Restored_Mod [64]; unsigned int PulseADC_16Point; unsigned int PulseADC_32Point; unsigned int PulseADC_64Point; unsigned int PulseADC_32PointD; unsigned int Buff_AMP [256]; unsigned int Buff_AMP64P [256]; unsigned int TypeMod=2; unsigned int ModArraySin [64] = {50,55,59,64,68,73,77,81,85,88,91,94,96,98,99,99,100,99,99,98,96,94,91,88,85,81,77,73,68,64,59,55,50,45,41,36,32,27,23,19,16,12,9,7,4,2,1,1,0,1,1,2,4,7,9,12,16,19,23,27,32,36,41,45}; unsigned int ModArrayTriangle [64]; unsigned int ModArraySaw [64]; unsigned int Mod=0; void InitMOD(void) { for (int i = 0; i < 64; i++ ) { if(i<32) { ModArrayTriangle[i]=Mod; Mod+=3;} else { ModArrayTriangle[i]=Mod; Mod-=3;} } for (int i = 0; i < 16; i++ ) { ModArraySaw[i]=Mod; Mod+=1; } } void Modulator(void) { if(!MODFlag) { switch(TypeMod) { case 0: LPC_DAC->DACR = (ModArraySin [(CountV64-2)&0x3f]*Gyro.ModAmp); break; case 1: LPC_DAC->DACR = (ModArraySaw [CountV64]*Gyro.ModAmp); break; case 2: LPC_DAC->DACR = (ModArrayTriangle [(CountV64-2)&0x3f]*Gyro.ModAmp); break; } } } void PLCRegul(void) { unsigned int temp, Temp_Dac_B=0,Side=0; static int CountFaza; // Temp_Dac_B=(0xffff-Spi.DAC_B); if(conuntPLS<10) { for (CountFaza = 0; CountFaza <32; CountFaza++ ) SinPls+= BuffADC_64Point[ (CountFaza + Gyro.PLC_Phase) & 0x3f]; for (CountFaza = 32; CountFaza <64; CountFaza++) SinMns+= BuffADC_64Point[ (CountFaza + Gyro.PLC_Phase) & 0x3f]; conuntPLS++; } else { conuntPLS=0; Gyro.PLC_Eror = SinMns-SinPls; if(Gyro.RgConA&0x8) { if(Gyro.PLC_Eror>0) {Spi.DAC_B+=Gyro.PLC_Gain;} else {Spi.DAC_B-=Gyro.PLC_Gain;} } if(Gyro.PLC_Eror>0) {Gyro.PLC_Eror_count++;} else {Gyro.PLC_Eror_count--;} if(Gyro.LG_Type==1) { if ( Spi.DAC_B < Gyro.HighTreshold ) Spi.DAC_B = (Gyro.ResetLevelHeat); else if ( Spi.DAC_B > Gyro.DownTreshold ) Spi.DAC_B = (Gyro.ResetLevelCool); } else { if ( Spi.DAC_B < 10300 ) Spi.DAC_B = 32000; //проверка на переваливание за границу. else if ( Spi.DAC_B > 57000 ) Spi.DAC_B = 32000; } SinPls=0; SinMns=0; } } void PLCRegul250(void) { unsigned int temp; static int CountFaza; temp = MODCount; for (CountFaza = 0; CountFaza <32; CountFaza++ ) SinPls+= BuffADC_64Point[ (CountFaza + Gyro.PLC_Phase) & 0x3f]; for (CountFaza = 32; CountFaza <64; CountFaza++) SinMns+= BuffADC_64Point[ (CountFaza + Gyro.PLC_Phase) & 0x3f]; Gyro.PLC_Eror = SinMns-SinPls; /* sprintf((Time)," %d %d %d %d %d\r\n",Spi.ADC5, Spi.DAC_B, SinPls, SinMns, Gyro.PLC_Eror); WriteCon(Time);*/ if(Gyro.RgConA&0x8) { if(Gyro.PLC_Eror>0) {Spi.DAC_B+=1 * Gyro.PLC_Gain;} else {Spi.DAC_B-=1 * Gyro.PLC_Gain;} } if(Gyro.PLC_Eror>0) {Gyro.PLC_Eror_count++;} else {Gyro.PLC_Eror_count--;} if ( Spi.DAC_B < 10300 ) Spi.DAC_B = 32000; //проверка на переваливание за границу. else if ( Spi.DAC_B > 57000 ) Spi.DAC_B = 32000; SinPls=0; SinMns=0; } void HFORegul(void) { RegulADC=32767-Spi.ADC5; DeltaRegul=((Gyro.HFO_ref-RegulADC)>>11); if(Gyro.RgConA&0x2) { Spi.DAC_A-=DeltaRegul*Gyro.HFO_Gain; if(Spi.DAC_A>Gyro.HFO_Min) Spi.DAC_A-=0xfff; else if(Spi.DAC_A<Gyro.HFO_Max) Spi.DAC_A+=0xfff; } } // Spi.DAC_B-=ADCDIF>>6; void ADS_Acum(void) { Spi.ADC_NewData = 0; // Gyro.Termo = (unsigned int)(((Spi.ADC1>>1) + Gyro.Tmp_OffsetT4) * Gyro.Tmp_scaleT4); Gyro.Termo = (unsigned int)(Spi.ADC1>>1); Gyro.IN1_Accum += Spi.ADC2; Gyro.IN2_Accum += Spi.ADC3; // Gyro.DeltaT = (unsigned int)(((Spi.ADC4>>1) + Gyro.Tmp_OffsetT5) * Gyro.Tmp_scaleT5); Gyro.DeltaT = (unsigned int)(Spi.ADC4>>1); TempA = (0xffff - Spi.ADC5); // перевернем знак и умножим на два (было 32000...0 стало 0 ...32000 /*сдвиг(<<1) стало 0 ...64000*/) Gyro.TermLM = Spi.ADC1; Gyro.ADF_Accum += TempA; Gyro.ADS_Accum += TempA; /// Gyro.ADS_AccumTermLM+=TempTermLM; Gyro.ADF_Count ++; Gyro.ADS_Count ++; Gyro.ADM_Count ++; /* sprintf((Time),"%d %d\r\n",((Gyro.In1>>1) - 0x4fff),(Spi.DAC_B-0x4fff)); WriteCon(Time);*/ if (Gyro.ADM_Count > 255) { Gyro.In1 = Gyro.IN1_Accum>>8; Gyro.In2 = Gyro.IN2_Accum>>8; Gyro.IN1_Accum=0; Gyro.IN2_Accum=0; Gyro.ADM_Count=0; } if (Gyro.ADF_Count > 15) { // если прошло 16 тактов виброподвеса Gyro.AD_Fast = Gyro.ADF_Accum << 11; //обновляем данные и приводим в один масштаб Gyro.ADF_Count = 0;// Gyro.ADF_Accum = 0; Gyro.ADF_NewData = 1; } if (Gyro.ADS_Count > 255) { // если прошло 256 тактов виброподвеса Gyro.AD_Slow = Gyro.ADS_Accum << 7; //обновляем данные и приводим в один масштаб // Gyro.TermLM = Gyro.ADS_AccumTermLM << 3; Gyro.ADS_Count = 0; Gyro.ADS_Accum = 0; Gyro.ADS_AccumTermLM=0; Gyro.ADS_NewData = 1; } } void SPI_Exchange(void) // новая функция чтения, в нецй не должно быть ничего лишнего { unsigned int DummySPI; //unsigned int ADC5Dif; ADC5New = LPC_SSP0->DR;// Чтение АЦП //Spi.ADC5_Accum += LPC_SSP0->DR; Spi.ADC4_Accum += LPC_SSP0->DR; Spi.ADC3_Accum += LPC_SSP0->DR; Spi.ADC2_Accum += LPC_SSP0->DR; Spi.ADC1_Accum += LPC_SSP0->DR; Spi.ADC5_Accum += ADC5New; while (LPC_SSP0->SR & RX_SSP_notEMPT) { DummySPI = LPC_SSP0->DR; //если буфер SPI не пуст.//очистить буфер. } DAC_OutPut(); if (CountV31 == 0) { // просто фильтруем по 32 точкам. // выставояем бит, что есть новы данные Spi.ADC1 = Spi.ADC1_Accum >> 5; // подгоотавливаем данные (в той эе сетке) те ADC1 0..65535 Spi.ADC2 = Spi.ADC2_Accum >> 5; Spi.ADC3 = Spi.ADC3_Accum >> 5; Spi.ADC4 = Spi.ADC4_Accum >> 5; Spi.ADC5 = Spi.ADC5_Accum >> 5; Spi.ADC1_Accum = 0; // сбрасывкем аккамулятор Spi.ADC2_Accum = 0; Spi.ADC3_Accum = 0; Spi.ADC4_Accum = 0; Spi.ADC5_Accum = 0; Spi.ADC_NewData = 1; } if(!MODFlag) BuffADC_64Point[CountV64]=ADC5New; Buff_ADC_5[CountV255] = (0x7fff-ADC5New)<<2; } void ShowMod(void)//технологическая функция для просмотра в ориджине мод на всем диапазпне цап { ////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////смотрим все моды///////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// if(dispersion>5) { if( (Gyro.PLC_Lern<60000)&&(Gyro.PLC_Error2Mode >1))//пробигаем по нескольким значениям цап(60*0х3с=0хВВ8) для определения максимальной амплитуды. { Gyro.PLC_Error2Mode--; Gyro.PLC_Lern++; Spi.DAC_B += tempstrafe*side; if(side>0)side=(-1); else side = 1; tempstrafe-=40; dispersion=0; } else {Gyro.LogPLC=0;} } else dispersion++; sprintf((Time),"%d %d %d %d \r\n", Gyro.CuruAngle, Spi.DAC_B, Gyro.AD_Slow, Gyro.Termo); Gyro.CuruAngle=0; WriteCon(Time); } void ShowMod2(void)//технологическая функция для просмотра в ориджине мод на всем диапазпне цап { if(dispersion>3) { unsigned int step = 50, ENDMOD=32767; sprintf((Time),"%d %d %d %d %d %d %d\r\n", Gyro.CuruAngle, Spi.DAC_B, Gyro.AD_Slow, Spi.ADC5, 0xfFFf-Spi.ADC1, Spi.ADC1, Gyro.Termo); Gyro.CuruAngle=0; WriteCon(Time); Spi.DAC_B-=step; if(Spi.DAC_B<ENDMOD) { Gyro.LogMod=0; PlcON Spi.DAC_B = 32000; } dispersion=0; } else dispersion++; } void DAC_OutPut(void)//выдача в цапы { if(Gyro.RgConA&0x10) Modulator(); LPC_SSP0->DR=0x5555; LPC_SSP0->DR=0x5555; LPC_SSP0->DR=0x5555; if (CountV31 & 1) { //если нечетный такт то LPC_SSP0->DR = WRITE_DAC0; //e.команда для ЦАП_0 передавать. LPC_SSP0->DR = (Spi.DAC_A); //e. передача 12 бит } else { //если такт четный. LPC_SSP0->DR = WRITE_DAC1 ; //e.команда для ЦАП_1 передавать. LPC_SSP0->DR = (Spi.DAC_B); } }