Rev Author Line No. Line
1744 kakl 1 #include "main.h"
2  
1886 kakl 3 #define VERSION 0.2
1757 kakl 4  
1759 kakl 5 #define START PIN_D4
6 #define STOP1 PIN_D5
7 #define STOP2 PIN_D6
1886 kakl 8  
1774 kaklik 9 #include "GP2.h"
1759 kakl 10  
1774 kaklik 11 #define ONE_WIRE_PIN PIN_E2
12 #include "ds1820.c"
13  
1744 kakl 14 void main()
15 {
16 setup_adc_ports(NO_ANALOGS|VSS_VDD);
17 setup_adc(ADC_CLOCK_DIV_2);
18 setup_psp(PSP_DISABLED);
19 setup_spi(SPI_SS_DISABLED);
20 setup_wdt(WDT_OFF);
21 setup_timer_0(RTCC_INTERNAL);
22 setup_timer_1(T1_DISABLED);
23 setup_timer_2(T2_DISABLED,0,1);
24 setup_ccp1(CCP_OFF);
25 setup_comparator(NC_NC_NC_NC);
26 setup_vref(FALSE);
27  
1745 kakl 28 TDC_reset();
1886 kakl 29  
1759 kakl 30 output_low(START);
31 output_low(STOP1);
32 output_low(STOP2);
1815 kaklik 33  
34 delay_ms(50);
35  
1886 kakl 36 int16 ret16;
37 int8 ret8;
1815 kaklik 38  
1967 kaklik 39 TDC_reset();
40 delay_ms(100);
1886 kakl 41  
1980 kaklik 42 while(TRUE)
43 {
44  
45  
1886 kakl 46 //----------------------------------------------- Nastaveni registru
1980 kaklik 47  
48 MRange=TDC_MRANGE2; // sets measurement mode
1965 kaklik 49 hit1=TDC_MRANGE2_HIT1_START;
1980 kaklik 50 hitin1=TDC_HITIN1_4; // set nomber of hits on channel 1
51 hitin2=TDC_HITIN2_0; // disable channel 2 (normal state for this mode)
52 en_int= TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT; // eneble all possible interrupt flags
53 en_err_val=TDC_ERRVAL_EN; // enable of error value output
54 clkhsdiv=TDC_CLKHSDIV_4; // divide clkHS by 4
55  
56 delval1=0x0; // windowing disabled
1965 kaklik 57 delval2=0x0;
58 delval3=0x0;
59  
60 TDC_update_registers();
1931 kaklik 61  
1967 kaklik 62 delay_ms(100);
1980 kaklik 63  
64 //----------------------------------------------- Mereni 2
1886 kakl 65  
66 TDC_init();
67  
1759 kakl 68 delay_ms(50);
1886 kakl 69  
70 TDC_start_cycle();
71  
72 delay_ms(200);
73  
74 output_high(STOP2); // Merime jenom jednim kanalem (druhy zrejme musi byt v H)
75  
1759 kakl 76 output_high(START);
1886 kakl 77 output_low(START);
1967 kaklik 78 delay_us(150);
1798 kaklik 79  
1886 kakl 80 output_high(STOP1);
81 output_low(STOP1);
82 delay_us(1);
1759 kakl 83  
1815 kaklik 84 output_high(STOP1);
1886 kakl 85 output_low(STOP1);
1966 kaklik 86 delay_us(10);
1886 kakl 87  
88 output_high(STOP1);
89 output_low(STOP1);
1967 kaklik 90 delay_us(1);
1886 kakl 91  
92 //----------------------------------------------- Pocitani
1964 kaklik 93  
1980 kaklik 94 printf("Time2: %3.7f %3.7f %3.7f ", TDC_mrange2_get_time(1), TDC_mrange2_get_time(2), TDC_mrange2_get_time(3));
1886 kakl 95  
1964 kaklik 96 output_low(TDC_ENABLE); //status register
1886 kakl 97 ret8=0;
98 ret8=(0b1011<<4)|4;
99 spi_xfer(TDC_stream,ret8,8);
100 ret16=spi_xfer(TDC_stream,0,16);
101 output_high(TDC_ENABLE);
1967 kaklik 102 printf("[%Lu %Lu %Lu %Lu %Lu %Lu %Lu]\r\n", (1&(ret16)>>12), (1&(ret16)>>11), (1&(ret16)>>10), 1&(ret16)>>9, 7&(ret16)>>6, 7&(ret16)>>3, 7&TDC_get_status());
103  
1980 kaklik 104 //----------------------------------------------- Nastaveni registru
105  
106 MRange=TDC_MRANGE1;
107 hit1=TDC_MRANGE1_HIT1_NOAC;
108 hit2=TDC_MRANGE1_HIT2_NOAC;
109 hitin1=TDC_HITIN1_1;
110 hitin2=TDC_HITIN2_1;
111 en_int= TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT;
112 en_err_val=TDC_ERRVAL_EN;
113 clkhsdiv=TDC_CLKHSDIV_4;
114 delval1=0x0;
115 delval2=0x0;
116 delval3=0x0;
117  
118 TDC_update_registers();
119  
120 delay_ms(100);
121  
122  
123 //----------------------------------------------- Mereni 1
124  
125 TDC_init();
126  
127 delay_ms(50);
128 output_low(START);
129 output_low(STOP1);
130 output_low(STOP2);
131  
132 output_high(START); // start of time measurement
133 output_low(START);
134  
135 output_high(STOP2);
136 output_high(STOP1);
137  
138 output_low(STOP2);
139 output_low(STOP1);
140  
141 //----------------------------------------------- Pocitani
142  
143 printf("Time1: %3.7f %3.7f %3.7f ", TDC_mrange1_get_time(1,0,1,1), TDC_mrange1_get_time(2,0,2,1), TDC_mrange1_get_time(1,1,2,1));
144 printf("Time1: %LX %LX %LX %LX ", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4));
145  
146 output_low(TDC_ENABLE); //status register
147 ret8=0;
148 ret8=(0b1011<<4)|4;
149 spi_xfer(TDC_stream,ret8,8);
150 ret16=spi_xfer(TDC_stream,0,16);
151 output_high(TDC_ENABLE);
152 printf("[%Lu %Lu %Lu %Lu %Lu %Lu %Lu]\r\n", (1&(ret16)>>12), (1&(ret16)>>11), (1&(ret16)>>10), 1&(ret16)>>9, 7&(ret16)>>6, 7&(ret16)>>3, 7&TDC_get_status());
153  
154  
155 /// ----------------------------------------------- Temperature masurement
156  
1967 kaklik 157 TDC_start_temp();
158 output_low(TDC_ENABLE); //status register
159 ret8=0;
160 ret8=(0b1011<<4)|4;
161 spi_xfer(TDC_stream,ret8,8);
162 ret16=spi_xfer(TDC_stream,0,16);
163 output_high(TDC_ENABLE);
164 printf("Temp: [%Lu %Lu %Lu %Lu %Lu %Lu %Lu] ", (1&(ret16)>>12), (1&(ret16)>>11), (1&(ret16)>>10), 1&(ret16)>>9, 7&(ret16)>>6, 7&(ret16)>>3, 7&TDC_get_status());
165 printf(" %LX %LX %LX %LX \r\n", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4));
166  
1980 kaklik 167  
168  
1886 kakl 169 }
1744 kakl 170 }