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