![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
forkd
Fork of LGstaandart by
Diff: SPI.c
- Revision:
- 99:3d8f206ceac2
- Parent:
- 96:1c8536458119
- Child:
- 104:ab1cb4ff56b2
diff -r 95b8e79f13e1 -r 3d8f206ceac2 SPI.c --- a/SPI.c Tue Mar 29 09:51:17 2016 +0000 +++ b/SPI.c Tue Mar 29 17:00:59 2016 +0000 @@ -3,6 +3,9 @@ unsigned int Temp_AMP; unsigned int Temp_AMP64P; +unsigned int Count_AMP, ADD_AMP, Cur_Amp; +int Znak_Amp; + unsigned int Temp_ADC_2; unsigned int Temp_ADC_3; unsigned int Temp_ADC_4; @@ -28,6 +31,8 @@ void SPI_Exchange(void) { unsigned int DummySPI; + int Delta; + Spi.ADC5 = LPC_SSP0->DR; Spi.ADC4 = LPC_SSP0->DR; @@ -49,7 +54,8 @@ LPC_SSP0->DR = (Spi.DAC_B); //e. передача 12 бит } - LPC_DAC->CR = (((SinPLC[CountV64]*35)+24300));// модулятор +// LPC_DAC->CR = (((SinPLC[CountV64]*35/5)+24300));// модулятор +// LPC_DAC->CR = (((SinPLC[CountV64]*35/5)+24300));// модулятор while (LPC_SSP0->SR & RX_SSP_notEMPT) //если буфер SPI не пуст. DummySPI = LPC_SSP0->DR; //очистить буфер. @@ -70,6 +76,33 @@ Temp_AMP += Buff_ADC_5[(CountV255-64) & 0xff]; // Temp_AMP -= Buff_ADC_5[(CountV255-96) & 0xff]; // з Buff_AMP[CountV255] = (unsigned int) (Temp_AMP); + + ADD_AMP+=Spi.ADC5; + Count_AMP++; + + + if(Count_AMP>=(64*200)) + { + Delta = ADD_AMP - Cur_Amp; + if ( Delta > 30000000 ) Spi.DAC_B += 1000; + else if ( Delta < (-3000000) ) Spi.DAC_B += 1000; + else if ((Delta * Znak_Amp) > 0) + { + Spi.DAC_B += 2 ; + Znak_Amp = 1; + } + else + { + Spi.DAC_B -= 2; + Znak_Amp = -1; + } + Cur_Amp=ADD_AMP; Count_AMP=0; ADD_AMP=0; + + + } + + + Temp_AMP64P += Buff_ADC_5[CountV255];