Line 2... |
Line 2... |
2 |
|
2 |
|
3 |
#include "GP2.h" |
3 |
#include "GP2.h" |
4 |
|
4 |
|
5 |
#define VERSION 0.1 |
5 |
#define VERSION 0.1 |
6 |
|
6 |
|
- |
|
7 |
#define START PIN_D4 |
- |
|
8 |
#define STOP1 PIN_D5 |
- |
|
9 |
#define STOP2 PIN_D6 |
- |
|
10 |
|
7 |
void main() |
11 |
void main() |
8 |
{ |
12 |
{ |
9 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
13 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
10 |
setup_adc(ADC_CLOCK_DIV_2); |
14 |
setup_adc(ADC_CLOCK_DIV_2); |
11 |
setup_psp(PSP_DISABLED); |
15 |
setup_psp(PSP_DISABLED); |
Line 19... |
Line 23... |
19 |
setup_vref(FALSE); |
23 |
setup_vref(FALSE); |
20 |
|
24 |
|
21 |
TDC_reset(); |
25 |
TDC_reset(); |
22 |
|
26 |
|
23 |
hit1=TDC_MRANGE2_HIT1_START; |
27 |
hit1=TDC_MRANGE2_HIT1_START; |
24 |
hit2=TDC_MRANGE2_HIT2_1CH1; |
28 |
hit2=TDC_MRANGE2_HIT2_2CH1; |
25 |
hitin1=TDC_HITIN1_2; |
29 |
hitin1=TDC_HITIN1_2; |
26 |
hitin2=TDC_HITIN1_0; |
30 |
hitin2=TDC_HITIN1_0; |
- |
|
31 |
en_int= 0xFF; //TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT; |
- |
|
32 |
en_err_val=TDC_ERRVAL_EN; |
- |
|
33 |
delval1=0x0; |
- |
|
34 |
delval2=0x0; |
- |
|
35 |
delval3=0x0; |
27 |
|
36 |
|
28 |
TDC_update_registers(); |
37 |
TDC_update_registers(); |
29 |
|
38 |
|
- |
|
39 |
output_low(START); |
- |
|
40 |
output_low(STOP1); |
- |
|
41 |
output_low(STOP2); |
- |
|
42 |
|
- |
|
43 |
TDC_start_cal(); |
- |
|
44 |
delay_ms(50); |
- |
|
45 |
|
30 |
while(true) |
46 |
while(true) |
31 |
{ |
47 |
{ |
- |
|
48 |
|
- |
|
49 |
/* delay_ms(500); |
- |
|
50 |
hit2=0x00; |
- |
|
51 |
hit1=0x00; |
- |
|
52 |
TDC_update_registers(); |
- |
|
53 |
printf("reg1: %X \n", TDC_get_reg1()); |
- |
|
54 |
|
- |
|
55 |
TDC_reset(); |
- |
|
56 |
delay_ms(50); |
- |
|
57 |
printf("reg1: %X \n", TDC_get_reg1()); |
- |
|
58 |
*/ |
32 |
TDC_init(); |
59 |
TDC_init(); |
- |
|
60 |
delay_ms(50); |
- |
|
61 |
printf("status: %LX \n", TDC_get_status()); |
- |
|
62 |
delay_us(10); |
- |
|
63 |
TDC_start_cycle(); |
- |
|
64 |
delay_us(10); |
- |
|
65 |
output_high(START); |
- |
|
66 |
delay_us(1); |
- |
|
67 |
output_low(START); |
- |
|
68 |
|
33 |
delay_ms(500); |
69 |
delay_us(500); |
- |
|
70 |
|
- |
|
71 |
output_high(STOP1); |
- |
|
72 |
delay_us(10); |
- |
|
73 |
output_low(STOP1); |
- |
|
74 |
delay_us(500); |
- |
|
75 |
output_high(STOP1); |
- |
|
76 |
delay_us(10); |
- |
|
77 |
output_low(STOP1); |
- |
|
78 |
delay_us(500); |
- |
|
79 |
output_high(STOP1); |
- |
|
80 |
delay_us(10); |
- |
|
81 |
output_low(STOP1); |
- |
|
82 |
|
- |
|
83 |
delay_ms(100); |
- |
|
84 |
printf("status: %LX \n", TDC_get_status()); |
- |
|
85 |
delay_ms(50); |
34 |
printf("measured: %LX, %LX, %LX, %LX \n", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4)); |
86 |
printf("measured: %LX, %LX, %LX, %LX \n", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4)); |
- |
|
87 |
delay_ms(500); |
- |
|
88 |
|
35 |
}; |
89 |
}; |
36 |
} |
90 |
} |