fork

Dependencies:   mbed

Fork of LG by igor Apu

Committer:
igor_v
Date:
Sat Jan 30 13:00:39 2016 +0000
Revision:
0:8ad47e2b6f00
Child:
21:bc8c1cec3da6
2016_01_30;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
igor_v 0:8ad47e2b6f00 1 #include "Global.h"
igor_v 0:8ad47e2b6f00 2 #include "SPI.h"
igor_v 0:8ad47e2b6f00 3 #include "stdlib.h"
igor_v 0:8ad47e2b6f00 4 #include "LPC17xx.h"
igor_v 0:8ad47e2b6f00 5 #include "InputOutput.h"
igor_v 0:8ad47e2b6f00 6 #include "MTimer.h"
igor_v 0:8ad47e2b6f00 7 struct SPI Spi;
igor_v 0:8ad47e2b6f00 8 unsigned int Temp_AMP=0;
igor_v 0:8ad47e2b6f00 9
igor_v 0:8ad47e2b6f00 10 unsigned int Temp_ADC_2=0;
igor_v 0:8ad47e2b6f00 11 unsigned int Temp_ADC_3=0;
igor_v 0:8ad47e2b6f00 12 unsigned int Temp_ADC_4=0;
igor_v 0:8ad47e2b6f00 13 unsigned int Temp_ADC_5=0;
igor_v 0:8ad47e2b6f00 14
igor_v 0:8ad47e2b6f00 15
igor_v 0:8ad47e2b6f00 16 unsigned int Buff_ADC_1 [256];
igor_v 0:8ad47e2b6f00 17 unsigned int Buff_ADC_2 [256];
igor_v 0:8ad47e2b6f00 18 unsigned int Buff_ADC_3 [256];
igor_v 0:8ad47e2b6f00 19 unsigned int Buff_ADC_4 [256];
igor_v 0:8ad47e2b6f00 20 unsigned int Buff_ADC_5 [256];
igor_v 0:8ad47e2b6f00 21
igor_v 0:8ad47e2b6f00 22 unsigned int Buff_AMP [256];
igor_v 0:8ad47e2b6f00 23 void SPI_Exchange()
igor_v 0:8ad47e2b6f00 24 {
igor_v 0:8ad47e2b6f00 25 unsigned int Dummy;
igor_v 0:8ad47e2b6f00 26
igor_v 0:8ad47e2b6f00 27 Spi.ADC5 = LPC_SSP0->DR;
igor_v 0:8ad47e2b6f00 28 Spi.ADC4 = LPC_SSP0->DR;
igor_v 0:8ad47e2b6f00 29 Spi.ADC3 = LPC_SSP0->DR;
igor_v 0:8ad47e2b6f00 30 Spi.ADC2 = LPC_SSP0->DR;
igor_v 0:8ad47e2b6f00 31 Spi.ADC1 = LPC_SSP0->DR;
igor_v 0:8ad47e2b6f00 32
igor_v 0:8ad47e2b6f00 33 Input.ArrayIn[2]= Spi.ADC5;
igor_v 0:8ad47e2b6f00 34
igor_v 0:8ad47e2b6f00 35 LPC_SSP0->DR=0x5555;
igor_v 0:8ad47e2b6f00 36 LPC_SSP0->DR=0x5555;
igor_v 0:8ad47e2b6f00 37 LPC_SSP0->DR=0x5555;
igor_v 0:8ad47e2b6f00 38
igor_v 0:8ad47e2b6f00 39 if (CountV31 & 1) //���� �������� ���� ��
igor_v 0:8ad47e2b6f00 40 {
igor_v 0:8ad47e2b6f00 41 LPC_SSP0->DR = WRITE_DAC0; //e.������� ��� ���_0 ����������.
igor_v 0:8ad47e2b6f00 42 LPC_SSP0->DR = (Spi.DAC_A); //e. �������� 12 ���
igor_v 0:8ad47e2b6f00 43 }
igor_v 0:8ad47e2b6f00 44 else //���� ���� ������.
igor_v 0:8ad47e2b6f00 45 {
igor_v 0:8ad47e2b6f00 46 LPC_SSP0->DR = WRITE_DAC1 ; //e.������� ��� ���_1 ����������.
igor_v 0:8ad47e2b6f00 47 LPC_SSP0->DR = (Spi.DAC_B); //e. �������� 12 ���
igor_v 0:8ad47e2b6f00 48 }
igor_v 0:8ad47e2b6f00 49 while (LPC_SSP0->SR & RX_SSP_notEMPT) //���� ����� SPI �� ����.
igor_v 0:8ad47e2b6f00 50 Dummy = LPC_SSP0->DR; //�������� �����.
igor_v 0:8ad47e2b6f00 51
igor_v 0:8ad47e2b6f00 52
igor_v 0:8ad47e2b6f00 53 Buff_ADC_1 [CountV255] = Spi.ADC1; // ���� ���.
igor_v 0:8ad47e2b6f00 54 Buff_ADC_2 [CountV255] = Spi.ADC2;
igor_v 0:8ad47e2b6f00 55 Buff_ADC_3 [CountV255] = Spi.ADC3;
igor_v 0:8ad47e2b6f00 56 Buff_ADC_4 [CountV255] = Spi.ADC4;
igor_v 0:8ad47e2b6f00 57 Buff_ADC_5 [CountV255] = Spi.ADC5;
igor_v 0:8ad47e2b6f00 58
igor_v 0:8ad47e2b6f00 59
igor_v 0:8ad47e2b6f00 60
igor_v 0:8ad47e2b6f00 61 Temp_AMP += Buff_ADC_5[CountV255];
igor_v 0:8ad47e2b6f00 62 Temp_AMP -= Buff_ADC_5[(CountV255-32) & 0xff]; // ���������� ������ ���������� ���������� �� 8 ������
igor_v 0:8ad47e2b6f00 63 Buff_AMP[CountV255] = (unsigned int) (Temp_AMP);
igor_v 0:8ad47e2b6f00 64
igor_v 0:8ad47e2b6f00 65 Temp_ADC_2 += Buff_ADC_2[CountV255];
igor_v 0:8ad47e2b6f00 66 Temp_ADC_2 -= Buff_ADC_2[(CountV255-32) & 0xff];
igor_v 0:8ad47e2b6f00 67
igor_v 0:8ad47e2b6f00 68 Temp_ADC_3 += Buff_ADC_3[CountV255];
igor_v 0:8ad47e2b6f00 69 Temp_ADC_3 -= Buff_ADC_3[(CountV255-32) & 0xff];
igor_v 0:8ad47e2b6f00 70
igor_v 0:8ad47e2b6f00 71 Temp_ADC_4 += Buff_ADC_4[CountV255];
igor_v 0:8ad47e2b6f00 72 Temp_ADC_4 -= Buff_ADC_4[(CountV255-32) & 0xff];
igor_v 0:8ad47e2b6f00 73
igor_v 0:8ad47e2b6f00 74 Temp_ADC_5 += Buff_ADC_1[CountV255];
igor_v 0:8ad47e2b6f00 75 Temp_ADC_5 -= Buff_ADC_1[(CountV255-32) & 0xff];
igor_v 0:8ad47e2b6f00 76 }
igor_v 0:8ad47e2b6f00 77 void Init_SPI_Exchange()
igor_v 0:8ad47e2b6f00 78 {
igor_v 0:8ad47e2b6f00 79 ResetCS(ADC); //prepare ADC for sampling
igor_v 0:8ad47e2b6f00 80 SetDAC(DAC);
igor_v 0:8ad47e2b6f00 81 LPC_GPIO2->FIOSET |= 0x0000004; // turn on the LED
igor_v 0:8ad47e2b6f00 82 //LPC_GPIO2->FIOSET |= 0x0000004; // turn on the LED
igor_v 0:8ad47e2b6f00 83 //LPC_GPIO2->FIOSET |= 0x0000004; // turn on the LED
igor_v 0:8ad47e2b6f00 84 SetCS(ADC); //start ADC sampling
igor_v 0:8ad47e2b6f00 85 ResetDAC(DAC);
igor_v 0:8ad47e2b6f00 86 }