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