![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
forkd
Fork of LG2 by
SPI.c@47:d902ef6f7564, 2016-02-10 (annotated)
- Committer:
- Kovalev_D
- Date:
- Wed Feb 10 14:06:57 2016 +0000
- Revision:
- 47:d902ef6f7564
- Parent:
- 31:c783288001b5
- Child:
- 51:81f47b817071
??????? ???? ?????????? ????
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; |
igor_v | 31:c783288001b5 | 3 | unsigned int Temp_AMP=0; |
igor_v | 31:c783288001b5 | 4 | |
igor_v | 31:c783288001b5 | 5 | unsigned int Temp_ADC_2=0; |
igor_v | 31:c783288001b5 | 6 | unsigned int Temp_ADC_3=0; |
igor_v | 31:c783288001b5 | 7 | unsigned int Temp_ADC_4=0; |
igor_v | 31:c783288001b5 | 8 | unsigned int Temp_ADC_5=0; |
igor_v | 31:c783288001b5 | 9 | |
igor_v | 31:c783288001b5 | 10 | |
Kovalev_D | 47:d902ef6f7564 | 11 | unsigned int Buff_ADC_1 [16]; |
Kovalev_D | 47:d902ef6f7564 | 12 | unsigned int Buff_ADC_2 [16]; |
Kovalev_D | 47:d902ef6f7564 | 13 | unsigned int Buff_ADC_3 [16]; |
Kovalev_D | 47:d902ef6f7564 | 14 | unsigned int Buff_ADC_4 [16]; |
igor_v | 31:c783288001b5 | 15 | unsigned int Buff_ADC_5 [256]; |
igor_v | 0:8ad47e2b6f00 | 16 | |
igor_v | 31:c783288001b5 | 17 | unsigned int Buff_AMP [256]; |
igor_v | 31:c783288001b5 | 18 | |
igor_v | 31:c783288001b5 | 19 | unsigned int SinPLC[64]= {1023, 1016, 1006, 993, 976, 954, 904, 874, 841, 806, 768, 728, |
igor_v | 31:c783288001b5 | 20 | 687, 645, 601, 557, 500, 379, 337, 296, 256, 219, 183, 150, |
igor_v | 31:c783288001b5 | 21 | 120, 93, 69, 48, 31, 18, 8, 0, 8, 18, 31, 48, |
igor_v | 31:c783288001b5 | 22 | 69, 93, 120, 150, 183, 219, 256, 296, 337, 379, 468, 512, 557, |
igor_v | 31:c783288001b5 | 23 | 601, 645, 687, 728, 768, 806, 841, 874, 904, 954, 976, 993, 1006, |
igor_v | 31:c783288001b5 | 24 | 1016, 1023 |
igor_v | 31:c783288001b5 | 25 | }; |
igor_v | 31:c783288001b5 | 26 | void DACLInit( void ) |
igor_v | 21:bc8c1cec3da6 | 27 | { |
igor_v | 31:c783288001b5 | 28 | /* setup the related pin to DAC output */ |
igor_v | 31:c783288001b5 | 29 | LPC_PINCON->PINSEL1 = 0x00200000; /* set p0.26 to DAC output */ |
igor_v | 31:c783288001b5 | 30 | return; |
igor_v | 21:bc8c1cec3da6 | 31 | } |
igor_v | 0:8ad47e2b6f00 | 32 | void SPI_Exchange() |
igor_v | 0:8ad47e2b6f00 | 33 | { |
igor_v | 31:c783288001b5 | 34 | unsigned int Dummy; |
igor_v | 31:c783288001b5 | 35 | |
igor_v | 31:c783288001b5 | 36 | Spi.ADC5 = LPC_SSP0->DR; |
igor_v | 31:c783288001b5 | 37 | Spi.ADC4 = LPC_SSP0->DR; |
igor_v | 31:c783288001b5 | 38 | Spi.ADC3 = LPC_SSP0->DR; |
igor_v | 31:c783288001b5 | 39 | Spi.ADC2 = LPC_SSP0->DR; |
igor_v | 31:c783288001b5 | 40 | Spi.ADC1 = LPC_SSP0->DR; |
igor_v | 31:c783288001b5 | 41 | |
igor_v | 31:c783288001b5 | 42 | Input.ArrayIn[2]= Spi.ADC5; |
igor_v | 0:8ad47e2b6f00 | 43 | |
igor_v | 31:c783288001b5 | 44 | LPC_SSP0->DR=0x5555; |
igor_v | 31:c783288001b5 | 45 | LPC_SSP0->DR=0x5555; |
igor_v | 31:c783288001b5 | 46 | LPC_SSP0->DR=0x5555; |
igor_v | 0:8ad47e2b6f00 | 47 | |
igor_v | 31:c783288001b5 | 48 | if (CountV31 & 1) { //если нечетный такт то |
igor_v | 31:c783288001b5 | 49 | LPC_SSP0->DR = WRITE_DAC0; //e.команда для ЦАП_0 передавать. |
igor_v | 31:c783288001b5 | 50 | LPC_SSP0->DR = (Spi.DAC_A); //e. передача 12 бит |
igor_v | 31:c783288001b5 | 51 | } else { //если такт четный. |
igor_v | 31:c783288001b5 | 52 | LPC_SSP0->DR = WRITE_DAC1 ; //e.команда для ЦАП_1 передавать. |
igor_v | 31:c783288001b5 | 53 | LPC_SSP0->DR = (Spi.DAC_B); //e. передача 12 бит |
igor_v | 31:c783288001b5 | 54 | } |
igor_v | 0:8ad47e2b6f00 | 55 | |
igor_v | 31:c783288001b5 | 56 | LPC_DAC->CR = (((SinPLC[CountV64]*35)+21300)); |
igor_v | 31:c783288001b5 | 57 | while (LPC_SSP0->SR & RX_SSP_notEMPT) //если буфер SPI не пуст. |
igor_v | 31:c783288001b5 | 58 | Dummy = LPC_SSP0->DR; //очистить буфер. |
igor_v | 31:c783288001b5 | 59 | |
igor_v | 31:c783288001b5 | 60 | |
igor_v | 31:c783288001b5 | 61 | Buff_ADC_1 [CountV255] = Spi.ADC1; // ампл ацп. |
igor_v | 31:c783288001b5 | 62 | Buff_ADC_2 [CountV255] = Spi.ADC2; |
igor_v | 31:c783288001b5 | 63 | Buff_ADC_3 [CountV255] = Spi.ADC3; |
igor_v | 31:c783288001b5 | 64 | Buff_ADC_4 [CountV255] = Spi.ADC4; |
igor_v | 31:c783288001b5 | 65 | Buff_ADC_5 [CountV255] = Spi.ADC5; |
igor_v | 31:c783288001b5 | 66 | |
igor_v | 31:c783288001b5 | 67 | |
igor_v | 0:8ad47e2b6f00 | 68 | |
igor_v | 31:c783288001b5 | 69 | Temp_AMP += Buff_ADC_5[CountV255]; |
igor_v | 31:c783288001b5 | 70 | Temp_AMP -= Buff_ADC_5[(CountV255-32) & 0xff]; // заполнение буфера накопленых приращений за 8 тактов |
igor_v | 31:c783288001b5 | 71 | Buff_AMP[CountV255] = (unsigned int) (Temp_AMP); |
igor_v | 31:c783288001b5 | 72 | |
Kovalev_D | 47:d902ef6f7564 | 73 | Temp_ADC_2 += Buff_ADC_2[CountV31]; |
Kovalev_D | 47:d902ef6f7564 | 74 | Temp_ADC_2 -= Buff_ADC_2[(CountV31-32) & 0xff]; |
igor_v | 31:c783288001b5 | 75 | |
Kovalev_D | 47:d902ef6f7564 | 76 | Temp_ADC_3 += Buff_ADC_3[CountV31]; |
Kovalev_D | 47:d902ef6f7564 | 77 | Temp_ADC_3 -= Buff_ADC_3[(CountV31-23) & 0xff]; |
igor_v | 31:c783288001b5 | 78 | |
Kovalev_D | 47:d902ef6f7564 | 79 | Temp_ADC_4 += Buff_ADC_4[CountV31]; |
Kovalev_D | 47:d902ef6f7564 | 80 | Temp_ADC_4 -= Buff_ADC_4[(CountV31-32) & 0xff]; |
igor_v | 31:c783288001b5 | 81 | |
igor_v | 31:c783288001b5 | 82 | Temp_ADC_5 += Buff_ADC_1[CountV255]; |
igor_v | 31:c783288001b5 | 83 | Temp_ADC_5 -= Buff_ADC_1[(CountV255-32) & 0xff]; |
igor_v | 0:8ad47e2b6f00 | 84 | } |
igor_v | 0:8ad47e2b6f00 | 85 | void Init_SPI_Exchange() |
igor_v | 0:8ad47e2b6f00 | 86 | { |
igor_v | 31:c783288001b5 | 87 | ResetCS(ADC); //prepare ADC for sampling |
igor_v | 31:c783288001b5 | 88 | SetDAC(DAC); |
igor_v | 31:c783288001b5 | 89 | LPC_GPIO2->FIOSET |= 0x0000004; // turn on the LED |
igor_v | 0:8ad47e2b6f00 | 90 | //LPC_GPIO2->FIOSET |= 0x0000004; // turn on the LED |
igor_v | 31:c783288001b5 | 91 | //LPC_GPIO2->FIOSET |= 0x0000004; // turn on the LED |
igor_v | 31:c783288001b5 | 92 | SetCS(ADC); //start ADC sampling |
igor_v | 31:c783288001b5 | 93 | ResetDAC(DAC); |
igor_v | 21:bc8c1cec3da6 | 94 | } |