Rev Author Line No. Line
1744 kakl 1 #include "main.h"
2012 kaklik 2 #include <math.h>
2160 kaklik 3 #include "GP2.h"
1744 kakl 4  
1886 kakl 5 #define VERSION 0.2
1757 kakl 6  
1774 kaklik 7 #define ONE_WIRE_PIN PIN_E2
8 #include "ds1820.c"
9  
1744 kakl 10 void main()
11 {
2012 kaklik 12 setup_adc_ports(NO_ANALOGS|VSS_VDD);
13 setup_adc(ADC_CLOCK_DIV_2);
14 setup_spi(SPI_SS_DISABLED);
15 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
16 setup_timer_1(T1_DISABLED);
17 setup_timer_2(T2_DISABLED,0,1);
18 setup_ccp1(CCP_OFF);
19 setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
1744 kakl 20  
1745 kakl 21 TDC_reset();
1886 kakl 22  
1815 kaklik 23 delay_ms(50);
24  
1886 kakl 25 int16 ret16;
26 int8 ret8;
1815 kaklik 27  
1967 kaklik 28 TDC_reset();
29 delay_ms(100);
1886 kakl 30  
1980 kaklik 31 while(TRUE)
32 {
2015 kaklik 33  
1886 kakl 34 //----------------------------------------------- Nastaveni registru
1980 kaklik 35  
36 MRange=TDC_MRANGE2; // sets measurement mode
1965 kaklik 37 hit1=TDC_MRANGE2_HIT1_START;
1980 kaklik 38 hitin1=TDC_HITIN1_4; // set nomber of hits on channel 1
39 hitin2=TDC_HITIN2_0; // disable channel 2 (normal state for this mode)
40 en_int= TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT; // eneble all possible interrupt flags
41 en_err_val=TDC_ERRVAL_EN; // enable of error value output
42 clkhsdiv=TDC_CLKHSDIV_4; // divide clkHS by 4
43  
44 delval1=0x0; // windowing disabled
1965 kaklik 45 delval2=0x0;
46 delval3=0x0;
47  
48 TDC_update_registers();
1931 kaklik 49  
1967 kaklik 50 delay_ms(100);
1980 kaklik 51  
52 //----------------------------------------------- Mereni 2
1886 kakl 53  
54 TDC_init();
55  
1759 kakl 56 delay_ms(50);
1886 kakl 57  
58 TDC_start_cycle();
59  
60 delay_ms(200);
2160 kaklik 61  
1886 kakl 62 //----------------------------------------------- Pocitani
1964 kaklik 63  
2013 kaklik 64 // printf("Time2: %LX %LX %LX %LX ", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4));
2012 kaklik 65  
1886 kakl 66  
1964 kaklik 67 output_low(TDC_ENABLE); //status register
1886 kakl 68 ret8=0;
69 ret8=(0b1011<<4)|4;
70 spi_xfer(TDC_stream,ret8,8);
71 ret16=spi_xfer(TDC_stream,0,16);
72 output_high(TDC_ENABLE);
1967 kaklik 73 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());
74  
2012 kaklik 75 printf("Time2: %3.7f %3.7f %3.7f \r\n", TDC_mrange2_get_time(1), TDC_mrange2_get_time(2), TDC_mrange2_get_time(3));
76  
77  
1980 kaklik 78 //----------------------------------------------- Nastaveni registru
79  
80 MRange=TDC_MRANGE1;
81 hit1=TDC_MRANGE1_HIT1_NOAC;
82 hit2=TDC_MRANGE1_HIT2_NOAC;
83 hitin1=TDC_HITIN1_1;
84 hitin2=TDC_HITIN2_1;
85 en_int= TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT;
86 en_err_val=TDC_ERRVAL_EN;
87 clkhsdiv=TDC_CLKHSDIV_4;
88 delval1=0x0;
89 delval2=0x0;
90 delval3=0x0;
91  
92 TDC_update_registers();
93  
94 delay_ms(100);
95  
96  
97 //----------------------------------------------- Mereni 1
98  
99 TDC_init();
100  
101 //----------------------------------------------- Pocitani
102  
2013 kaklik 103 // printf("Time1: %LX %LX %LX %LX ", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4));
2012 kaklik 104  
1980 kaklik 105 output_low(TDC_ENABLE); //status register
106 ret8=0;
107 ret8=(0b1011<<4)|4;
108 spi_xfer(TDC_stream,ret8,8);
109 ret16=spi_xfer(TDC_stream,0,16);
110 output_high(TDC_ENABLE);
2012 kaklik 111  
1980 kaklik 112 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());
113  
2012 kaklik 114 printf("Time1: %3.7f %3.7f %3.7f \r\n", TDC_mrange1_get_time(1,0,1,1), TDC_mrange1_get_time(2,0,2,1), TDC_mrange1_get_time(1,1,2,1));
1980 kaklik 115  
116 /// ----------------------------------------------- Temperature masurement
117  
2013 kaklik 118  
119 TDC_reset();
120 portnum=TDC_TPORTNUM_4;
121 Tcycle=TDC_TCYCLE_SHORT;
122 fakenum=TDC_TFAKENUM_2;
123 selclkT=TDC_TSELCLK_128HS;
124  
125 TDC_update_registers();
126  
127 TDC_init();
1967 kaklik 128 TDC_start_temp();
2013 kaklik 129  
130  
1967 kaklik 131 output_low(TDC_ENABLE); //status register
132 ret8=0;
133 ret8=(0b1011<<4)|4;
134 spi_xfer(TDC_stream,ret8,8);
135 ret16=spi_xfer(TDC_stream,0,16);
136 output_high(TDC_ENABLE);
2011 kaklik 137 printf("Temp: %LX %LX %LX %LX ", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4));
138 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());
1886 kakl 139 }
1744 kakl 140 }