Rev 2164 Rev 2178
Line 9... Line 9...
9 #define VERSION "0.2" 9 #define VERSION "0.2"
10   10  
11 #define ONE_WIRE_PIN PIN_E2 11 #define ONE_WIRE_PIN PIN_E2
12 #include "ds1820.c" 12 #include "ds1820.c"
13   13  
14   -  
15 void get_string(char* s, unsigned int8 max) -  
16 { -  
17 unsigned int8 len; -  
18 char c; -  
19   -  
20 --max; -  
21 len=0; -  
22 do { -  
23 c=getc(); -  
24 if(c==8) { // Backspace -  
25 if(len>0) { -  
26 len--; -  
27 putc(c); -  
28 putc(' '); -  
29 putc(c); -  
30 } -  
31 } else if ((c>=' ')&&(c<='~')) -  
32 if(len<=max) { -  
33 s[len++]=c; -  
34 putc(c); -  
35 } -  
36 } while(c!=13); -  
37 s[len]=0; -  
38 } -  
39   -  
40 signed int16 get_int() { -  
41 char s[5]; -  
42 signed int16 i; -  
43   -  
44 get_string(s, 7); -  
45   -  
46 i=atoi(s); -  
47 return(i); -  
48 } -  
49   -  
50 void temperature_measurement() /// Temperature masurement by TDC and dallas sensor 14 void temperature_measurement() /// Temperature masurement by TDC and dallas sensor
51   15  
52 { 16 {
53 //For temperature measurement TDC unit must be initialised in measurement mode2 this is not destribed in datasheet!! 17 //For temperature measurement TDC unit must be initialised in measurement mode2 this is not destribed in datasheet!!
54 TDC_reset(); 18 TDC_reset();
Line 73... Line 37...
73 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)); 37 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));
74 printf("%f \r\n",ds1820_read()+273.15); 38 printf("%f \r\n",ds1820_read()+273.15);
75   39  
76 } 40 }
77   41  
78 void measurementM2() 42 void measurementM1()
-   43 {
-   44 MRange=TDC_MRANGE1;
-   45 hit1=TDC_MRANGE1_HIT1_NOAC;
-   46 hit2=TDC_MRANGE1_HIT2_NOAC;
-   47 hitin1=TDC_HITIN1_1;
-   48 hitin2=TDC_HITIN2_1;
-   49 en_int= TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT;
-   50 en_err_val=TDC_ERRVAL_EN;
-   51 clkhsdiv=TDC_CLKHSDIV_4;
-   52 delval1=0x0;
-   53 delval2=0x0;
-   54 delval3=0x0;
-   55
-   56 TDC_update_registers();
-   57  
-   58 delay_ms(100);
-   59  
-   60  
-   61 //----------------------------------------------- Mereni 1
-   62
-   63 TDC_init();
-   64  
-   65 //----------------------------------------------- Pocitani
-   66  
-   67 // printf("Time1: %LX %LX %LX %LX ", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4));
-   68  
-   69 /* output_low(TDC_ENABLE); //status register
-   70 ret8=0;
-   71 ret8=(0b1011<<4)|4;
-   72 spi_xfer(TDC_stream,ret8,8);
-   73 ret16=spi_xfer(TDC_stream,0,16);
-   74 output_high(TDC_ENABLE);
-   75  
-   76 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());
-   77 */
-   78 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));
-   79  
-   80  
-   81 }
-   82  
-   83  
-   84 void measurementM2(unsigned int hits)
79 { 85 {
80 TDC_reset(); 86 TDC_reset();
81 delay_ms(50); 87 delay_ms(50);
82 MRange=TDC_MRANGE2; // sets measurement mode 88 MRange=TDC_MRANGE2; // sets measurement mode
83 hit1=TDC_MRANGE2_HIT1_START; 89 hit1=TDC_MRANGE2_HIT1_START;
84 hitin1=TDC_HITIN1_4; // set nomber of hits on channel 1 90 // hitin1=TDC_HITIN1_4; // set nomber of hits on channel 1
85 hitin2=TDC_HITIN2_0; // disable channel 2 (normal state for this mode) 91 hitin2=TDC_HITIN2_0; // disable channel 2 (normal state for this mode)
86 en_int= TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT; // eneble all possible interrupt flags 92 en_int= TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT; // eneble all possible interrupt flags
87 en_err_val=TDC_ERRVAL_EN; // enable of error value output 93 en_err_val=TDC_ERRVAL_EN; // enable of error value output
88 clkhsdiv=TDC_CLKHSDIV_4; // divide clkHS by 4 94 clkhsdiv=TDC_CLKHSDIV_4; // divide clkHS by 4
89 firenum=TDC_FIRENUM_1; 95 firenum=TDC_FIRENUM_1;
90 96
-   97 switch(hits)
-   98 {
-   99 case 1:
-   100 hitin1=TDC_HITIN1_2;
-   101 break;
-   102  
-   103 case 2:
-   104 hitin1=TDC_HITIN1_3;
-   105 break;
-   106  
-   107 case 3:
-   108 hitin1=TDC_HITIN1_4;
-   109 break;
-   110  
-   111 default: return;
-   112 }
-   113  
91 delval1=0x0; // windowing disabled 114 delval1=0x0; // windowing disabled
92 delval2=0x0; 115 delval2=0x0;
93 delval3=0x0; 116 delval3=0x0;
94 117
95 TDC_update_registers(); 118 TDC_update_registers();
Line 116... Line 139...
116 void main() 139 void main()
117 { 140 {
118   141  
119 char command[20]; 142 char command[20];
120 char tmp[5]; 143 char tmp[5];
121   -  
-   144 unsigned int parameter;
122 setup_adc_ports(NO_ANALOGS|VSS_VDD); 145 setup_adc_ports(NO_ANALOGS|VSS_VDD);
123 setup_adc(ADC_CLOCK_DIV_2); 146 setup_adc(ADC_CLOCK_DIV_2);
124 setup_spi(SPI_SS_DISABLED); 147 setup_spi(SPI_SS_DISABLED);
125 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); 148 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
126 setup_timer_1(T1_DISABLED); 149 setup_timer_1(T1_DISABLED);
Line 129... Line 152...
129 setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard 152 setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
130   153  
131 TDC_reset(); 154 TDC_reset();
132 delay_ms(50); 155 delay_ms(50);
133   156  
-   157 printf("\r\n\r\n# TDC%s (C) 2011 Jakub Kakona\r\n",VERSION); // Welcome message
-   158 // printf("#%s\r\n",&REV[4]);
-   159  
134 while(TRUE) 160 while(TRUE)
135 { 161 {
-   162 printf("$TDC%s->", VERSION);
136 get_string(command, 20); 163 fgets(command);
-   164 printf("%s\r\n", command);
137 165
138 strcpy(tmp,"TM"); 166 strcpy(tmp,"TM");
139 if (stricmp(command, tmp)) temperature_measurement(); 167 if (!strncmp(command, tmp, 2)) temperature_measurement();
140 strcpy(tmp,"M2"); -  
141 if (stricmp(command, tmp)) measurementM2(); -  
142 -  
143 /* MRange=TDC_MRANGE1; -  
144 hit1=TDC_MRANGE1_HIT1_NOAC; -  
145 hit2=TDC_MRANGE1_HIT2_NOAC; -  
146 hitin1=TDC_HITIN1_1; -  
147 hitin2=TDC_HITIN2_1; -  
148 en_int= TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT; -  
149 en_err_val=TDC_ERRVAL_EN; -  
150 clkhsdiv=TDC_CLKHSDIV_4; -  
151 delval1=0x0; -  
152 delval2=0x0; -  
153 delval3=0x0; -  
154 -  
155 TDC_update_registers(); -  
156   -  
157 delay_ms(100); -  
158   -  
159   -  
160 //----------------------------------------------- Mereni 1 -  
161 -  
162 TDC_init(); -  
163   -  
164 //----------------------------------------------- Pocitani -  
165   -  
166 // printf("Time1: %LX %LX %LX %LX ", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4)); -  
167   -  
168 output_low(TDC_ENABLE); //status register -  
169 ret8=0; -  
170 ret8=(0b1011<<4)|4; -  
171 spi_xfer(TDC_stream,ret8,8); -  
172 ret16=spi_xfer(TDC_stream,0,16); -  
173 output_high(TDC_ENABLE); -  
174   -  
175 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()); -  
176   -  
177 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)); -  
178   168  
-   169 strcpy(tmp,"M2 ");
-   170 if (!strncmp(command, tmp, 3))
-   171 {
-   172 parameter=atoi(command[5]);
-   173 printf("%u\r\n",parameter);
-   174 measurementM2(parameter);
-   175 }
179   176
-   177 strcpy(tmp,"M1 ");
-   178 if (!strncmp(command, tmp, 3))
-   179 {
-   180 measurementM1();
180 */ 181 }
181   182  
182 } 183 }
183 } 184 }