![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
forkd
Fork of LGstaandart by
SPI.c@105:bd01d8d20fb6, 2016-03-31 (annotated)
- Committer:
- Kovalev_D
- Date:
- Thu Mar 31 14:03:40 2016 +0000
- Revision:
- 105:bd01d8d20fb6
- Parent:
- 104:ab1cb4ff56b2
- Child:
- 109:ee0cff33ad3b
iopoi
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
igor_v | 0:8ad47e2b6f00 | 1 | #include "Global.h" |
igor_v | 0:8ad47e2b6f00 | 2 | struct SPI Spi; |
Kovalev_D | 86:398da56ef751 | 3 | unsigned int Temp_AMP; |
Kovalev_D | 96:1c8536458119 | 4 | unsigned int Temp_AMP64P; |
igor_v | 31:c783288001b5 | 5 | |
Kovalev_D | 99:3d8f206ceac2 | 6 | unsigned int Count_AMP, ADD_AMP, Cur_Amp; |
Kovalev_D | 99:3d8f206ceac2 | 7 | int Znak_Amp; |
Kovalev_D | 99:3d8f206ceac2 | 8 | |
Kovalev_D | 86:398da56ef751 | 9 | unsigned int Temp_ADC_2; |
Kovalev_D | 86:398da56ef751 | 10 | unsigned int Temp_ADC_3; |
Kovalev_D | 86:398da56ef751 | 11 | unsigned int Temp_ADC_4; |
Kovalev_D | 86:398da56ef751 | 12 | unsigned int Temp_ADC_5; |
igor_v | 31:c783288001b5 | 13 | |
igor_v | 31:c783288001b5 | 14 | |
Kovalev_D | 95:dd51e577e114 | 15 | unsigned int Buff_ADC_1 [32]; |
Kovalev_D | 95:dd51e577e114 | 16 | unsigned int Buff_ADC_2 [32]; |
Kovalev_D | 95:dd51e577e114 | 17 | unsigned int Buff_ADC_3 [32]; |
Kovalev_D | 95:dd51e577e114 | 18 | unsigned int Buff_ADC_4 [32]; |
igor_v | 51:81f47b817071 | 19 | |
igor_v | 31:c783288001b5 | 20 | unsigned int Buff_ADC_5 [256]; |
igor_v | 31:c783288001b5 | 21 | unsigned int Buff_AMP [256]; |
Kovalev_D | 96:1c8536458119 | 22 | unsigned int Buff_AMP64P [256]; |
igor_v | 31:c783288001b5 | 23 | unsigned int SinPLC[64]= {1023, 1016, 1006, 993, 976, 954, 904, 874, 841, 806, 768, 728, |
igor_v | 31:c783288001b5 | 24 | 687, 645, 601, 557, 500, 379, 337, 296, 256, 219, 183, 150, |
igor_v | 31:c783288001b5 | 25 | 120, 93, 69, 48, 31, 18, 8, 0, 8, 18, 31, 48, |
igor_v | 31:c783288001b5 | 26 | 69, 93, 120, 150, 183, 219, 256, 296, 337, 379, 468, 512, 557, |
igor_v | 31:c783288001b5 | 27 | 601, 645, 687, 728, 768, 806, 841, 874, 904, 954, 976, 993, 1006, |
igor_v | 31:c783288001b5 | 28 | 1016, 1023 |
igor_v | 31:c783288001b5 | 29 | }; |
Kovalev_D | 86:398da56ef751 | 30 | |
Kovalev_D | 89:a0d344db227e | 31 | void SPI_Exchange(void) |
igor_v | 0:8ad47e2b6f00 | 32 | { |
Kovalev_D | 89:a0d344db227e | 33 | unsigned int DummySPI; |
Kovalev_D | 99:3d8f206ceac2 | 34 | int Delta; |
Kovalev_D | 99:3d8f206ceac2 | 35 | |
igor_v | 31:c783288001b5 | 36 | |
igor_v | 31:c783288001b5 | 37 | Spi.ADC5 = LPC_SSP0->DR; |
igor_v | 31:c783288001b5 | 38 | Spi.ADC4 = LPC_SSP0->DR; |
igor_v | 31:c783288001b5 | 39 | Spi.ADC3 = LPC_SSP0->DR; |
igor_v | 31:c783288001b5 | 40 | Spi.ADC2 = LPC_SSP0->DR; |
igor_v | 31:c783288001b5 | 41 | Spi.ADC1 = LPC_SSP0->DR; |
igor_v | 31:c783288001b5 | 42 | |
igor_v | 31:c783288001b5 | 43 | Input.ArrayIn[2]= Spi.ADC5; |
igor_v | 0:8ad47e2b6f00 | 44 | |
igor_v | 31:c783288001b5 | 45 | LPC_SSP0->DR=0x5555; |
igor_v | 31:c783288001b5 | 46 | LPC_SSP0->DR=0x5555; |
igor_v | 31:c783288001b5 | 47 | LPC_SSP0->DR=0x5555; |
igor_v | 0:8ad47e2b6f00 | 48 | |
igor_v | 31:c783288001b5 | 49 | if (CountV31 & 1) { //если нечетный такт то |
igor_v | 31:c783288001b5 | 50 | LPC_SSP0->DR = WRITE_DAC0; //e.команда для ЦАП_0 передавать. |
igor_v | 31:c783288001b5 | 51 | LPC_SSP0->DR = (Spi.DAC_A); //e. передача 12 бит |
igor_v | 31:c783288001b5 | 52 | } else { //если такт четный. |
igor_v | 31:c783288001b5 | 53 | LPC_SSP0->DR = WRITE_DAC1 ; //e.команда для ЦАП_1 передавать. |
igor_v | 31:c783288001b5 | 54 | LPC_SSP0->DR = (Spi.DAC_B); //e. передача 12 бит |
igor_v | 31:c783288001b5 | 55 | } |
igor_v | 0:8ad47e2b6f00 | 56 | |
Kovalev_D | 99:3d8f206ceac2 | 57 | // LPC_DAC->CR = (((SinPLC[CountV64]*35/5)+24300));// модулятор |
Kovalev_D | 99:3d8f206ceac2 | 58 | // LPC_DAC->CR = (((SinPLC[CountV64]*35/5)+24300));// модулятор |
Kovalev_D | 89:a0d344db227e | 59 | while (LPC_SSP0->SR & RX_SSP_notEMPT) //если буфер SPI не пуст. |
Kovalev_D | 89:a0d344db227e | 60 | DummySPI = LPC_SSP0->DR; //очистить буфер. |
igor_v | 31:c783288001b5 | 61 | |
igor_v | 31:c783288001b5 | 62 | |
Kovalev_D | 95:dd51e577e114 | 63 | Buff_ADC_1 [CountV31] = Spi.ADC1; |
Kovalev_D | 95:dd51e577e114 | 64 | Buff_ADC_2 [CountV31] = Spi.ADC2; |
Kovalev_D | 95:dd51e577e114 | 65 | Buff_ADC_3 [CountV31] = Spi.ADC3; |
Kovalev_D | 95:dd51e577e114 | 66 | Buff_ADC_4 [CountV31] = Spi.ADC4; |
Kovalev_D | 95:dd51e577e114 | 67 | Buff_ADC_5 [CountV255] = Spi.ADC5; // ампл ацп. |
Kovalev_D | 95:dd51e577e114 | 68 | |
Kovalev_D | 95:dd51e577e114 | 69 | |
Kovalev_D | 96:1c8536458119 | 70 | // Temp_AMP += Buff_ADC_5[CountV255]; |
Kovalev_D | 96:1c8536458119 | 71 | // Temp_AMP -= Buff_ADC_5[(CountV255-32) & 0xff]; // заполнение буфера накопленых приращений за 8 тактов |
Kovalev_D | 96:1c8536458119 | 72 | // Buff_AMP[CountV255] = (unsigned int) (Temp_AMP); |
Kovalev_D | 96:1c8536458119 | 73 | |
Kovalev_D | 96:1c8536458119 | 74 | Temp_AMP += Buff_ADC_5[CountV255]; |
Kovalev_D | 96:1c8536458119 | 75 | Temp_AMP -= Buff_ADC_5[(CountV255-32) & 0xff]; // з |
Kovalev_D | 96:1c8536458119 | 76 | Temp_AMP += Buff_ADC_5[(CountV255-64) & 0xff]; // |
Kovalev_D | 96:1c8536458119 | 77 | Temp_AMP -= Buff_ADC_5[(CountV255-96) & 0xff]; // з |
Kovalev_D | 96:1c8536458119 | 78 | Buff_AMP[CountV255] = (unsigned int) (Temp_AMP); |
Kovalev_D | 99:3d8f206ceac2 | 79 | |
Kovalev_D | 99:3d8f206ceac2 | 80 | ADD_AMP+=Spi.ADC5; |
Kovalev_D | 99:3d8f206ceac2 | 81 | Count_AMP++; |
Kovalev_D | 105:bd01d8d20fb6 | 82 | if(Gyro.RgConA&0x2){ |
Kovalev_D | 104:ab1cb4ff56b2 | 83 | if(Count_AMP>=(32*32)) |
Kovalev_D | 99:3d8f206ceac2 | 84 | { |
Kovalev_D | 99:3d8f206ceac2 | 85 | Delta = ADD_AMP - Cur_Amp; |
Kovalev_D | 104:ab1cb4ff56b2 | 86 | if ( Delta > 3000000 ) Spi.DAC_B += 100; |
Kovalev_D | 104:ab1cb4ff56b2 | 87 | else if ( Delta < (-300000) ) Spi.DAC_B += 100; |
Kovalev_D | 99:3d8f206ceac2 | 88 | else if ((Delta * Znak_Amp) > 0) |
Kovalev_D | 99:3d8f206ceac2 | 89 | { |
Kovalev_D | 104:ab1cb4ff56b2 | 90 | Spi.DAC_B += 1 ; |
Kovalev_D | 99:3d8f206ceac2 | 91 | Znak_Amp = 1; |
Kovalev_D | 99:3d8f206ceac2 | 92 | } |
Kovalev_D | 99:3d8f206ceac2 | 93 | else |
Kovalev_D | 99:3d8f206ceac2 | 94 | { |
Kovalev_D | 104:ab1cb4ff56b2 | 95 | Spi.DAC_B -= 1; |
Kovalev_D | 99:3d8f206ceac2 | 96 | Znak_Amp = -1; |
Kovalev_D | 99:3d8f206ceac2 | 97 | } |
Kovalev_D | 99:3d8f206ceac2 | 98 | Cur_Amp=ADD_AMP; Count_AMP=0; ADD_AMP=0; |
Kovalev_D | 99:3d8f206ceac2 | 99 | } |
Kovalev_D | 105:bd01d8d20fb6 | 100 | } |
Kovalev_D | 99:3d8f206ceac2 | 101 | |
Kovalev_D | 99:3d8f206ceac2 | 102 | |
Kovalev_D | 96:1c8536458119 | 103 | |
Kovalev_D | 96:1c8536458119 | 104 | |
Kovalev_D | 96:1c8536458119 | 105 | Temp_AMP64P += Buff_ADC_5[CountV255]; |
Kovalev_D | 96:1c8536458119 | 106 | Temp_AMP64P -= Buff_ADC_5[(CountV255-64) & 0xff]; // заполнение буфера накопленых приращений за 8 тактов |
Kovalev_D | 96:1c8536458119 | 107 | Buff_AMP64P[CountV255] = (unsigned int) (Temp_AMP64P); |
Kovalev_D | 96:1c8536458119 | 108 | |
igor_v | 31:c783288001b5 | 109 | |
Kovalev_D | 47:d902ef6f7564 | 110 | Temp_ADC_2 += Buff_ADC_2[CountV31]; |
Kovalev_D | 47:d902ef6f7564 | 111 | Temp_ADC_2 -= Buff_ADC_2[(CountV31-32) & 0xff]; |
igor_v | 31:c783288001b5 | 112 | |
Kovalev_D | 47:d902ef6f7564 | 113 | Temp_ADC_3 += Buff_ADC_3[CountV31]; |
Kovalev_D | 95:dd51e577e114 | 114 | Temp_ADC_3 -= Buff_ADC_3[(CountV31-32) & 0xff]; |
igor_v | 31:c783288001b5 | 115 | |
Kovalev_D | 47:d902ef6f7564 | 116 | Temp_ADC_4 += Buff_ADC_4[CountV31]; |
Kovalev_D | 47:d902ef6f7564 | 117 | Temp_ADC_4 -= Buff_ADC_4[(CountV31-32) & 0xff]; |
igor_v | 31:c783288001b5 | 118 | |
igor_v | 31:c783288001b5 | 119 | Temp_ADC_5 += Buff_ADC_1[CountV255]; |
igor_v | 31:c783288001b5 | 120 | Temp_ADC_5 -= Buff_ADC_1[(CountV255-32) & 0xff]; |
igor_v | 21:bc8c1cec3da6 | 121 | } |