1744 |
kakl |
1 |
#include "main.h" |
|
|
2 |
|
|
|
3 |
#include "GP2.h" |
|
|
4 |
|
1757 |
kakl |
5 |
#define VERSION 0.1 |
|
|
6 |
|
1759 |
kakl |
7 |
#define START PIN_D4 |
|
|
8 |
#define STOP1 PIN_D5 |
|
|
9 |
#define STOP2 PIN_D6 |
|
|
10 |
|
1744 |
kakl |
11 |
void main() |
|
|
12 |
{ |
|
|
13 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
|
|
14 |
setup_adc(ADC_CLOCK_DIV_2); |
|
|
15 |
setup_psp(PSP_DISABLED); |
|
|
16 |
setup_spi(SPI_SS_DISABLED); |
|
|
17 |
setup_wdt(WDT_OFF); |
|
|
18 |
setup_timer_0(RTCC_INTERNAL); |
|
|
19 |
setup_timer_1(T1_DISABLED); |
|
|
20 |
setup_timer_2(T2_DISABLED,0,1); |
|
|
21 |
setup_ccp1(CCP_OFF); |
|
|
22 |
setup_comparator(NC_NC_NC_NC); |
|
|
23 |
setup_vref(FALSE); |
|
|
24 |
|
1745 |
kakl |
25 |
TDC_reset(); |
1744 |
kakl |
26 |
|
1758 |
kakl |
27 |
hit1=TDC_MRANGE2_HIT1_START; |
1759 |
kakl |
28 |
hit2=TDC_MRANGE2_HIT2_2CH1; |
1758 |
kakl |
29 |
hitin1=TDC_HITIN1_2; |
|
|
30 |
hitin2=TDC_HITIN1_0; |
1759 |
kakl |
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; |
1758 |
kakl |
36 |
|
|
|
37 |
TDC_update_registers(); |
|
|
38 |
|
1759 |
kakl |
39 |
output_low(START); |
|
|
40 |
output_low(STOP1); |
|
|
41 |
output_low(STOP2); |
|
|
42 |
|
|
|
43 |
TDC_start_cal(); |
|
|
44 |
delay_ms(50); |
|
|
45 |
|
1744 |
kakl |
46 |
while(true) |
|
|
47 |
{ |
1759 |
kakl |
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 |
*/ |
1758 |
kakl |
59 |
TDC_init(); |
1759 |
kakl |
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 |
|
|
|
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); |
|
|
86 |
printf("measured: %LX, %LX, %LX, %LX \n", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4)); |
1744 |
kakl |
87 |
delay_ms(500); |
1759 |
kakl |
88 |
|
1744 |
kakl |
89 |
}; |
|
|
90 |
} |