![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
fork
Fork of LG by
SPI.c
- Committer:
- Kovalev_D
- Date:
- 2016-03-31
- Revision:
- 104:ab1cb4ff56b2
- Parent:
- 99:3d8f206ceac2
- Child:
- 105:bd01d8d20fb6
File content as of revision 104:ab1cb4ff56b2:
#include "Global.h" struct SPI Spi; 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; unsigned int Temp_ADC_5; unsigned int Buff_ADC_1 [32]; unsigned int Buff_ADC_2 [32]; unsigned int Buff_ADC_3 [32]; unsigned int Buff_ADC_4 [32]; unsigned int Buff_ADC_5 [256]; unsigned int Buff_AMP [256]; unsigned int Buff_AMP64P [256]; unsigned int SinPLC[64]= {1023, 1016, 1006, 993, 976, 954, 904, 874, 841, 806, 768, 728, 687, 645, 601, 557, 500, 379, 337, 296, 256, 219, 183, 150, 120, 93, 69, 48, 31, 18, 8, 0, 8, 18, 31, 48, 69, 93, 120, 150, 183, 219, 256, 296, 337, 379, 468, 512, 557, 601, 645, 687, 728, 768, 806, 841, 874, 904, 954, 976, 993, 1006, 1016, 1023 }; void SPI_Exchange(void) { unsigned int DummySPI; int Delta; Spi.ADC5 = LPC_SSP0->DR; Spi.ADC4 = LPC_SSP0->DR; Spi.ADC3 = LPC_SSP0->DR; Spi.ADC2 = LPC_SSP0->DR; Spi.ADC1 = LPC_SSP0->DR; Input.ArrayIn[2]= Spi.ADC5; 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); //e. передача 12 бит } // 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; //очистить буфер. Buff_ADC_1 [CountV31] = Spi.ADC1; Buff_ADC_2 [CountV31] = Spi.ADC2; Buff_ADC_3 [CountV31] = Spi.ADC3; Buff_ADC_4 [CountV31] = Spi.ADC4; Buff_ADC_5 [CountV255] = Spi.ADC5; // ампл ацп. // Temp_AMP += Buff_ADC_5[CountV255]; // Temp_AMP -= Buff_ADC_5[(CountV255-32) & 0xff]; // заполнение буфера накопленых приращений за 8 тактов // Buff_AMP[CountV255] = (unsigned int) (Temp_AMP); Temp_AMP += Buff_ADC_5[CountV255]; Temp_AMP -= Buff_ADC_5[(CountV255-32) & 0xff]; // з 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>=(32*32)) { Delta = ADD_AMP - Cur_Amp; if ( Delta > 3000000 ) Spi.DAC_B += 100; else if ( Delta < (-300000) ) Spi.DAC_B += 100; else if ((Delta * Znak_Amp) > 0) { Spi.DAC_B += 1 ; Znak_Amp = 1; } else { Spi.DAC_B -= 1; Znak_Amp = -1; } Cur_Amp=ADD_AMP; Count_AMP=0; ADD_AMP=0; } Temp_AMP64P += Buff_ADC_5[CountV255]; Temp_AMP64P -= Buff_ADC_5[(CountV255-64) & 0xff]; // заполнение буфера накопленых приращений за 8 тактов Buff_AMP64P[CountV255] = (unsigned int) (Temp_AMP64P); Temp_ADC_2 += Buff_ADC_2[CountV31]; Temp_ADC_2 -= Buff_ADC_2[(CountV31-32) & 0xff]; Temp_ADC_3 += Buff_ADC_3[CountV31]; Temp_ADC_3 -= Buff_ADC_3[(CountV31-32) & 0xff]; Temp_ADC_4 += Buff_ADC_4[CountV31]; Temp_ADC_4 -= Buff_ADC_4[(CountV31-32) & 0xff]; Temp_ADC_5 += Buff_ADC_1[CountV255]; Temp_ADC_5 -= Buff_ADC_1[(CountV255-32) & 0xff]; }