Rev 1967 Rev 1980
Line 31... Line 31...
31 output_low(STOP1); 31 output_low(STOP1);
32 output_low(STOP2); 32 output_low(STOP2);
33   33  
34 delay_ms(50); 34 delay_ms(50);
35   35  
36 /* -  
37 1 0 0 0 0 ADR2 ADR1 ADR0 Write into address ADR -  
38 1 0 1 1 0 ADR2 ADR1 ADR0 Read from address ADR -  
39 0 1 1 1 0 0 0 0 Init -  
40 0 1 0 1 0 0 0 0 Power On Reset -  
41 0 0 0 0 0 0 0 1 Start_Cycle -  
42 0 0 0 0 0 0 1 0 Start_Temp -  
43 0 0 0 0 0 0 1 1 Start_Cal_Resonator -  
44 0 0 0 0 0 1 0 0 Start_Cal_TDC -  
45 */ -  
46   -  
47 int16 ret16; 36 int16 ret16;
48 int8 ret8; 37 int8 ret8;
49   38  
50 TDC_reset(); 39 TDC_reset();
51 delay_ms(100); 40 delay_ms(100);
52 41
-   42 while(TRUE)
-   43 {
-   44  
-   45  
53 //----------------------------------------------- Nastaveni registru 46 //----------------------------------------------- Nastaveni registru
-   47
-   48 MRange=TDC_MRANGE2; // sets measurement mode
54 hit1=TDC_MRANGE2_HIT1_START; 49 hit1=TDC_MRANGE2_HIT1_START;
55 hitin1=TDC_HITIN1_4; 50 hitin1=TDC_HITIN1_4; // set nomber of hits on channel 1
56 hitin2=TDC_HITIN2_0; 51 hitin2=TDC_HITIN2_0; // disable channel 2 (normal state for this mode)
57 en_int= TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT; 52 en_int= TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT; // eneble all possible interrupt flags
58 en_err_val=TDC_ERRVAL_EN; 53 en_err_val=TDC_ERRVAL_EN; // enable of error value output
59 clkhsdiv=TDC_CLKHSDIV_4; 54 clkhsdiv=TDC_CLKHSDIV_4; // divide clkHS by 4
-   55
60 delval1=0x0; 56 delval1=0x0; // windowing disabled
61 delval2=0x0; 57 delval2=0x0;
62 delval3=0x0; 58 delval3=0x0;
63 59
64 TDC_update_registers(); 60 TDC_update_registers();
65   61  
66 while(TRUE) -  
67 { -  
68 delay_ms(100); 62 delay_ms(100);
69 63  
70 //----------------------------------------------- Mereni 64 //----------------------------------------------- Mereni 2
71 65
72 TDC_init(); 66 TDC_init();
73 67
74 delay_ms(50); 68 delay_ms(50);
75 69
Line 95... Line 89...
95 output_low(STOP1); 89 output_low(STOP1);
96 delay_us(1); 90 delay_us(1);
97 91
98 //----------------------------------------------- Pocitani 92 //----------------------------------------------- Pocitani
99   93  
100 printf("Time: %3.7f %3.7f %3.7f ", TDC_mrange2_get_time(1), TDC_mrange2_get_time(2), TDC_mrange2_get_time(3)); 94 printf("Time2: %3.7f %3.7f %3.7f ", TDC_mrange2_get_time(1), TDC_mrange2_get_time(2), TDC_mrange2_get_time(3));
101 95
102 output_low(TDC_ENABLE); //status register 96 output_low(TDC_ENABLE); //status register
103 ret8=0; 97 ret8=0;
104 ret8=(0b1011<<4)|4; 98 ret8=(0b1011<<4)|4;
105 spi_xfer(TDC_stream,ret8,8); 99 spi_xfer(TDC_stream,ret8,8);
106 ret16=spi_xfer(TDC_stream,0,16); 100 ret16=spi_xfer(TDC_stream,0,16);
107 output_high(TDC_ENABLE); 101 output_high(TDC_ENABLE);
108 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()); 102 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());
109   103  
-   104 //----------------------------------------------- Nastaveni registru
-   105
-   106 MRange=TDC_MRANGE1;
-   107 hit1=TDC_MRANGE1_HIT1_NOAC;
-   108 hit2=TDC_MRANGE1_HIT2_NOAC;
-   109 hitin1=TDC_HITIN1_1;
-   110 hitin2=TDC_HITIN2_1;
-   111 en_int= TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT;
-   112 en_err_val=TDC_ERRVAL_EN;
-   113 clkhsdiv=TDC_CLKHSDIV_4;
-   114 delval1=0x0;
-   115 delval2=0x0;
-   116 delval3=0x0;
-   117
-   118 TDC_update_registers();
-   119  
-   120 delay_ms(100);
-   121  
-   122  
-   123 //----------------------------------------------- Mereni 1
-   124
-   125 TDC_init();
-   126
-   127 delay_ms(50);
-   128 output_low(START);
-   129 output_low(STOP1);
-   130 output_low(STOP2);
-   131
-   132 output_high(START); // start of time measurement
-   133 output_low(START);
-   134  
-   135 output_high(STOP2);
-   136 output_high(STOP1);
-   137  
-   138 output_low(STOP2);
-   139 output_low(STOP1);
-   140
-   141 //----------------------------------------------- Pocitani
-   142  
-   143 printf("Time1: %3.7f %3.7f %3.7f ", TDC_mrange1_get_time(1,0,1,1), TDC_mrange1_get_time(2,0,2,1), TDC_mrange1_get_time(1,1,2,1));
-   144 printf("Time1: %LX %LX %LX %LX ", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4));
-   145
-   146 output_low(TDC_ENABLE); //status register
-   147 ret8=0;
-   148 ret8=(0b1011<<4)|4;
-   149 spi_xfer(TDC_stream,ret8,8);
-   150 ret16=spi_xfer(TDC_stream,0,16);
-   151 output_high(TDC_ENABLE);
-   152 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());
-   153  
-   154  
-   155 /// ----------------------------------------------- Temperature masurement
-   156  
110 TDC_start_temp(); 157 TDC_start_temp();
111 output_low(TDC_ENABLE); //status register 158 output_low(TDC_ENABLE); //status register
112 ret8=0; 159 ret8=0;
113 ret8=(0b1011<<4)|4; 160 ret8=(0b1011<<4)|4;
114 spi_xfer(TDC_stream,ret8,8); 161 spi_xfer(TDC_stream,ret8,8);
115 ret16=spi_xfer(TDC_stream,0,16); 162 ret16=spi_xfer(TDC_stream,0,16);
116 output_high(TDC_ENABLE); 163 output_high(TDC_ENABLE);
117 printf("Temp: [%Lu %Lu %Lu %Lu %Lu %Lu %Lu] ", (1&(ret16)>>12), (1&(ret16)>>11), (1&(ret16)>>10), 1&(ret16)>>9, 7&(ret16)>>6, 7&(ret16)>>3, 7&TDC_get_status()); 164 printf("Temp: [%Lu %Lu %Lu %Lu %Lu %Lu %Lu] ", (1&(ret16)>>12), (1&(ret16)>>11), (1&(ret16)>>10), 1&(ret16)>>9, 7&(ret16)>>6, 7&(ret16)>>3, 7&TDC_get_status());
118 printf(" %LX %LX %LX %LX \r\n", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4)); 165 printf(" %LX %LX %LX %LX \r\n", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4));
119 166
-   167
-   168
120 } 169 }
121 } 170 }