![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
forkd
Fork of LG2 by
SPI.c@110:6406b7ac0442, 2016-04-03 (annotated)
- Committer:
- igor_v
- Date:
- Sun Apr 03 05:20:36 2016 +0000
- Revision:
- 110:6406b7ac0442
- Parent:
- 109:ee0cff33ad3b
- Child:
- 112:4a96133a1311
??????? ???????? ?????????? ???, ???? ??? ??????? ?? ?????????? ? ???????????? ??? ?????????? (???? ??????? ??? ??????????)
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 | |
igor_v | 110:6406b7ac0442 | 34 | |
igor_v | 110:6406b7ac0442 | 35 | |
igor_v | 110:6406b7ac0442 | 36 | |
igor_v | 110:6406b7ac0442 | 37 | |
igor_v | 110:6406b7ac0442 | 38 | void SPI_Exchange_I(void) // новая функция чтения, в нецй не должно быть ничего лишнего |
igor_v | 110:6406b7ac0442 | 39 | { |
igor_v | 110:6406b7ac0442 | 40 | unsigned int DummySPI; |
igor_v | 110:6406b7ac0442 | 41 | Spi.ADC5_Accum += LPC_SSP0->DR; // Чтение АЦП |
igor_v | 110:6406b7ac0442 | 42 | Spi.ADC4_Accum += LPC_SSP0->DR; |
igor_v | 110:6406b7ac0442 | 43 | Spi.ADC3_Accum += LPC_SSP0->DR; |
igor_v | 110:6406b7ac0442 | 44 | Spi.ADC2_Accum += LPC_SSP0->DR; |
igor_v | 110:6406b7ac0442 | 45 | Spi.ADC1_Accum += LPC_SSP0->DR; |
igor_v | 110:6406b7ac0442 | 46 | while (LPC_SSP0->SR & RX_SSP_notEMPT) {DummySPI = LPC_SSP0->DR;} //если буфер SPI не пуст.//очистить буфер. |
igor_v | 110:6406b7ac0442 | 47 | LPC_SSP0->DR=0x5555; |
igor_v | 110:6406b7ac0442 | 48 | LPC_SSP0->DR=0x5555; |
igor_v | 110:6406b7ac0442 | 49 | LPC_SSP0->DR=0x5555; |
igor_v | 110:6406b7ac0442 | 50 | |
igor_v | 110:6406b7ac0442 | 51 | if (CountV31 & 1) { // если нечетный такт то |
igor_v | 110:6406b7ac0442 | 52 | LPC_SSP0->DR = WRITE_DAC0; // команда для ЦАП_0 передавать. |
igor_v | 110:6406b7ac0442 | 53 | LPC_SSP0->DR = (Spi.DAC_A); |
igor_v | 110:6406b7ac0442 | 54 | } else { //если такт четный. |
igor_v | 110:6406b7ac0442 | 55 | LPC_SSP0->DR = WRITE_DAC1 ; // команда для ЦАП_1 передавать. |
igor_v | 110:6406b7ac0442 | 56 | LPC_SSP0->DR = (Spi.DAC_B); // передача 12 бит |
igor_v | 110:6406b7ac0442 | 57 | } |
igor_v | 110:6406b7ac0442 | 58 | if (CountV31 == 0) // просто фильтруем по 32 точкам. |
igor_v | 110:6406b7ac0442 | 59 | { |
igor_v | 110:6406b7ac0442 | 60 | Spi.ADC_NewData = 1; // выставояем бит, что есть новы данные |
igor_v | 110:6406b7ac0442 | 61 | Spi.ADC1 = Spi.ADC1_Accum >> 5; // подгоотавливаем данные (в той эе сетке) те ADC1 0..65535 |
igor_v | 110:6406b7ac0442 | 62 | Spi.ADC2 = Spi.ADC2_Accum >> 5; |
igor_v | 110:6406b7ac0442 | 63 | Spi.ADC3 = Spi.ADC3_Accum >> 5; |
igor_v | 110:6406b7ac0442 | 64 | Spi.ADC4 = Spi.ADC4_Accum >> 5; |
igor_v | 110:6406b7ac0442 | 65 | Spi.ADC5 = Spi.ADC5_Accum >> 5; |
igor_v | 110:6406b7ac0442 | 66 | Spi.ADC1_Accum = 0; // сбрасывкем аккамулятор |
igor_v | 110:6406b7ac0442 | 67 | Spi.ADC2_Accum = 0; |
igor_v | 110:6406b7ac0442 | 68 | Spi.ADC3_Accum = 0; |
igor_v | 110:6406b7ac0442 | 69 | Spi.ADC4_Accum = 0; |
igor_v | 110:6406b7ac0442 | 70 | Spi.ADC5_Accum = 0; |
igor_v | 110:6406b7ac0442 | 71 | } |
igor_v | 110:6406b7ac0442 | 72 | } |
igor_v | 110:6406b7ac0442 | 73 | |
igor_v | 110:6406b7ac0442 | 74 | |
Kovalev_D | 89:a0d344db227e | 75 | void SPI_Exchange(void) |
igor_v | 0:8ad47e2b6f00 | 76 | { |
Kovalev_D | 89:a0d344db227e | 77 | unsigned int DummySPI; |
Kovalev_D | 99:3d8f206ceac2 | 78 | int Delta; |
Kovalev_D | 99:3d8f206ceac2 | 79 | |
igor_v | 31:c783288001b5 | 80 | Spi.ADC5 = LPC_SSP0->DR; |
igor_v | 31:c783288001b5 | 81 | Spi.ADC4 = LPC_SSP0->DR; |
igor_v | 31:c783288001b5 | 82 | Spi.ADC3 = LPC_SSP0->DR; |
igor_v | 31:c783288001b5 | 83 | Spi.ADC2 = LPC_SSP0->DR; |
igor_v | 31:c783288001b5 | 84 | Spi.ADC1 = LPC_SSP0->DR; |
igor_v | 31:c783288001b5 | 85 | |
igor_v | 31:c783288001b5 | 86 | Input.ArrayIn[2]= Spi.ADC5; |
igor_v | 0:8ad47e2b6f00 | 87 | |
igor_v | 31:c783288001b5 | 88 | LPC_SSP0->DR=0x5555; |
igor_v | 31:c783288001b5 | 89 | LPC_SSP0->DR=0x5555; |
igor_v | 31:c783288001b5 | 90 | LPC_SSP0->DR=0x5555; |
igor_v | 0:8ad47e2b6f00 | 91 | |
igor_v | 110:6406b7ac0442 | 92 | if (CountV31 & 1) { //если нечетный такт то |
igor_v | 31:c783288001b5 | 93 | LPC_SSP0->DR = WRITE_DAC0; //e.команда для ЦАП_0 передавать. |
igor_v | 31:c783288001b5 | 94 | LPC_SSP0->DR = (Spi.DAC_A); //e. передача 12 бит |
igor_v | 31:c783288001b5 | 95 | } else { //если такт четный. |
igor_v | 31:c783288001b5 | 96 | LPC_SSP0->DR = WRITE_DAC1 ; //e.команда для ЦАП_1 передавать. |
igor_v | 31:c783288001b5 | 97 | LPC_SSP0->DR = (Spi.DAC_B); //e. передача 12 бит |
igor_v | 31:c783288001b5 | 98 | } |
igor_v | 0:8ad47e2b6f00 | 99 | |
Kovalev_D | 99:3d8f206ceac2 | 100 | // LPC_DAC->CR = (((SinPLC[CountV64]*35/5)+24300));// модулятор |
Kovalev_D | 99:3d8f206ceac2 | 101 | // LPC_DAC->CR = (((SinPLC[CountV64]*35/5)+24300));// модулятор |
Kovalev_D | 89:a0d344db227e | 102 | while (LPC_SSP0->SR & RX_SSP_notEMPT) //если буфер SPI не пуст. |
Kovalev_D | 89:a0d344db227e | 103 | DummySPI = LPC_SSP0->DR; //очистить буфер. |
igor_v | 31:c783288001b5 | 104 | |
igor_v | 31:c783288001b5 | 105 | |
Kovalev_D | 95:dd51e577e114 | 106 | Buff_ADC_1 [CountV31] = Spi.ADC1; |
Kovalev_D | 95:dd51e577e114 | 107 | Buff_ADC_2 [CountV31] = Spi.ADC2; |
Kovalev_D | 95:dd51e577e114 | 108 | Buff_ADC_3 [CountV31] = Spi.ADC3; |
Kovalev_D | 95:dd51e577e114 | 109 | Buff_ADC_4 [CountV31] = Spi.ADC4; |
Kovalev_D | 95:dd51e577e114 | 110 | Buff_ADC_5 [CountV255] = Spi.ADC5; // ампл ацп. |
igor_v | 110:6406b7ac0442 | 111 | |
igor_v | 110:6406b7ac0442 | 112 | |
Kovalev_D | 96:1c8536458119 | 113 | // Temp_AMP += Buff_ADC_5[CountV255]; |
Kovalev_D | 96:1c8536458119 | 114 | // Temp_AMP -= Buff_ADC_5[(CountV255-32) & 0xff]; // заполнение буфера накопленых приращений за 8 тактов |
Kovalev_D | 96:1c8536458119 | 115 | // Buff_AMP[CountV255] = (unsigned int) (Temp_AMP); |
Kovalev_D | 96:1c8536458119 | 116 | |
Kovalev_D | 109:ee0cff33ad3b | 117 | // Temp_AMP += Buff_ADC_5[CountV255]; |
Kovalev_D | 109:ee0cff33ad3b | 118 | // Temp_AMP -= Buff_ADC_5[(CountV255-32) & 0xff]; // з |
Kovalev_D | 109:ee0cff33ad3b | 119 | // Temp_AMP += Buff_ADC_5[(CountV255-64) & 0xff]; // |
Kovalev_D | 109:ee0cff33ad3b | 120 | // Temp_AMP -= Buff_ADC_5[(CountV255-96) & 0xff]; // з |
Kovalev_D | 109:ee0cff33ad3b | 121 | // Buff_AMP[CountV255] = (unsigned int) (Temp_AMP); |
Kovalev_D | 99:3d8f206ceac2 | 122 | |
Kovalev_D | 109:ee0cff33ad3b | 123 | ADD_AMP+=Spi.ADC5; |
Kovalev_D | 109:ee0cff33ad3b | 124 | Count_AMP++; |
Kovalev_D | 109:ee0cff33ad3b | 125 | if(Count_AMP>=(32*32+8)) |
Kovalev_D | 99:3d8f206ceac2 | 126 | { |
Kovalev_D | 99:3d8f206ceac2 | 127 | Delta = ADD_AMP - Cur_Amp; |
Kovalev_D | 109:ee0cff33ad3b | 128 | |
Kovalev_D | 109:ee0cff33ad3b | 129 | if(Gyro.RgConA&0x2){ |
Kovalev_D | 109:ee0cff33ad3b | 130 | |
Kovalev_D | 109:ee0cff33ad3b | 131 | |
Kovalev_D | 109:ee0cff33ad3b | 132 | |
Kovalev_D | 109:ee0cff33ad3b | 133 | if (Znak_Amp > 10) {Znak_Amp --;} |
Kovalev_D | 109:ee0cff33ad3b | 134 | else if ( Delta > 30000000 ) {AD_Regul += 5000000; Znak_Amp = 5;} |
Kovalev_D | 109:ee0cff33ad3b | 135 | else if ( Delta < (-3000000)) {AD_Regul += 5000000; Znak_Amp = 5;} |
Kovalev_D | 109:ee0cff33ad3b | 136 | else if ((Delta * Znak_Amp) > 0) |
Kovalev_D | 109:ee0cff33ad3b | 137 | { |
Kovalev_D | 109:ee0cff33ad3b | 138 | // Spi.DAC_B += 1 ; |
Kovalev_D | 109:ee0cff33ad3b | 139 | Znak_Amp = 1; |
Kovalev_D | 109:ee0cff33ad3b | 140 | AD_Regul += (Delta * Znak_Amp * 100); |
Kovalev_D | 109:ee0cff33ad3b | 141 | } |
Kovalev_D | 109:ee0cff33ad3b | 142 | else |
Kovalev_D | 109:ee0cff33ad3b | 143 | { |
Kovalev_D | 109:ee0cff33ad3b | 144 | // Spi.DAC_B -= 1; |
Kovalev_D | 109:ee0cff33ad3b | 145 | Znak_Amp = -1; |
Kovalev_D | 109:ee0cff33ad3b | 146 | AD_Regul += (Delta * Znak_Amp * 100); |
Kovalev_D | 109:ee0cff33ad3b | 147 | } |
Kovalev_D | 109:ee0cff33ad3b | 148 | |
Kovalev_D | 109:ee0cff33ad3b | 149 | Spi.DAC_B = (AD_Regul + 0x1fffffff)/65536; |
Kovalev_D | 109:ee0cff33ad3b | 150 | |
Kovalev_D | 109:ee0cff33ad3b | 151 | |
Kovalev_D | 99:3d8f206ceac2 | 152 | } |
Kovalev_D | 109:ee0cff33ad3b | 153 | |
Kovalev_D | 109:ee0cff33ad3b | 154 | |
Kovalev_D | 109:ee0cff33ad3b | 155 | |
Kovalev_D | 99:3d8f206ceac2 | 156 | Cur_Amp=ADD_AMP; Count_AMP=0; ADD_AMP=0; |
Kovalev_D | 99:3d8f206ceac2 | 157 | } |
igor_v | 110:6406b7ac0442 | 158 | Temp_AMP64P += Buff_ADC_5[CountV255]; |
Kovalev_D | 96:1c8536458119 | 159 | Temp_AMP64P -= Buff_ADC_5[(CountV255-64) & 0xff]; // заполнение буфера накопленых приращений за 8 тактов |
Kovalev_D | 96:1c8536458119 | 160 | Buff_AMP64P[CountV255] = (unsigned int) (Temp_AMP64P); |
Kovalev_D | 96:1c8536458119 | 161 | |
igor_v | 31:c783288001b5 | 162 | |
Kovalev_D | 47:d902ef6f7564 | 163 | Temp_ADC_2 += Buff_ADC_2[CountV31]; |
Kovalev_D | 47:d902ef6f7564 | 164 | Temp_ADC_2 -= Buff_ADC_2[(CountV31-32) & 0xff]; |
igor_v | 31:c783288001b5 | 165 | |
Kovalev_D | 47:d902ef6f7564 | 166 | Temp_ADC_3 += Buff_ADC_3[CountV31]; |
Kovalev_D | 95:dd51e577e114 | 167 | Temp_ADC_3 -= Buff_ADC_3[(CountV31-32) & 0xff]; |
igor_v | 31:c783288001b5 | 168 | |
Kovalev_D | 47:d902ef6f7564 | 169 | Temp_ADC_4 += Buff_ADC_4[CountV31]; |
Kovalev_D | 47:d902ef6f7564 | 170 | Temp_ADC_4 -= Buff_ADC_4[(CountV31-32) & 0xff]; |
igor_v | 31:c783288001b5 | 171 | |
igor_v | 31:c783288001b5 | 172 | Temp_ADC_5 += Buff_ADC_1[CountV255]; |
igor_v | 31:c783288001b5 | 173 | Temp_ADC_5 -= Buff_ADC_1[(CountV255-32) & 0xff]; |
igor_v | 21:bc8c1cec3da6 | 174 | } |