Rev 2162 Rev 2163
Line 2... Line 2...
2 #include <math.h> 2 #include <math.h>
3   3  
4 #define INTN_PIN PIN_D7 4 #define INTN_PIN PIN_D7
5 #include "GP2.h" 5 #include "GP2.h"
6   6  
7 #define VERSION 0.2 7 #define VERSION "0.2"
8   8  
9 #define ONE_WIRE_PIN PIN_E2 9 #define ONE_WIRE_PIN PIN_E2
10 #include "ds1820.c" 10 #include "ds1820.c"
11   11  
12 void main() 12 void main()
Line 19... Line 19...
19 setup_timer_2(T2_DISABLED,0,1); 19 setup_timer_2(T2_DISABLED,0,1);
20 setup_ccp1(CCP_OFF); 20 setup_ccp1(CCP_OFF);
21 setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard 21 setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
22   22  
23 TDC_reset(); 23 TDC_reset();
24   -  
25 delay_ms(50); 24 delay_ms(50);
26   25  
27 int16 ret16; -  
28 int8 ret8; -  
29   -  
30 TDC_reset(); -  
31 delay_ms(100); -  
32 -  
33 while(TRUE) 26 while(TRUE)
34 { 27 {
35 28
36 //----------------------------------------------- Nastaveni registru 29 //----------------------------------------------- Nastaveni registru
37 30  
-   31 TDC_reset();
-   32 delay_ms(50);
38 MRange=TDC_MRANGE2; // sets measurement mode 33 MRange=TDC_MRANGE2; // sets measurement mode
39 hit1=TDC_MRANGE2_HIT1_START; 34 hit1=TDC_MRANGE2_HIT1_START;
40 hitin1=TDC_HITIN1_4; // set nomber of hits on channel 1 35 hitin1=TDC_HITIN1_4; // set nomber of hits on channel 1
41 hitin2=TDC_HITIN2_0; // disable channel 2 (normal state for this mode) 36 hitin2=TDC_HITIN2_0; // disable channel 2 (normal state for this mode)
42 en_int= TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT; // eneble all possible interrupt flags 37 en_int= TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT; // eneble all possible interrupt flags
Line 56... Line 51...
56 51
57 TDC_init(); 52 TDC_init();
58 delay_ms(50); 53 delay_ms(50);
59 TDC_start_cycle(); 54 TDC_start_cycle();
60 While(!input(INTN_PIN)); // waiting for interrupt flag 55 While(!input(INTN_PIN)); // waiting for interrupt flag
-   56
-   57 // STOP2 INPUT MUST BE PULLED HIGH - else GP2 does not respond to stop pulses!
61 58
62 //----------------------------------------------- Pocitani 59 //----------------------------------------------- Pocitani
63   60  
-   61 printf("$TDC%s M2 ", VERSION);
64 // printf("Time2: %LX %LX %LX %LX ", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4)); 62 printf("%3.7f %3.7f %3.7f \r\n", TDC_mrange2_get_time(1), TDC_mrange2_get_time(2), TDC_mrange2_get_time(3));
65   63  
66 -  
67 output_low(TDC_ENABLE); //status register read -  
68 ret8=0; 64 TDC_init();
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); -  
73 -  
74 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()); //status register print -  
75   -  
76 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)); -  
77   65  
78   66  
79 //----------------------------------------------- Nastaveni registru 67 //----------------------------------------------- Nastaveni registru
80 68
81 /* MRange=TDC_MRANGE1; 69 /* MRange=TDC_MRANGE1;
Line 112... Line 100...
112   100  
113 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()); 101 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());
114   102  
115 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)); 103 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));
116   104  
117 /// ----------------------------------------------- Temperature masurement -  
118   105  
119 */ 106 */
-   107 /// ----------------------------------------------- Temperature masurement
120 TDC_reset(); 108 TDC_reset();
-   109 delay_ms(50);
-   110  
-   111 //For temperature measurement TDC unit must be initialised in measurement mode2 this is not destribed in datasheet!!
-   112  
-   113 hit1=TDC_MRANGE2_HIT1_START;
-   114 hitin1=TDC_HITIN1_4; // set number of hits on channel 1
-   115 hitin2=TDC_HITIN2_0; // disable channel 2 (normal state for this mode)
-   116 en_int= TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT; // eneble all possible interrupt flags
-   117 en_err_val=TDC_ERRVAL_EN; // enable of error value output
-   118 clkhsdiv=TDC_CLKHSDIV_4; // divide clkHS by 4
-   119
121 portnum=TDC_TPORTNUM_4; 120 portnum=TDC_TPORTNUM_4;
122 Tcycle=TDC_TCYCLE_SHORT; 121 Tcycle=TDC_TCYCLE_SHORT;
123 fakenum=TDC_TFAKENUM_2; 122 fakenum=TDC_TFAKENUM_2;
124 selclkT=TDC_TSELCLK_128HS; 123 selclkT=TDC_TSELCLK_128HS;
125   124  
126 TDC_update_registers(); 125 TDC_update_registers();
-   126 delay_ms(10);
127   127  
128 TDC_init(); 128 TDC_init();
-   129 delay_ms(50);
-   130  
129 TDC_start_temp(); 131 TDC_start_temp();
130 132
131 -  
132 output_low(TDC_ENABLE); //status register -  
133 ret8=0; -  
134 ret8=(0b1011<<4)|4; -  
135 spi_xfer(TDC_stream,ret8,8); -  
136 ret16=spi_xfer(TDC_stream,0,16); -  
137 output_high(TDC_ENABLE); -  
138 printf("Temp: %LX %LX %LX %LX ", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4)); 133 printf("$TDC%s TMP %10LU %10LU %10LU %10LU ", VERSION, TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4));
139 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()); 134 printf("%f \r\n",ds1820_read()+273.15);
140 } 135 }
141 } 136 }