Rev 1774 Rev 1775
1 #include "main.h" 1 #include "main.h"
2   2  
3 #define VERSION 0.1 3 #define VERSION 0.1
4   4  
5 #define START PIN_D4 5 #define START PIN_D4
6 #define STOP1 PIN_D5 6 #define STOP1 PIN_D5
7 #define STOP2 PIN_D6 7 #define STOP2 PIN_D6
8 #include "GP2.h" 8 #include "GP2.h"
9   9  
10 #define ONE_WIRE_PIN PIN_E2 10 #define ONE_WIRE_PIN PIN_E2
11 #include "ds1820.c" 11 #include "ds1820.c"
12   12  
13 void main() 13 void main()
14 { 14 {
15 float temperature; 15 float temperature;
16   16  
17 setup_adc_ports(NO_ANALOGS|VSS_VDD); 17 setup_adc_ports(NO_ANALOGS|VSS_VDD);
18 setup_adc(ADC_CLOCK_DIV_2); 18 setup_adc(ADC_CLOCK_DIV_2);
19 setup_psp(PSP_DISABLED); 19 setup_psp(PSP_DISABLED);
20 setup_spi(SPI_SS_DISABLED); 20 setup_spi(SPI_SS_DISABLED);
21 setup_wdt(WDT_OFF); 21 setup_wdt(WDT_OFF);
22 setup_timer_0(RTCC_INTERNAL); 22 setup_timer_0(RTCC_INTERNAL);
23 setup_timer_1(T1_DISABLED); 23 setup_timer_1(T1_DISABLED);
24 setup_timer_2(T2_DISABLED,0,1); 24 setup_timer_2(T2_DISABLED,0,1);
25 setup_ccp1(CCP_OFF); 25 setup_ccp1(CCP_OFF);
26 setup_comparator(NC_NC_NC_NC); 26 setup_comparator(NC_NC_NC_NC);
27 setup_vref(FALSE); 27 setup_vref(FALSE);
28   28  
29 TDC_reset(); 29 TDC_reset();
30 30
31 hit1=TDC_MRANGE2_HIT1_START; -  
32 hit2=TDC_MRANGE2_HIT2_2CH1; 31 MRange=TDC_MRANGE1;
33 hitin1=TDC_HITIN1_2; 32 hitin1=TDC_HITIN1_2;
34 hitin2=TDC_HITIN1_0; 33 hitin2=TDC_HITIN2_2;
-   34 hit1=TDC_MRANGE1_HIT1_START;
-   35 hit2=TDC_MRANGE1_HIT2_2CH1;
35 en_int= 0xFF; //TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT; 36 en_int= (TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT);
36 en_err_val=TDC_ERRVAL_EN; 37 en_err_val=TDC_ERRVAL_EN;
37 delval1=0x0; 38 delval1=0x0;
38 delval2=0x0; 39 delval2=0x0;
39 delval3=0x0; 40 delval3=0x0;
-   41 calibrate=TDC_CALIBRATE_EN;
-   42 disautocal=TDC_AUTOCAL_EN;
-   43
-   44 firenum=TDC_FIRENUM_2;
-   45 div_fire=TDC_DIV_FIRE_3;
40 46
41 TDC_update_registers(); 47 TDC_update_registers();
42 48
43 output_low(START); 49 output_low(START);
44 output_low(STOP1); 50 output_low(STOP1);
45 output_low(STOP2); 51 output_low(STOP2);
46 52
-   53 TDC_start_cal_resonator();
-   54 delay_ms(50);
-   55 printf("calibrate: %LX, %LX, %LX, %LX \r\n", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4));
47 TDC_start_cal(); 56 TDC_start_cal();
48 delay_ms(50); 57 delay_ms(50);
49 58
50 while(true) 59 while(true)
51 { 60 {
52 temperature = ds1820_read(); 61 temperature = ds1820_read();
53   62  
54 TDC_init(); 63 TDC_init();
55 delay_ms(50); 64 delay_ms(50);
56 printf("Temp: %f \r\n", temperature); 65 printf("Temp: %f \r\n", temperature);
57 delay_ms(50); 66 delay_ms(50);
58 printf("status: %LX \r\n", TDC_get_status()); 67 printf("status: %LX \r\n", TDC_get_status());
59 delay_us(10); -  
-   68  
60 TDC_start_cycle(); 69 TDC_start_cycle();
-   70  
61 delay_us(10); 71 delay_us(10);
62 output_high(START); 72 output_high(START);
63 delay_us(1); 73 // delay_us(1);
64 output_low(START); 74 output_low(START);
65 75
66 delay_us(500); 76 // delay_us(1);
67 77
68 output_high(STOP1); 78 output_high(STOP1);
69 delay_us(10); 79 // delay_us(10);
70 output_low(STOP1); 80 output_low(STOP1);
71 delay_us(500); 81 // delay_us(500);
-   82 // output_high(STOP1);
-   83 // delay_us(10);
-   84 // output_low(STOP1);
-   85 // delay_us(500);
-   86 // output_high(STOP1);
-   87 // delay_us(10);
-   88 // output_low(STOP1);
-   89  
72 output_high(STOP1); 90 output_high(STOP2);
-   91 // delay_us(10);
-   92 output_low(STOP2);
-   93 // delay_us(500);
-   94 output_high(STOP2);
73 delay_us(10); 95 // delay_us(10);
74 output_low(STOP1); 96 output_low(STOP2);
75 delay_us(500); 97 // delay_us(500);
76 output_high(STOP1); 98 output_high(STOP2);
77 delay_us(10); 99 // delay_us(10);
78 output_low(STOP1); 100 output_low(STOP2);
-   101  
-   102 output_low(START);
79   103  
80 delay_ms(100); 104 delay_ms(10);
81 printf("status: %LX \r\n", TDC_get_status()); 105 printf("status: %LX \r\n", TDC_get_status());
82 delay_ms(50); 106 delay_ms(50);
83 printf("measured: %LX, %LX, %LX, %LX \r\n", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4)); 107 printf("measured: %LX, %LX, %LX, %LX \r\n", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4));
84 delay_ms(500); 108 delay_ms(500);
85 109
86 }; 110 };
87 } 111 }