Line 37... |
Line 37... |
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)); |
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)); |
38 |
printf("%f \r\n",ds1820_read()+273.15); |
38 |
printf("%f \r\n",ds1820_read()+273.15); |
39 |
|
39 |
|
40 |
} |
40 |
} |
41 |
|
41 |
|
42 |
void measurementM1() |
42 |
void measurementM1(unsigned int hits1,unsigned int hits2,) |
43 |
{ |
43 |
{ |
- |
|
44 |
TDC_reset(); |
- |
|
45 |
delay_ms(50); |
- |
|
46 |
en_int= TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT; // eneble all possible interrupt flags |
- |
|
47 |
en_err_val=TDC_ERRVAL_EN; // enable of error value output |
- |
|
48 |
clkhsdiv=TDC_CLKHSDIV_4; // divide clkHS by 2 |
- |
|
49 |
firenum=TDC_FIRENUM_1; |
- |
|
50 |
calibrate=TDC_CALIBRATE_EN; |
- |
|
51 |
disautocal=TDC_AUTOCAL_EN; // automatic calibration enabled |
- |
|
52 |
|
- |
|
53 |
rfedge2=TDC_CH2EDGE_FAL_RIS; // stop channels input edge sensityvity selection |
- |
|
54 |
rfedge1=TDC_CH1EDGE_FAL_RIS; |
- |
|
55 |
|
44 |
MRange=TDC_MRANGE1; |
56 |
MRange=TDC_MRANGE1; |
45 |
hit1=TDC_MRANGE1_HIT1_NOAC; |
57 |
hit1=TDC_MRANGE1_HIT1_NOAC; |
46 |
hit2=TDC_MRANGE1_HIT2_NOAC; |
58 |
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; |
- |
|
- |
|
59 |
|
- |
|
60 |
|
52 |
delval1=0x0; |
61 |
delval1=0x0; |
53 |
delval2=0x0; |
62 |
delval2=0x0; |
54 |
delval3=0x0; |
63 |
delval3=0x0; |
- |
|
64 |
|
- |
|
65 |
switch(hits2) // sets number of hits on channel 1 |
- |
|
66 |
{ |
- |
|
67 |
case 0: |
- |
|
68 |
hitin2=TDC_HITIN2_0; |
- |
|
69 |
break; |
- |
|
70 |
|
- |
|
71 |
case 1: |
- |
|
72 |
hitin2=TDC_HITIN2_1; |
- |
|
73 |
break; |
- |
|
74 |
|
- |
|
75 |
case 2: |
- |
|
76 |
hitin2=TDC_HITIN2_2; |
- |
|
77 |
break; |
- |
|
78 |
|
- |
|
79 |
case 3: |
- |
|
80 |
hitin2=TDC_HITIN2_3; |
- |
|
81 |
break; |
- |
|
82 |
|
- |
|
83 |
case 4: |
- |
|
84 |
hitin2=TDC_HITIN2_4; |
- |
|
85 |
break; |
- |
|
86 |
|
- |
|
87 |
default: return; |
- |
|
88 |
} |
- |
|
89 |
|
- |
|
90 |
switch(hits1) // sets number of hits on channel 1 |
- |
|
91 |
{ |
- |
|
92 |
case 0: |
- |
|
93 |
hitin1=TDC_HITIN1_0; |
- |
|
94 |
break; |
- |
|
95 |
|
- |
|
96 |
case 1: |
- |
|
97 |
hitin1=TDC_HITIN1_1; |
- |
|
98 |
break; |
- |
|
99 |
|
- |
|
100 |
case 2: |
- |
|
101 |
hitin1=TDC_HITIN1_2; |
- |
|
102 |
break; |
- |
|
103 |
|
- |
|
104 |
case 3: |
- |
|
105 |
hitin1=TDC_HITIN1_3; |
- |
|
106 |
break; |
- |
|
107 |
|
- |
|
108 |
case 4: |
- |
|
109 |
hitin1=TDC_HITIN1_4; |
- |
|
110 |
break; |
- |
|
111 |
|
- |
|
112 |
default: return; |
55 |
|
113 |
} |
- |
|
114 |
|
56 |
TDC_update_registers(); |
115 |
TDC_update_registers(); |
57 |
|
116 |
|
58 |
delay_ms(100); |
117 |
delay_ms(50); |
59 |
|
118 |
|
60 |
|
119 |
|
61 |
//----------------------------------------------- Mereni 1 |
120 |
//----------------------------------------------- Mereni 1 |
62 |
|
121 |
|
63 |
TDC_init(); |
122 |
TDC_init(); |
- |
|
123 |
// TDC_start_cycle(); // Fire pulse generator activation |
- |
|
124 |
delay_ms(100); |
- |
|
125 |
|
- |
|
126 |
While(!input(INTN_PIN)); // waiting for interrupt flag |
64 |
|
127 |
|
65 |
//----------------------------------------------- Pocitani |
128 |
//----------------------------------------------- Pocitani |
66 |
|
129 |
|
67 |
// printf("Time1: %LX %LX %LX %LX ", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4)); |
130 |
// printf("Time1: %LX %LX %LX %LX ", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4)); |
68 |
|
131 |
|
Line 73... |
Line 136... |
73 |
ret16=spi_xfer(TDC_stream,0,16); |
136 |
ret16=spi_xfer(TDC_stream,0,16); |
74 |
output_high(TDC_ENABLE); |
137 |
output_high(TDC_ENABLE); |
75 |
|
138 |
|
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()); |
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()); |
77 |
*/ |
140 |
*/ |
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 |
|
141 |
|
- |
|
142 |
printf("[%Lu %Lu %Lu %Lu %Lu %Lu %Lu]\r\n", (1&(TDC_get_status())>>12), (1&(TDC_get_status())>>11), (1&(TDC_get_status())>>10), 1&(TDC_get_status())>>9, 7&(TDC_get_status())>>6, 7&(TDC_get_status())>>3, 7&TDC_get_status()); |
80 |
|
143 |
|
- |
|
144 |
printf("$TDC%s M1 ", VERSION); |
- |
|
145 |
printf("%f %f", TDC_mrange1_get_time(1,1,1,2), TDC_mrange1_get_time(1,0,1,1)); |
- |
|
146 |
|
- |
|
147 |
// syntax TDC_mrange1_get_time(Channel, shot, Channel , shot ) |
- |
|
148 |
|
- |
|
149 |
printf("\r\n"); |
81 |
} |
150 |
} |
82 |
|
151 |
|
83 |
|
152 |
|
84 |
void measurementM2(unsigned int hits) |
153 |
void measurementM2(unsigned int hits) |
85 |
{ |
154 |
{ |
- |
|
155 |
unsigned int i; |
- |
|
156 |
|
86 |
TDC_reset(); |
157 |
TDC_reset(); |
87 |
delay_ms(50); |
158 |
delay_ms(50); |
88 |
MRange=TDC_MRANGE2; // sets measurement mode |
159 |
MRange=TDC_MRANGE2; // sets measurement mode |
89 |
hit1=TDC_MRANGE2_HIT1_START; |
- |
|
90 |
// hitin1=TDC_HITIN1_4; // set nomber of hits on channel 1 |
160 |
hit1=TDC_MRANGE2_HIT1_START; // time is always counted from start pulse at this measurement mode |
91 |
hitin2=TDC_HITIN2_0; // disable channel 2 (normal state for this mode) |
161 |
hitin2=TDC_HITIN2_0; // disable channel 2 (normal state for this mode) |
92 |
en_int= TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT; // eneble all possible interrupt flags |
162 |
en_int= TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT; // eneble all possible interrupt flags |
93 |
en_err_val=TDC_ERRVAL_EN; // enable of error value output |
163 |
en_err_val=TDC_ERRVAL_EN; // enable of error value output |
94 |
clkhsdiv=TDC_CLKHSDIV_4; // divide clkHS by 4 |
164 |
clkhsdiv=TDC_CLKHSDIV_4; // divide clkHS by 4 |
95 |
firenum=TDC_FIRENUM_1; |
165 |
firenum=TDC_FIRENUM_1; |
96 |
|
166 |
|
97 |
switch(hits) |
167 |
switch(hits) // sets number of hits on channel 1 |
98 |
{ |
168 |
{ |
99 |
case 1: |
169 |
case 1: |
100 |
hitin1=TDC_HITIN1_2; |
170 |
hitin1=TDC_HITIN1_2; |
101 |
break; |
171 |
break; |
102 |
|
172 |
|
Line 126... |
Line 196... |
126 |
TDC_start_cycle(); |
196 |
TDC_start_cycle(); |
127 |
While(!input(INTN_PIN)); // waiting for interrupt flag |
197 |
While(!input(INTN_PIN)); // waiting for interrupt flag |
128 |
|
198 |
|
129 |
// STOP2 INPUT MUST BE PULLED HIGH - else GP2 does not respond to stop pulses! |
199 |
// STOP2 INPUT MUST BE PULLED HIGH - else GP2 does not respond to stop pulses! |
130 |
|
200 |
|
131 |
//----------------------------------------------- Pocitani |
201 |
//----------------------------------------------- Calculate and print output |
132 |
|
202 |
|
133 |
printf("$TDC%s M2 ", VERSION); |
203 |
printf("$TDC%s M2 ", VERSION); |
134 |
printf("%3.7f %3.7f %3.7f \r\n", TDC_mrange2_get_time(1), TDC_mrange2_get_time(2), TDC_mrange2_get_time(3)); |
204 |
for(i=1;i<=hits;i++) printf(" %4.6f", TDC_mrange2_get_time(i)); |
- |
|
205 |
printf("\r\n"); |
135 |
|
206 |
|
136 |
} |
207 |
} |
137 |
|
208 |
|
138 |
void get_command(char *ptr, unsigned int max) // gets string of defined maximum lenght |
209 |
void get_command(char *ptr, unsigned int max) // gets string of defined maximum lenght |
139 |
{ |
210 |
{ |
Line 150... |
Line 221... |
150 |
return; |
221 |
return; |
151 |
} |
222 |
} |
152 |
len++; |
223 |
len++; |
153 |
} |
224 |
} |
154 |
|
225 |
|
- |
|
226 |
ptr[len]=0; |
155 |
return; |
227 |
return; |
156 |
} |
228 |
} |
157 |
|
229 |
|
158 |
|
230 |
|
159 |
void main() |
231 |
void main() |
160 |
{ |
232 |
{ |
161 |
|
233 |
|
162 |
char command[20]; |
234 |
char command[20]; |
163 |
char tmp[5]; |
235 |
char tmp[5]; |
164 |
char *ptr; |
236 |
char *ptr; |
165 |
unsigned long parameter; |
237 |
unsigned long parameter, parameter2; |
166 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
238 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
167 |
setup_adc(ADC_CLOCK_DIV_2); |
239 |
setup_adc(ADC_CLOCK_DIV_2); |
168 |
setup_spi(SPI_SS_DISABLED); |
240 |
setup_spi(SPI_SS_DISABLED); |
169 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
241 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
170 |
setup_timer_1(T1_DISABLED); |
242 |
setup_timer_1(T1_DISABLED); |
Line 189... |
Line 261... |
189 |
|
261 |
|
190 |
strcpy(tmp,"M2 "); |
262 |
strcpy(tmp,"M2 "); |
191 |
if (!strncmp(command, tmp, 3)) |
263 |
if (!strncmp(command, tmp, 3)) |
192 |
{ |
264 |
{ |
193 |
parameter=strtol(command+3,&ptr,10); |
265 |
parameter=strtol(command+3,&ptr,10); |
194 |
|
- |
|
195 |
printf("%s\r\n", command+3); |
- |
|
196 |
printf("%lu\r\n",parameter); |
- |
|
197 |
measurementM2(parameter); |
266 |
measurementM2(parameter); |
198 |
} |
267 |
} |
199 |
|
268 |
|
200 |
strcpy(tmp,"M1 "); |
269 |
strcpy(tmp,"M1 "); |
201 |
if (!strncmp(command, tmp, 3)) |
270 |
if (!strncmp(command, tmp, 3)) |
202 |
{ |
271 |
{ |
- |
|
272 |
parameter=strtol(command+3,&ptr,10); |
- |
|
273 |
parameter2=strtol(ptr,&ptr,10); |
- |
|
274 |
printf("%lu\r\n", parameter); // echo received command |
- |
|
275 |
printf("%lu\r\n", parameter2); // echo received command |
203 |
measurementM1(); |
276 |
measurementM1(parameter, parameter2); |
204 |
} |
277 |
} |
205 |
|
278 |
|
206 |
} |
279 |
} |
207 |
} |
280 |
} |