- Timestamp:
- Jan 11, 2012, 4:32:57 PM (13 years ago)
- Location:
- trunk/MultiChannelUSB
- Files:
-
- 8 added
- 7 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MultiChannelUSB/Paella.dpf
r41 r159 3 3 <pin_planner> 4 4 <pin_info> 5 <pin name="ADC_D[2]" direction="Input" source="Hierarchy Database" diff_pair_node="ADC_D[2](n)" > 6 </pin> 7 <pin name="ADC_D[1]" direction="Input" source="Hierarchy Database" diff_pair_node="ADC_D[1](n)" > 8 </pin> 9 <pin name="ADC_D[0]" direction="Input" source="Hierarchy Database" diff_pair_node="ADC_D[0](n)" > 10 </pin> 5 11 <pin name="ADC_DCO" direction="Input" source="Hierarchy Database" diff_pair_node="ADC_DCO(n)" > 12 </pin> 13 <pin name="ADC_FCO" direction="Input" source="Hierarchy Database" diff_pair_node="ADC_FCO(n)" > 6 14 </pin> 7 15 <pin name="ADC_DCO(n)" direction="Input" source="Assignments" diff_pair_node="ADC_DCO" > 8 16 </pin> 9 <pin name="ADC_FCO" direction="Input" source="Hierarchy Database" diff_pair_node="ADC_FCO(n)" >10 </pin>11 17 <pin name="ADC_FCO(n)" direction="Input" source="Assignments" diff_pair_node="ADC_FCO" > 12 </pin>13 <pin name="ADC_D[0]" direction="Input" source="Hierarchy Database" diff_pair_node="ADC_D[0](n)" >14 18 </pin> 15 19 <pin name="ADC_D[0](n)" direction="Input" source="Assignments" diff_pair_node="ADC_D[0]" > 16 20 </pin> 17 <pin name="ADC_D[1]" direction="Input" source="Hierarchy Database" diff_pair_node="ADC_D[1](n)" >18 </pin>19 21 <pin name="ADC_D[1](n)" direction="Input" source="Assignments" diff_pair_node="ADC_D[1]" > 20 </pin>21 <pin name="ADC_D[2]" direction="Input" source="Hierarchy Database" diff_pair_node="ADC_D[2](n)" >22 22 </pin> 23 23 <pin name="ADC_D[2](n)" direction="Input" source="Assignments" diff_pair_node="ADC_D[2]" > -
trunk/MultiChannelUSB/Paella.qsf
r101 r159 42 42 set_global_assignment -name ORIGINAL_QUARTUS_VERSION 9.0 43 43 set_global_assignment -name PROJECT_CREATION_TIME_DATE "14:14:14 AUGUST 28, 2009" 44 set_global_assignment -name LAST_QUARTUS_VERSION 9.044 set_global_assignment -name LAST_QUARTUS_VERSION "9.1 SP2" 45 45 set_global_assignment -name DEVICE_FILTER_PACKAGE "ANY QFP" 46 46 set_global_assignment -name DEVICE_FILTER_PIN_COUNT 240 … … 49 49 set_global_assignment -name AUTO_SHIFT_REGISTER_RECOGNITION OFF 50 50 set_global_assignment -name MISC_FILE Paella.dpf 51 set_global_assignment -name VERILOG_FILE Paella.v52 set_global_assignment -name VERILOG_FILE adc_fifo.v53 set_global_assignment -name VERILOG_FILE adc_lvds.v54 set_global_assignment -name VERILOG_FILE adc_para.v55 set_global_assignment -name VERILOG_FILE adc_pll.v56 set_global_assignment -name VERILOG_FILE control.v57 set_global_assignment -name VERILOG_FILE analyser.v58 set_global_assignment -name VERILOG_FILE counter.v59 set_global_assignment -name VERILOG_FILE histogram.v60 set_global_assignment -name VERILOG_FILE trigger.v61 set_global_assignment -name VERILOG_FILE oscilloscope.v62 set_global_assignment -name VERILOG_FILE configuration.v63 set_global_assignment -name VERILOG_FILE usb_fifo.v64 set_global_assignment -name VERILOG_FILE i2c_fifo.v65 set_global_assignment -name VERILOG_FILE uwt_bior31.v66 set_global_assignment -name VERILOG_FILE test.v67 set_global_assignment -name VERILOG_FILE test_pll.v68 set_global_assignment -name VERILOG_FILE sys_pll.v69 51 set_global_assignment -name USE_TIMEQUEST_TIMING_ANALYZER OFF 70 52 set_global_assignment -name ENABLE_CLOCK_LATENCY ON 71 set_instance_assignment -name PARTITION_HIERARCHY root_partition -to | -section_id Top72 53 set_global_assignment -name PARTITION_NETLIST_TYPE SOURCE -section_id Top 73 54 set_global_assignment -name PARTITION_COLOR 16764057 -section_id Top … … 92 73 set_global_assignment -name IOBANK_VCCIO 3.3V -section_id 8 93 74 set_location_assignment PIN_21 -to LED 94 set_location_assignment PIN_33 -to CLK_50MHz95 75 set_location_assignment PIN_37 -to USB_PA7 96 76 set_location_assignment PIN_38 -to USB_PA6 … … 157 137 set_location_assignment PIN_146 -to CON_B[14] 158 138 set_location_assignment PIN_147 -to CON_B[15] 159 set_location_assignment PIN_149 -to CON_BCLK[0] 160 set_location_assignment PIN_150 -to CON_BCLK[1] 139 set_location_assignment PIN_148 -to CON_B[16] 140 set_location_assignment PIN_149 -to CON_BCLK 141 set_location_assignment PIN_150 -to CLK_50MHz 161 142 set_location_assignment PIN_151 -to CON_CCLK[0] 162 143 set_location_assignment PIN_152 -to CON_CCLK[1] … … 266 247 set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to CON_B[14] 267 248 set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to CON_B[15] 268 set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to CON_BCLK[0] 269 set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to CON_BCLK[1] 249 set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to CON_BCLK 270 250 set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to CON_C[0] 271 251 set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to CON_C[1] … … 324 304 set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_DQB[6] 325 305 set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to RAM_DQB[7] 306 307 set_global_assignment -name VERILOG_FILE clip.v 308 set_global_assignment -name VERILOG_FILE shift.v 309 set_global_assignment -name VERILOG_FILE Paella.v 310 set_global_assignment -name VERILOG_FILE adc_lvds.v 311 set_global_assignment -name VERILOG_FILE sys_pll.v 312 set_global_assignment -name VERILOG_FILE control.v 313 set_global_assignment -name VERILOG_FILE filter.v 314 set_global_assignment -name VERILOG_FILE amplitude.v 315 set_global_assignment -name VERILOG_FILE delay.v 316 set_global_assignment -name VERILOG_FILE coincidence.v 317 set_global_assignment -name VERILOG_FILE counter.v 318 set_global_assignment -name VERILOG_FILE histogram16.v 319 set_global_assignment -name VERILOG_FILE histogram32.v 320 set_global_assignment -name VERILOG_FILE trigger.v 321 set_global_assignment -name VERILOG_FILE oscilloscope.v 322 set_global_assignment -name VERILOG_FILE configuration.v 323 set_global_assignment -name VERILOG_FILE usb_fifo.v 324 set_global_assignment -name VERILOG_FILE i2c_fifo.v 325 set_global_assignment -name VERILOG_FILE test.v 326 327 set_instance_assignment -name PARTITION_HIERARCHY root_partition -to | -section_id Top -
trunk/MultiChannelUSB/Paella.v
r101 r159 8 8 inout wire I2C_SCL, 9 9 inout wire [4:0] CON_A, 10 input wire [1 5:0] CON_B,10 input wire [16:0] CON_B, 11 11 input wire [12:0] CON_C, 12 input wire [1:0]CON_BCLK,12 input wire CON_BCLK, 13 13 input wire [1:0] CON_CCLK, 14 14 … … 68 68 69 69 assign USB_PA2 = ~usb_rden; 70 assign USB_PA4 = usb_addr[0]; 71 assign USB_PA5 = usb_addr[1]; 70 assign USB_PA5 = 1'b1; 72 71 assign USB_PA6 = ~usb_pktend; 73 72 … … 76 75 wire usb_tx_full, usb_rx_empty; 77 76 wire [7:0] usb_tx_data, usb_rx_data; 78 wire [1:0] usb_addr;79 77 80 78 assign USB_SLRD = ~usb_rdreq; … … 83 81 usb_fifo usb_unit 84 82 ( 85 .usb_cl k(USB_IFCLK),83 .usb_clock(USB_IFCLK), 86 84 .usb_data(USB_PB), 87 85 .usb_full(~USB_FLAGB), … … 91 89 .usb_rden(usb_rden), 92 90 .usb_pktend(usb_pktend), 93 .usb_addr( usb_addr),94 95 .cl k(sys_clock),91 .usb_addr(USB_PA4), 92 93 .clock(sys_clock), 96 94 97 95 .tx_full(usb_tx_full), … … 103 101 .rx_q(usb_rx_data) 104 102 ); 105 106 wire ana_dead [N-1:0];107 wire ana_good [N-1:0];108 wire [11:0] ana_data [N-1:0];109 wire [11:0] ana_base [N-1:0];110 111 wire cnt_good [N-1:0];112 113 wire [11:0] osc_mux_data [ N-1:0];103 /* 104 reg [31:0] led_counter; 105 always @(posedge CLK_50MHz) 106 begin 107 led_counter = led_counter + 32'd1; 108 end 109 assign LED = led_counter[28]; 110 */ 111 wire [11:0] osc_mux_data [4:0]; 114 112 115 113 wire [11:0] trg_mux_data; 116 114 wire trg_flag; 117 115 118 wire [83:0] int_mux_data [N-1:0]; 116 wire [4*12-1:0] int_mux_data [N-1:0]; 117 118 wire [1:0] amp_flag [2*N-1:0]; 119 wire [11:0] amp_data [2*N-1:0]; 120 121 wire cnt_good [N-1:0]; 122 wire [15:0] cnt_bits_wire; 119 123 120 124 wire sys_clock, sys_frame; 121 125 122 wire [11:0] adc_data [N-1:0]; 123 wire [11:0] int_data [N-1:0]; 126 wire [11:0] adc_data [N-1:0]; 124 127 wire [11:0] sys_data [N-1:0]; 125 wire [11:0] cmp_data; 126 wire [11:0] nowhere; 127 128 wire [31:0] uwt_d1 [N-1:0]; 129 wire [31:0] uwt_a1 [N-1:0]; 130 wire [31:0] uwt_peak1 [N-1:0]; 131 wire [31:0] uwt_d2 [N-1:0]; 132 wire [31:0] uwt_a2 [N-1:0]; 133 wire [31:0] uwt_peak2 [N-1:0]; 134 wire [31:0] uwt_d3 [N-1:0]; 135 wire [31:0] uwt_a3 [N-1:0]; 136 wire [31:0] uwt_peak3 [N-1:0]; 137 138 wire [1:0] uwt_flag1 [N-1:0]; 139 wire [1:0] uwt_flag2 [N-1:0]; 140 wire [1:0] uwt_flag3 [N-1:0]; 141 128 wire [11:0] tst_data; 129 130 wire [1:0] cmp_data; 131 wire [1:0] del_data; 132 133 wire [19:0] cic_data [N-1:0]; 134 135 wire [11:0] dec_data [N-1:0]; 136 wire [11:0] clp_data [N-1:0]; 137 wire [11:0] tmp_data; 138 139 142 140 wire i2c_reset; 143 144 /*145 adc_para adc_para_unit (146 .lvds_dco(ADC_DCO),147 .lvds_fco(ADC_FCO),148 .para_good(CON_CCLK[0]),149 .para_data(CON_C[11:0]),150 .adc_data(adc_data[2]));151 */152 153 wire adc_pll_clk;154 155 /*156 adc_pll adc_pll_unit(157 .inclk0(ADC_FCO),158 .c0(adc_pll_clk));159 */160 141 161 142 sys_pll sys_pll_unit( … … 165 146 test test_unit( 166 147 .clk(ADC_FCO), 167 .data(adc_data[2])); 168 // .data(nowhere)); 148 .data(tst_data)); 169 149 170 150 adc_lvds #( 171 151 .size(3), 172 152 .width(12)) adc_lvds_unit ( 153 .clock(sys_clock), 173 154 .lvds_dco(ADC_DCO), 174 // .lvds_dco(adc_pll_clk),175 155 .lvds_fco(ADC_FCO), 176 .lvds_d(ADC_D[2:0]), 177 // .adc_data({ adc_data[2], 178 .adc_data({ nowhere, 179 adc_data[1], 180 adc_data[0] })); 181 182 /* 183 assign cmp_data = CON_B[11:0]; 184 assign sys_clock = ADC_DCO; 185 assign sys_frame = ADC_FCO; 186 */ 187 188 wire [15:0] cfg_bits [31:0]; 189 wire [511:0] int_cfg_bits; 190 191 wire [31:0] cfg_mux_selector; 156 .lvds_d(ADC_D), 157 .trig(TRG[1:0]), 158 .adc_frame(sys_frame), 159 .adc_data({cmp_data, adc_data[2], adc_data[1], adc_data[0]})); 160 161 wire [15:0] cfg_bits [63:0]; 162 wire [1023:0] int_cfg_bits; 163 164 wire [39:0] cfg_mux_selector; 192 165 193 166 wire cfg_reset; 194 167 195 wire [ 8:0] bus_ssel;168 wire [11:0] bus_ssel; 196 169 wire bus_wren; 197 170 wire [31:0] bus_addr; 198 171 wire [15:0] bus_mosi; 199 wire [15:0] bus_miso [ 7:0];200 wire [ 8:0] bus_busy;172 wire [15:0] bus_miso [10:0]; 173 wire [11:0] bus_busy; 201 174 202 175 wire [15:0] mrg_bus_miso; 203 176 wire mrg_bus_busy; 204 177 205 wire [1 27:0] int_bus_miso;178 wire [11*16-1:0] int_bus_miso; 206 179 207 180 genvar j; 208 181 209 182 generate 210 for (j = 0; j < 32; j = j + 1)183 for (j = 0; j < 64; j = j + 1) 211 184 begin : CONFIGURATION_OUTPUT 212 185 assign cfg_bits[j] = int_cfg_bits[j*16+15:j*16]; … … 229 202 begin : MUX_DATA 230 203 assign int_mux_data[j] = { 231 {ana_good[j], 11'd0}, 232 ana_data[j], 233 ana_base[j], 234 uwt_a3[j][20:9], 235 uwt_a2[j][17:6], 236 uwt_a1[j][14:3], 204 {4'd0, amp_flag[0+2*j][0], 7'd0}, 205 amp_data[0+2*j], 206 clp_data[j], 237 207 sys_data[j]}; 238 208 end 239 209 endgenerate 240 210 241 assign cfg_mux_selector = {cfg_bits[ 3], cfg_bits[2]};211 assign cfg_mux_selector = {cfg_bits[4][7:0], cfg_bits[3], cfg_bits[2]}; 242 212 243 213 lpm_mux #( 244 .lpm_size( 21),214 .lpm_size(4*3), 245 215 .lpm_type("LPM_MUX"), 246 216 .lpm_width(12), 247 .lpm_widths( 5)) trg_mux_unit (248 .sel(cfg_ mux_selector[28:24]),217 .lpm_widths(4)) trg_mux_unit ( 218 .sel(cfg_bits[4][11:8]), 249 219 .data({int_mux_data[2], int_mux_data[1], int_mux_data[0]}), 250 220 .result(trg_mux_data)); 251 221 252 222 generate 253 for (j = 0; j < 3; j = j + 1)223 for (j = 0; j < 5; j = j + 1) 254 224 begin : OSC_CHAIN 255 225 256 226 lpm_mux #( 257 .lpm_size( 21),227 .lpm_size(4*3), 258 228 .lpm_type("LPM_MUX"), 259 229 .lpm_width(12), 260 .lpm_widths( 5)) osc_mux_unit (261 .sel(cfg_mux_selector[j*8+ 4:j*8]),230 .lpm_widths(4)) osc_mux_unit ( 231 .sel(cfg_mux_selector[j*8+3:j*8]), 262 232 .data({int_mux_data[2], int_mux_data[1], int_mux_data[0]}), 263 233 .result(osc_mux_data[j])); … … 278 248 .frame(sys_frame), 279 249 .reset(cfg_bits[0][1]), 280 .cfg_data(cfg_bits[ 4][0]),250 .cfg_data(cfg_bits[5][12]), 281 251 .trg_flag(trg_flag), 282 .osc_data({ cmp_data, osc_mux_data[2], osc_mux_data[1], osc_mux_data[0]}),252 .osc_data({2'd0, cmp_data, osc_mux_data[4], osc_mux_data[3], osc_mux_data[2], osc_mux_data[1], osc_mux_data[0]}), 283 253 .ram_wren(RAM_WE), 284 254 .ram_addr(RAM_ADDR), … … 291 261 .bus_busy(bus_busy[1])); 292 262 293 294 adc_fifo #(.W(48)) adc_fifo_unit ( 295 .adc_clock(ADC_FCO), 296 .adc_data({CON_B[11:0], adc_data[2], adc_data[1], adc_data[0]}), 297 .sys_clock(sys_clock), 298 .sys_frame(sys_frame), 299 .sys_data({cmp_data, int_data[2], int_data[1], int_data[0]})); 300 301 263 filter #(.size(3), .width(12)) filter_unit ( 264 .clock(sys_clock), 265 .frame(sys_frame), 266 .reset(1'b0), 267 .inp_data({sys_data[2], sys_data[1], sys_data[0]}), 268 .out_data({cic_data[2], cic_data[1], cic_data[0]})); 269 270 271 /* 272 clip #(.shift(19), .width(19), .widthr(12)) clip_unit ( 273 .clock(sys_clock), 274 .frame(sys_frame), 275 .reset(1'b0), 276 .del_data({cfg_bits[39][5:0], cfg_bits[37][5:0], cfg_bits[35+8][5:0], cfg_bits[33][5:0]}), 277 .amp_data({6'd6, 6'd6, 6'd6, 6'd6}), 278 .tau_data({cfg_bits[38], cfg_bits[36], cfg_bits[34], cfg_bits[32]}), 279 .inp_data({ 280 19'd0, cic_data[2][18:0], 281 cic_data[1][18:0], cic_data[0][18:0]}), 282 .out_data({ 283 tmp_data, clp_data[2], 284 clp_data[1], clp_data[0]})); 285 */ 302 286 generate 303 287 for (j = 0; j < 3; j = j + 1) 304 288 begin : MCA_CHAIN 305 306 assign sys_data[j] = (cfg_bits[1][4*j]) ? (int_data[j] ^ 12'hfff) : (int_data[j]); 307 308 uwt_bior31 #(.L(1)) uwt_1_unit ( 289 290 shift #(.shift(9), .width(19), .widthr(12)) shift_unit ( 309 291 .clock(sys_clock), 310 292 .frame(sys_frame), 311 293 .reset(1'b0), 312 . x({20'h00000, sys_data[j]}),313 . d(uwt_d1[j]),314 . a(uwt_a1[j]),315 .peak(uwt_peak1[j]),316 .flag(uwt_flag1[j]));317 318 uwt_bior31 #(.L(2)) uwt_2_unit(294 .amp_data(6'd5), 295 .inp_data(cic_data[j][18:0]), 296 .out_data(clp_data[j])); 297 298 assign sys_data[j] = (cfg_bits[1][4*j]) ? (adc_data[j] ^ 12'hfff) : (adc_data[j]); 299 300 amplitude #(.width(12)) amplitude_unit_1 ( 319 301 .clock(sys_clock), 320 302 .frame(sys_frame), 321 303 .reset(1'b0), 322 .x(uwt_a1[j]), 323 .d(uwt_d2[j]), 324 .a(uwt_a2[j]), 325 .peak(uwt_peak2[j]), 326 .flag(uwt_flag2[j])); 327 328 uwt_bior31 #(.L(3)) uwt_3_unit ( 304 .cfg_data(cfg_bits[6+2*j][11:0]), 305 .inp_data(clp_data[j]), 306 .out_flag(amp_flag[0+2*j]), 307 .out_data(amp_data[0+2*j])); 308 309 amplitude #(.width(12)) amplitude_unit_2 ( 329 310 .clock(sys_clock), 330 311 .frame(sys_frame), 331 312 .reset(1'b0), 332 .x(uwt_a2[j]), 333 .d(uwt_d3[j]), 334 .a(uwt_a3[j]), 335 .peak(uwt_peak3[j]), 336 .flag(uwt_flag3[j])); 337 338 analyser analyser_unit ( 339 .clock(sys_clock), 340 .frame(sys_frame), 341 .reset(cfg_bits[0][2+j]), 342 .cfg_data({cfg_bits[7+2*j][12:0], cfg_bits[6+2*j][11:0]}), 343 .uwt_flag(uwt_flag3[j]), 344 .uwt_data(uwt_peak3[j]), 345 .ana_dead(ana_dead[j]), 346 .ana_good(ana_good[j]), 347 .ana_data(ana_data[j]), 348 .ana_base(ana_base[j])); 349 350 histogram histogram_unit ( 351 .clock(sys_clock), 352 .frame(sys_frame), 353 .reset(cfg_bits[0][5+j]), 354 .hst_good((ana_good[j]) & (cnt_good[j])), 355 .hst_data(ana_data[j]), 356 .bus_ssel(bus_ssel[2+j]), 357 .bus_wren(bus_wren), 358 .bus_addr(bus_addr[12:0]), 359 .bus_mosi(bus_mosi), 360 .bus_miso(bus_miso[2+j]), 361 .bus_busy(bus_busy[2+j])); 362 363 counter counter_unit ( 364 .clock(sys_clock), 365 .frame((sys_frame) & (~ana_dead[j])), 366 .reset(cfg_bits[0][8+j]), 367 .cfg_data(cfg_bits[12+j]), 368 .bus_ssel(bus_ssel[5+j]), 369 .bus_wren(bus_wren), 370 .bus_addr(bus_addr[1:0]), 371 .bus_mosi(bus_mosi), 372 .bus_miso(bus_miso[5+j]), 373 .bus_busy(bus_busy[5+j]), 374 .cnt_good(cnt_good[j])); 313 .cfg_data(cfg_bits[7+2*j][11:0]), 314 .inp_data(clp_data[j]), 315 .out_flag(amp_flag[1+2*j]), 316 .out_data(amp_data[1+2*j])); 375 317 376 318 end 377 319 endgenerate 320 321 histogram32 histogram32_unit ( 322 .clock(sys_clock), 323 .frame(sys_frame), 324 .reset(cfg_bits[0][5]), 325 .hst_good((amp_flag[0][0]) & (cnt_good[0]) & (cfg_bits[13][1])), 326 .hst_data(amp_data[0]), 327 /* 328 .hst_good((amp_flag[j]) & (cnt_good[j]) & (cfg_bits[13][1])), 329 .hst_data(amp_data[j]), 330 */ 331 .bus_ssel(bus_ssel[2]), 332 .bus_wren(bus_wren), 333 .bus_addr(bus_addr[12:0]), 334 .bus_mosi(bus_mosi), 335 .bus_miso(bus_miso[2]), 336 .bus_busy(bus_busy[2])); 337 338 counter hst_counter_unit ( 339 .clock(sys_clock), 340 .frame((sys_frame) & (~amp_flag[0][1])), 341 // .frame(sys_frame), 342 .reset(cfg_bits[0][8]), 343 .setup(cfg_bits[13][0]), 344 .count(cfg_bits[13][1]), 345 .bus_ssel(bus_ssel[5]), 346 .bus_wren(bus_wren), 347 .bus_addr(bus_addr[1:0]), 348 .bus_mosi(bus_mosi), 349 .bus_miso(bus_miso[5]), 350 .bus_busy(bus_busy[5]), 351 .cnt_good(cnt_good[0])); 352 353 histogram16 histogram16_unit ( 354 .clock(sys_clock), 355 .frame(sys_frame), 356 .reset(cfg_bits[0][11]), 357 .hst_good((cnt_good[2]) & (~cnt_good[1])), 358 .hst_data(cnt_bits_wire), 359 .bus_ssel(bus_ssel[8]), 360 .bus_wren(bus_wren), 361 .bus_addr(bus_addr[13:0]), 362 .bus_mosi(bus_mosi), 363 .bus_miso(bus_miso[8]), 364 .bus_busy(bus_busy[8])); 365 366 counter rmt_counter_1 ( 367 .clock(sys_clock), 368 .frame((sys_frame) & (~amp_flag[1][1])), 369 // .frame(sys_frame), 370 .reset(cfg_bits[0][12]), 371 .setup((sys_frame) & (~cnt_good[1])), 372 .count((cnt_good[2]) & (cfg_bits[16][1])), 373 .bus_ssel(bus_ssel[9]), 374 .bus_wren(bus_wren), 375 .bus_addr(bus_addr[1:0]), 376 .bus_mosi(bus_mosi), 377 .bus_miso(bus_miso[9]), 378 .bus_busy(bus_busy[9]), 379 .cnt_good(cnt_good[1])); 380 381 counter rmt_counter_2 ( 382 .clock(sys_clock), 383 .frame((sys_frame) & (~cnt_good[1])), 384 .reset(cfg_bits[0][13]), 385 .setup(cfg_bits[16][0]), 386 .count(cfg_bits[16][1]), 387 .bus_ssel(bus_ssel[10]), 388 .bus_wren(bus_wren), 389 .bus_addr(bus_addr[1:0]), 390 .bus_mosi(bus_mosi), 391 .bus_miso(bus_miso[10]), 392 .bus_busy(bus_busy[10]), 393 .cnt_good(cnt_good[2])); 394 395 lpm_counter #( 396 .lpm_direction("UP"), 397 .lpm_port_updown("PORT_UNUSED"), 398 .lpm_type("LPM_COUNTER"), 399 .lpm_width(16)) lpm_counter_component ( 400 .sclr(((sys_frame) & (cnt_good[2]) & (~cnt_good[1])) | (cfg_bits[0][11])), 401 .clock(sys_clock), 402 .cnt_en((sys_frame) & (amp_flag[1][0]) & (cnt_good[1]) & (cnt_good[2]) & (cfg_bits[16][1])), 403 .q(cnt_bits_wire)); 378 404 379 405 i2c_fifo i2c_unit( … … 390 416 .i2c_scl(I2C_SDA), 391 417 392 .bus_ssel(bus_ssel[ 8]),393 .bus_wren(bus_wren), 394 .bus_mosi(bus_mosi), 395 .bus_busy(bus_busy[ 8]));418 .bus_ssel(bus_ssel[11]), 419 .bus_wren(bus_wren), 420 .bus_mosi(bus_mosi), 421 .bus_busy(bus_busy[11])); 396 422 397 423 generate 398 for (j = 0; j < 8; j = j + 1)424 for (j = 0; j < 11; j = j + 1) 399 425 begin : BUS_OUTPUT 400 426 assign int_bus_miso[j*16+15:j*16] = bus_miso[j]; … … 403 429 404 430 lpm_mux #( 405 .lpm_size( 8),431 .lpm_size(11), 406 432 .lpm_type("LPM_MUX"), 407 433 .lpm_width(16), 408 .lpm_widths( 3)) bus_miso_mux_unit (409 .sel(bus_addr[3 0:28]),434 .lpm_widths(4)) bus_miso_mux_unit ( 435 .sel(bus_addr[31:28]), 410 436 .data(int_bus_miso), 411 437 .result(mrg_bus_miso)); 412 438 413 439 lpm_mux #( 414 .lpm_size( 9),440 .lpm_size(12), 415 441 .lpm_type("LPM_MUX"), 416 442 .lpm_width(1), … … 420 446 .result(mrg_bus_busy)); 421 447 422 /*423 lpm_or #(424 .lpm_size(6),425 .lpm_type("LPM_OR"),426 .lpm_width(16)) bus_miso_or_unit (427 .data(int_bus_miso),428 .result(mrg_bus_miso));429 */430 431 448 lpm_decode #( 432 .lpm_decodes( 9),449 .lpm_decodes(12), 433 450 .lpm_type("LPM_DECODE"), 434 451 .lpm_width(4)) lpm_decode_unit ( 435 452 .data(bus_addr[31:28]), 436 .eq(bus_ssel), 437 .aclr(), 438 .clken(), 439 .clock(), 440 .enable()); 453 .eq(bus_ssel)); 454 441 455 442 456 control control_unit ( -
trunk/MultiChannelUSB/UserInterface.tcl
r85 r159 16 16 namespace import ::blt::tabnotebook 17 17 18 proc validate {max value} { 18 # ------------------------------------------------------------------------- 19 20 variable oscCodes 21 array set oscCodes { 22 1 {Channel 1} 23 2 {Channel 2} 24 3 {Channel 3} 25 4 {Channel 4} 26 5 {Channel 5} 27 6 {Trigger} 28 } 29 30 # ------------------------------------------------------------------------- 31 32 variable adcCodes 33 array set adcCodes { 34 1 {ADC 1} 35 2 {ADC 2} 36 3 {ADC 3} 37 } 38 39 # ------------------------------------------------------------------------- 40 41 variable inpCodes 42 array set inpCodes { 43 0 {raw data} 44 1 {filtered} 45 2 {amplitude} 46 3 {amp flag} 47 } 48 49 # ------------------------------------------------------------------------- 50 51 proc validate {max size value} { 19 52 if {![regexp {^[0-9]*$} $value]} { 53 return 0 54 } elseif {[regexp {^0[0-9]+$} $value]} { 20 55 return 0 21 56 } elseif {$value > $max} { 22 57 return 0 23 } elseif {[string length $value] > 4} {58 } elseif {[string length $value] > $size} { 24 59 return 0 25 60 } else { … … 30 65 # ------------------------------------------------------------------------- 31 66 32 Class Display 33 34 # ------------------------------------------------------------------------- 35 36 Display instproc usbCmd {command} { 37 global usb_handle 38 39 if {[catch {$usb_handle writeRaw [usb::convert $command]} result]} { 40 puts {Error during write} 41 puts $result 42 } 43 } 44 45 # ------------------------------------------------------------------------- 46 47 Display instproc usbCmdRead {command width size} { 48 global usb_handle 49 67 proc doublevalidate {max value} { 68 if {![regexp {^[0-9]{0,2}\.?[0-9]{0,3}$} $value]} { 69 return 0 70 } elseif {[regexp {^0[0-9]+$} $value]} { 71 return 0 72 } elseif {$value > $max} { 73 return 0 74 } else { 75 return 1 76 } 77 } 78 79 # ------------------------------------------------------------------------- 80 81 proc legendLabel {master row key title} { 82 label ${master}.${key}_label -anchor w -text ${title} 83 label ${master}.${key}_value -width 10 -anchor e -text {} 84 85 grid ${master}.${key}_label -row ${row} -column 1 -sticky w 86 grid ${master}.${key}_value -row ${row} -column 2 -sticky ew 87 } 88 89 # ------------------------------------------------------------------------- 90 91 proc legendButton {master row key title var bg {fg black}} { 92 checkbutton ${master}.${key}_check -variable $var 93 label ${master}.${key}_label -anchor w -text ${title} -bg ${bg} -fg $fg 94 label ${master}.${key}_value -width 10 -anchor e -text {} -bg ${bg} -fg $fg 95 96 grid ${master}.${key}_check -row ${row} -column 0 -sticky w 97 grid ${master}.${key}_label -row ${row} -column 1 -sticky w 98 grid ${master}.${key}_value -row ${row} -column 2 -sticky ew 99 } 100 101 # ------------------------------------------------------------------------- 102 103 Class UsbController 104 105 # ------------------------------------------------------------------------- 106 107 UsbController instproc usbConnect {} { 108 my instvar handle 109 110 puts usbConnect 111 112 if {[my exists handle]} { 113 $handle disconnect 114 unset handle 115 } 116 if {1} { 117 while {[catch {usb::connect 0x09FB 0x6001 1 1 0} result]} { 118 set answer [tk_messageBox -icon error -type retrycancel \ 119 -message {Cannot access USB device} -detail $result] 120 # puts $result 121 if {[string equal $answer cancel]} exit 122 } 123 124 set handle $result 125 126 } 127 } 128 129 # ------------------------------------------------------------------------- 130 131 UsbController instproc usbHandle {} { 132 my instvar handle 133 134 if {[my exists handle]} { 135 return $handle 136 } else { 137 my usbConnect 138 } 139 } 140 141 # ------------------------------------------------------------------------- 142 143 UsbController instproc usbCmd {command} { 144 set code [catch {[my usbHandle] writeRaw [usb::convert $command]} result] 145 switch -- $code { 146 1 { 147 # puts $result 148 my usbConnect 149 } 150 } 151 152 } 153 154 # ------------------------------------------------------------------------- 155 156 UsbController instproc usbCmdReadRaw {command size data} { 50 157 my usbCmd $command 51 158 52 set usb_data {} 53 if {[catch {$usb_handle readHex $width $size} result]} { 54 puts {Error during read} 55 puts $result 56 set result {} 57 } 58 59 my set data $result 60 } 61 62 # ------------------------------------------------------------------------- 63 64 Display instproc usbCmdReadEpt {command size} { 65 global usb_handle 66 159 set code [catch {[my usbHandle] readRaw $size} result] 160 switch -- $code { 161 0 { 162 set $data $result 163 } 164 1 { 165 # puts $result 166 my usbConnect 167 } 168 5 { 169 # puts Busy 170 } 171 } 172 } 173 174 # ------------------------------------------------------------------------- 175 176 UsbController instproc usbCmdReadRaw {command size data} { 67 177 my usbCmd $command 68 178 69 set usb_data {} 70 if {[catch {$usb_handle readEpt $size} result]} { 71 puts {Error during read} 72 puts $result 73 set result {} 74 } 75 76 my set data $result 77 } 78 79 # ------------------------------------------------------------------------- 80 81 Class CfgDisplay -superclass Display -parameter { 179 set code [catch {[my usbHandle] readRaw $size} result] 180 switch -- $code { 181 0 { 182 set $data $result 183 } 184 1 { 185 # puts $result 186 my usbConnect 187 } 188 5 { 189 # puts Busy 190 } 191 } 192 } 193 194 # ------------------------------------------------------------------------- 195 196 UsbController instproc usbCmdReadHex {command width size data} { 197 my usbCmd $command 198 199 set code [catch {[my usbHandle] readHex $width $size} result] 200 switch -- $code { 201 0 { 202 set $data $result 203 } 204 1 { 205 # puts $result 206 my usbConnect 207 } 208 5 { 209 # puts Busy 210 } 211 } 212 } 213 214 # ------------------------------------------------------------------------- 215 216 Class MuxDisplay -parameter { 82 217 {master} 83 } 84 85 # ------------------------------------------------------------------------- 86 87 CfgDisplay instproc init {} { 88 89 my reset 218 {controller} 219 } 220 221 # ------------------------------------------------------------------------- 222 223 MuxDisplay instproc init {} { 90 224 91 225 my setup … … 96 230 # ------------------------------------------------------------------------- 97 231 98 CfgDisplay instproc destroy {} {232 MuxDisplay instproc destroy {} { 99 233 next 100 234 } … … 102 236 # ------------------------------------------------------------------------- 103 237 104 CfgDisplay instproc reset {} { 105 } 106 107 # ------------------------------------------------------------------------- 108 109 CfgDisplay instproc start {} { 238 MuxDisplay instproc start {} { 239 my instvar config chan_val 240 241 set chan_val(1) 0 242 set chan_val(2) 0 243 set chan_val(3) 0 244 set chan_val(4) 0 245 set chan_val(5) 0 246 set chan_val(6) 0 247 248 trace add variable [myvar chan_val] write [myproc chan_val_update] 249 trace add variable [myvar polar] write [myproc polar_update] 250 251 $config(1).chan_1_1 select 252 $config(2).chan_1_2 select 253 $config(3).chan_1_3 select 254 $config(4).chan_1_1 select 255 $config(5).chan_3_1 select 256 $config(6).chan_3_1 select 257 258 for {set i 1} {$i <= 3} {incr i} { 259 $config(7).polar$i select 260 } 261 } 262 263 # ------------------------------------------------------------------------- 264 265 MuxDisplay instproc setup {} { 266 variable oscCodes 267 variable adcCodes 268 variable inpCodes 269 my instvar master 110 270 my instvar config 111 271 112 trace add variable [myvar dac1] write [myproc dac1_update] 113 trace add variable [myvar dac2] write [myproc dac2_update] 114 trace add variable [myvar polar] write [myproc polar_update] 115 116 ${config(1)}.dac1 set 0 117 ${config(1)}.dac2 set 0 118 119 ${config(2)}.polar1 select 120 ${config(2)}.polar2 select 121 ${config(2)}.polar3 select 122 } 123 124 # ------------------------------------------------------------------------- 125 126 CfgDisplay instproc setup {} { 127 my instvar number master 128 my instvar config 129 130 set config(1) [labelframe ${master}.cfg1 -borderwidth 1 -relief sunken -text {DAC}] 131 set config(2) [labelframe ${master}.cfg2 -borderwidth 1 -relief sunken -text {polarity inversion}] 132 133 frame ${config(1)}.limits 134 label ${config(1)}.limits.min -text {0.0V} 135 label ${config(1)}.limits.max -text {-3.3V} 136 137 scale ${config(1)}.dac1 -orient vertical -from 0 -to 4095 -tickinterval 500 -variable [myvar dac1] 138 scale ${config(1)}.dac2 -orient vertical -from 0 -to 4095 -tickinterval 0 -variable [myvar dac2] 139 140 checkbutton ${config(2)}.polar1 -text {channel 1} -variable [myvar polar(1)] 141 checkbutton ${config(2)}.polar2 -text {channel 2} -variable [myvar polar(2)] 142 checkbutton ${config(2)}.polar3 -text {channel 3} -variable [myvar polar(3)] 143 144 grid ${config(1)} -sticky ns 145 grid ${config(2)} -sticky ew -pady 7 146 147 pack ${config(1)}.limits.min -anchor n -side top -pady 10 148 pack ${config(1)}.limits.max -anchor s -side bottom -pady 9 149 150 grid ${config(1)}.dac1 ${config(1)}.dac2 ${config(1)}.limits -sticky ns -pady 7 151 152 grid ${config(2)}.polar1 153 grid ${config(2)}.polar2 154 grid ${config(2)}.polar3 272 set size [array size inpCodes] 273 set oscList [array get oscCodes] 274 set adcList [array get adcCodes] 275 set inpList [array get inpCodes] 276 277 foreach {osc title} $oscList { 278 set config($osc) [labelframe ${master}.mux_$osc -borderwidth 1 -relief sunken -text $title] 279 280 foreach {ch dummy} $adcList { 281 label $config($osc).chan_${ch} -text "#$ch " 282 grid $config($osc).chan_${ch} -row 0 -column $ch -sticky w 283 } 284 foreach {code input} $inpList { 285 set row [expr {$code + 1}] 286 set last 0 287 foreach {ch dummy} $adcList { 288 set value [expr {$size * ($ch - 1) + $code}] 289 radiobutton $config($osc).chan_${code}_${ch} -variable [myvar chan_val($osc)] -value ${value} 290 grid $config($osc).chan_${code}_${ch} -row ${row} -column $ch -sticky w 291 set last $ch 292 } 293 $config($osc).chan_${code}_${last} configure -text $input 294 } 295 set column [expr {($osc - 1) % 3}] 296 set row [expr {($osc - 1) / 3 * 2 + 1}] 297 grid $config($osc) -row $row -column $column -sticky news -padx 10 298 } 299 300 set config(7) [labelframe ${master}.mux_8 -borderwidth 1 -relief sunken -text {polarity inversion}] 301 for {set i 1} {$i <= 3} {incr i} { 302 checkbutton $config(7).polar$i -text "ADC $i" -variable [myvar polar($i)] 303 grid ${config(7)}.polar$i 304 } 305 grid $config(7) -row 2 -column 3 -sticky news -padx 10 306 307 grid columnconfigure ${master} 0 -weight 1 308 grid columnconfigure ${master} 1 -weight 1 309 grid columnconfigure ${master} 2 -weight 1 310 grid columnconfigure ${master} 3 -weight 1 155 311 156 312 grid rowconfigure ${master} 0 -weight 1 157 grid rowconfigure ${config(1)} 0 -weight 1 158 grid rowconfigure ${config(2)} 0 -weight 1 159 } 160 161 # ------------------------------------------------------------------------- 162 163 CfgDisplay instproc dac1_update args { 164 my instvar dac1 165 166 set value [format {%03x} $dac1] 167 set command 0005012000050030000500[string range $value 0 1]000502[string index $value 2]0 168 169 my usbCmd $command 170 } 171 172 # ------------------------------------------------------------------------- 173 174 CfgDisplay instproc dac2_update args { 175 my instvar dac2 176 177 set value [format {%03x} $dac2] 178 set command 0005012400050030000500[string range $value 0 1]000502[string index $value 2]0 179 180 my usbCmd $command 181 } 182 183 # ------------------------------------------------------------------------- 184 185 CfgDisplay instproc polar_update args { 186 my instvar polar 187 188 set value [format {0%x%x%x} $polar(3) $polar(2) $polar(1)] 189 190 my usbCmd 000A${value} 191 } 192 193 # ------------------------------------------------------------------------- 194 195 Class OscDisplay -superclass Display -parameter { 313 grid rowconfigure ${master} 1 -weight 0 314 grid rowconfigure ${master} 2 -weight 0 315 grid rowconfigure ${master} 3 -weight 0 316 grid rowconfigure ${master} 4 -weight 1 317 318 } 319 320 321 # ------------------------------------------------------------------------ 322 323 MuxDisplay instproc chan_val_update args { 324 my instvar controller chan_val 325 326 set byte1 [format {%02x%02x} $chan_val(2) $chan_val(1)] 327 set byte2 [format {%02x%02x} $chan_val(4) $chan_val(3)] 328 set byte3 [format {%02x%02x} $chan_val(6) $chan_val(5)] 329 330 $controller usbCmd 000200020004${byte1}000200030004${byte2}000200040004${byte3} 331 } 332 333 # ------------------------------------------------------------------------- 334 335 MuxDisplay instproc polar_update args { 336 my instvar controller polar 337 338 set value [format {%x%x%x} $polar(3) $polar(2) $polar(1)] 339 340 $controller usbCmd 0002000100040${value} 341 } 342 343 # ------------------------------------------------------------------------- 344 345 Class HstDisplay -parameter { 196 346 {number} 197 347 {master} 198 } 199 200 # ------------------------------------------------------------------------- 201 202 OscDisplay instproc init {} { 203 my instvar data xvec yvec 204 205 set xvec [vector #auto] 206 set yvec [vector #auto] 207 # fill one vector for the x axis with 1025 points 208 $xvec seq 0 1024 209 210 my reset 348 {controller} 349 } 350 351 # ------------------------------------------------------------------------- 352 353 HstDisplay instproc init {} { 354 355 my set data {} 356 357 vector create [myvar xvec](4096) 358 vector create [myvar yvec](4096) 359 360 # fill one vector for the x axis with 4096 points 361 [myvar xvec] seq -0.5 4095.5 211 362 212 363 my setup … … 217 368 # ------------------------------------------------------------------------- 218 369 219 OscDisplay instproc destroy {} {370 HstDisplay instproc destroy {} { 220 371 next 221 372 } … … 223 374 # ------------------------------------------------------------------------- 224 375 225 OscDisplay instproc reset {} { 226 my instvar data xvec yvec 227 228 set data {} 229 230 $yvec set {} 231 } 232 233 # ------------------------------------------------------------------------- 234 235 OscDisplay instproc start {} { 236 my instvar config trig_mux disp_mux 237 238 set trig_mux 2 239 set disp_mux 2 376 HstDisplay instproc start {} { 377 my instvar config 240 378 241 379 trace add variable [myvar data] write [myproc data_update] 242 trace add variable [myvar auto] write [myproc auto_update] 380 trace add variable [myvar cntr_val] write [myproc cntr_val_update] 381 trace add variable [myvar rate_val] write [myproc rate_val_update] 382 383 trace add variable [myvar axis] write [myproc axis_update] 243 384 trace add variable [myvar thrs] write [myproc thrs_update] 244 trace add variable [myvar thrs_val] write [myproc thrs_val_update] 245 trace add variable [myvar disp_val] write [myproc disp_val_update] 246 trace add variable [myvar trig_val] write [myproc trig_val_update] 247 248 ${config}.auto_check select 385 trace add variable [myvar thrs_val] write [myproc thrs_update] 386 387 ${config}.axis_check select 388 249 389 ${config}.thrs_check select 250 ${config}.thrs_field set 1278 251 ${config}.disp_uwt2 select 252 ${config}.trig_uwt2 select 253 } 254 255 # ------------------------------------------------------------------------- 256 257 OscDisplay instproc setup {} { 390 ${config}.thrs_field set 25 391 392 set cntr_tmp 1200000000 393 my set cntr_val $cntr_tmp 394 my set cntr_bak $cntr_tmp 395 my set cntr_old $cntr_tmp 396 my set yvec_bak 0.0 397 my set yvec_old 0.0 398 399 my set rate_val(inst) 0.0 400 my set rate_val(mean) 0.0 401 402 # my cntr_reset 403 } 404 405 # ------------------------------------------------------------------------- 406 407 HstDisplay instproc setup {} { 258 408 my instvar number master 259 my instvar data xvec yvec 260 my instvar config auto thrs thrs_val disp_val trig_val 409 my instvar xvec yvec graph 410 my instvar config thrs thrs_val 411 my instvar cntr_h cntr_m cntr_s 261 412 262 413 # create a graph widget and show a grid 263 414 set graph [graph ${master}.graph -height 250 -leftmargin 80] 264 $graph crosshairs configure -hide no -linewidth 2 -dashes { 1 1 } 265 $graph grid configure -hide no 266 $graph legend configure -hide yes 267 $graph axis configure x -min 0 -max 1024 268 $graph axis configure y -min 0 -max 4100 269 270 set config [frame ${master}.config] 271 272 checkbutton ${config}.auto_check -text {auto update} -variable [myvar auto] 273 274 frame ${config}.spc1 -width 10 -height 10 275 276 checkbutton ${config}.thrs_check -text threshold -variable [myvar thrs] 277 spinbox ${config}.thrs_field -from 1 -to 4095 \ 278 -increment 5 -width 10 -textvariable [myvar thrs_val] \ 279 -validate all -vcmd {::mca::validate 4095 %P} 280 281 frame ${config}.spc2 -width 10 -height 10 282 283 label ${config}.disp -text {display input} 284 radiobutton ${config}.disp_data -text {raw data} -variable [myvar disp_val] -value data 285 radiobutton ${config}.disp_uwt1 -text {filter 1} -variable [myvar disp_val] -value uwt1 286 radiobutton ${config}.disp_uwt2 -text {filter 2} -variable [myvar disp_val] -value uwt2 287 radiobutton ${config}.disp_uwt3 -text {filter 3} -variable [myvar disp_val] -value uwt3 288 radiobutton ${config}.disp_base -text {baseline} -variable [myvar disp_val] -value base 289 # radiobutton ${config}.disp_sum8 -text {sum of 8} -variable [myvar disp_val] -value sum8 290 291 frame ${config}.spc3 -width 10 -height 10 292 293 label ${config}.trig -text {trigger input} 294 radiobutton ${config}.trig_data -text {raw data} -variable [myvar trig_val] -value data 295 radiobutton ${config}.trig_uwt1 -text {filter 1} -variable [myvar trig_val] -value uwt1 296 radiobutton ${config}.trig_uwt2 -text {filter 2} -variable [myvar trig_val] -value uwt2 297 radiobutton ${config}.trig_uwt3 -text {filter 3} -variable [myvar trig_val] -value uwt3 298 radiobutton ${config}.trig_base -text {baseline} -variable [myvar trig_val] -value base 299 # radiobutton ${config}.trig_sum8 -text {sum of 8} -variable [myvar trig_val] -value sum8 300 301 frame ${config}.spc4 -width 10 -height 10 302 303 button ${config}.acquire -text Acquire \ 304 -bg green -activebackground green -command [myproc acquire] 305 button ${config}.restart -text Restart \ 306 -bg yellow -activebackground yellow -command [myproc restart] 307 button ${config}.register -text Register \ 308 -bg lightblue -activebackground lightblue -command [myproc register] 309 310 grid ${config}.auto_check -sticky w 311 grid ${config}.spc1 312 grid ${config}.thrs_check -sticky w 313 grid ${config}.thrs_field -sticky ew -pady 1 -padx 5 314 grid ${config}.spc2 315 grid ${config}.disp -sticky w -pady 1 -padx 3 316 grid ${config}.disp_data -sticky w 317 grid ${config}.disp_uwt1 -sticky w 318 grid ${config}.disp_uwt2 -sticky w 319 grid ${config}.disp_uwt3 -sticky w 320 grid ${config}.disp_base -sticky w 321 # grid ${config}.disp_sum8 -sticky w 322 grid ${config}.spc3 323 grid ${config}.trig -sticky w -pady 1 -padx 3 324 grid ${config}.trig_data -sticky w 325 grid ${config}.trig_uwt1 -sticky w 326 grid ${config}.trig_uwt2 -sticky w 327 grid ${config}.trig_uwt3 -sticky w 328 grid ${config}.trig_base -sticky w 329 # grid ${config}.disp_sum8 -sticky w 330 grid ${config}.spc4 331 grid ${config}.acquire -sticky ew -pady 3 -padx 5 332 grid ${config}.restart -sticky ew -pady 3 -padx 5 333 grid ${config}.register -sticky ew -pady 3 -padx 5 334 335 grid ${graph} -row 0 -column 0 -sticky news 336 grid ${config} -row 0 -column 1 337 338 grid rowconfigure ${master} 0 -weight 1 339 grid columnconfigure ${master} 0 -weight 1 340 grid columnconfigure ${master} 1 -weight 0 -minsize 80 341 342 # enable zooming 343 Blt_ZoomStack $graph 344 345 #bind .graph <Motion> {%W crosshairs configure -position @%x,%y} 346 347 # create one element with data for the x and y axis, no dots 348 $graph element create Spectrum1 -symbol none -xdata $xvec -ydata $yvec 349 } 350 351 # ------------------------------------------------------------------------- 352 353 OscDisplay instproc data_update args { 354 my instvar data yvec 355 $yvec set $data 356 } 357 358 # ------------------------------------------------------------------------- 359 360 OscDisplay instproc auto_update args { 361 my instvar config auto after_handle 362 363 if {$auto} { 364 ${config}.acquire configure -state disabled 365 ${config}.restart configure -state disabled 366 ${config}.register configure -state disabled 367 368 my acquire_restart_loop 369 } else { 370 if {[my exists after_handle]} { 371 after cancel $after_handle 372 } 373 ${config}.acquire configure -state active 374 ${config}.restart configure -state active 375 ${config}.register configure -state active 376 } 377 } 378 379 # ------------------------------------------------------------------------- 380 381 OscDisplay instproc thrs_update args { 382 my instvar config number thrs thrs_val 383 384 set val_addr [format %04x [expr {17 + ${number}}]] 385 386 if {$thrs} { 387 ${config}.thrs_field configure -state normal 388 my thrs_val_update 389 } else { 390 ${config}.thrs_field configure -state disabled 391 my usbCmd ${val_addr}0000 392 } 393 } 394 395 # ------------------------------------------------------------------------- 396 397 OscDisplay instproc thrs_val_update args { 398 my instvar config number thrs_val 399 400 if {[string equal $thrs_val {}]} { 401 set thrs_val 0 402 } 403 404 set val_addr [format %04x [expr {17 + ${number}}]] 405 set value [format %04x $thrs_val] 406 407 my usbCmd ${val_addr}${value} 408 } 409 410 # ------------------------------------------------------------------------- 411 412 OscDisplay instproc mux {} { 413 my instvar trig_mux disp_mux 414 415 format {00%x%x} $trig_mux $disp_mux 416 } 417 418 # ------------------------------------------------------------------------ 419 420 OscDisplay instproc disp_val_update args { 421 my instvar number disp_val disp_mux 422 423 set mux_addr [format %04x [expr {20 + ${number}}]] 424 425 switch -- $disp_val { 426 data { 427 set disp_mux 0 428 my usbCmd ${mux_addr}[my mux] 429 } 430 uwt1 { 431 set disp_mux 1 432 my usbCmd ${mux_addr}[my mux] 433 } 434 uwt2 { 435 set disp_mux 2 436 my usbCmd ${mux_addr}[my mux] 437 } 438 uwt3 { 439 set disp_mux 3 440 my usbCmd ${mux_addr}[my mux] 441 } 442 base { 443 set disp_mux 4 444 my usbCmd ${mux_addr}[my mux] 445 } 446 } 447 } 448 449 # ------------------------------------------------------------------------ 450 451 OscDisplay instproc trig_val_update args { 452 my instvar number trig_val trig_mux 453 454 set mux_addr [format %04x [expr {20 + ${number}}]] 455 456 switch -- $trig_val { 457 data { 458 set trig_mux 0 459 my usbCmd ${mux_addr}[my mux] 460 } 461 uwt1 { 462 set trig_mux 1 463 my usbCmd ${mux_addr}[my mux] 464 } 465 uwt2 { 466 set trig_mux 2 467 my usbCmd ${mux_addr}[my mux] 468 } 469 uwt3 { 470 set trig_mux 3 471 my usbCmd ${mux_addr}[my mux] 472 } 473 base { 474 set trig_mux 4 475 my usbCmd ${mux_addr}[my mux] 476 } 477 } 478 } 479 480 # ------------------------------------------------------------------------- 481 482 OscDisplay instproc save_data {data} { 483 set file [tk_getSaveFile] 484 if {[string equal $file {}]} { 485 return 486 } 487 488 set x [catch {set fid [open $file w+]}] 489 set y [catch {puts $fid $data}] 490 set z [catch {close $fid}] 491 492 if { $x || $y || $z || ![file exists $file] || ![file isfile $file] || ![file readable $file] } { 493 tk_messageBox -icon error \ 494 -message "An error occurred while writing to \"$file\"" 495 } else { 496 tk_messageBox -icon info \ 497 -message "File \"$file\" written successfully" 498 } 499 } 500 501 # ------------------------------------------------------------------------- 502 503 OscDisplay instproc acquire {} { 504 my instvar number 505 my usbCmdRead 0002000${number} 2 1024 506 } 507 508 # ------------------------------------------------------------------------- 509 510 OscDisplay instproc restart {} { 511 my instvar number 512 my usbCmd 0001000${number} 513 } 514 515 # ------------------------------------------------------------------------- 516 517 OscDisplay instproc register {} { 518 my save_data [my set data] 519 } 520 521 # ------------------------------------------------------------------------- 522 523 OscDisplay instproc acquire_restart_loop {} { 524 my instvar number after_handle 525 526 my acquire 527 my restart 528 529 set after_handle [after 1000 [myproc acquire_restart_loop]] 530 } 531 532 # ------------------------------------------------------------------------- 533 534 Class HstDisplay -superclass Display -parameter { 535 {number} 536 {master} 537 } 538 539 # ------------------------------------------------------------------------- 540 541 HstDisplay instproc init {} { 542 my instvar data xvec yvec 543 544 set xvec [vector #auto] 545 set yvec [vector #auto] 546 # fill one vector for the x axis with 4097 points 547 $xvec seq 0 4096 548 549 my reset 550 551 my setup 552 553 next 554 } 555 556 # ------------------------------------------------------------------------- 557 558 HstDisplay instproc destroy {} { 559 next 560 } 561 562 # ------------------------------------------------------------------------- 563 564 HstDisplay instproc reset {} { 565 my instvar data xvec yvec 566 567 set data {} 568 569 $yvec set {} 570 } 571 572 # ------------------------------------------------------------------------- 573 574 HstDisplay instproc start {} { 575 my instvar config base_mux peak_mux 576 577 set base_mux 0 578 set peak_mux 1 579 580 trace add variable [myvar axis] write [myproc axis_update] 581 trace add variable [myvar data] write [myproc data_update] 582 trace add variable [myvar auto] write [myproc auto_update] 583 trace add variable [myvar peak] write [myproc peak_update] 584 trace add variable [myvar thrs] write [myproc thrs_update] 585 trace add variable [myvar thrs_val] write [myproc thrs_val_update] 586 trace add variable [myvar base] write [myproc base_update] 587 trace add variable [myvar base_typ] write [myproc base_typ_update] 588 trace add variable [myvar base_val] write [myproc base_val_update] 589 590 ${config}.axis_check deselect 591 ${config}.auto_check select 592 ${config}.peak_check select 593 594 ${config}.thrs_check select 595 ${config}.thrs_field set 1278 596 597 ${config}.base_const select 598 ${config}.base_field set 35 599 ${config}.base_check deselect 600 } 601 602 # ------------------------------------------------------------------------- 603 604 HstDisplay instproc setup {} { 605 my instvar number master 606 my instvar data xvec yvec graph 607 my instvar config auto thrs thrs_val base base_typ base_val 608 609 # create a graph widget and show a grid 610 set graph [graph ${master}.graph -height 250 -leftmargin 80] 611 $graph crosshairs configure -hide no -linewidth 2 -dashes { 1 1 } 415 $graph crosshairs configure -hide no -linewidth 1 -color darkblue -dashes {2 2} 612 416 $graph grid configure -hide no 613 417 $graph legend configure -hide yes 614 418 $graph axis configure x -min 0 -max 4096 615 419 616 set config [frame ${master}.config ]420 set config [frame ${master}.config -width 170] 617 421 618 422 checkbutton ${config}.axis_check -text {log scale} -variable [myvar axis] 619 423 620 frame ${config}.spc1 -width 10 -height 10 621 622 checkbutton ${config}.auto_check -text {auto update} -variable [myvar auto] 623 624 frame ${config}.spc2 -width 10 -height 10 625 626 checkbutton ${config}.peak_check -text {peak detect} -variable [myvar peak] 627 628 frame ${config}.spc3 -width 10 -height 10 629 630 checkbutton ${config}.thrs_check -text threshold -variable [myvar thrs] 424 frame ${config}.spc1 -width 170 -height 30 425 426 frame ${config}.rate_frame -borderwidth 0 -width 170 427 legendLabel ${config}.rate_frame 0 inst {Inst. rate, 1/s} 428 legendLabel ${config}.rate_frame 1 mean {Avg. rate, 1/s} 429 430 frame ${config}.spc2 -width 170 -height 30 431 432 frame ${config}.chan_frame -borderwidth 0 -width 170 433 legendLabel ${config}.chan_frame 0 entr {Total entries} 434 legendLabel ${config}.chan_frame 1 empty {} 435 legendLabel ${config}.chan_frame 2 axisy {Bin entries} 436 legendLabel ${config}.chan_frame 3 axisx {Bin number} 437 438 frame ${config}.spc3 -width 170 -height 30 439 440 checkbutton ${config}.thrs_check -text {amplitude threshold} -variable [myvar thrs] 631 441 spinbox ${config}.thrs_field -from 1 -to 4095 \ 632 442 -increment 5 -width 10 -textvariable [myvar thrs_val] \ 633 -validate all -vcmd {::mca::validate 4095 %P} 634 635 frame ${config}.spc4 -width 10 -height 10 636 637 checkbutton ${config}.base_check -text baseline -variable [myvar base] 638 radiobutton ${config}.base_auto -text automatic -variable [myvar base_typ] -value auto 639 radiobutton ${config}.base_const -text constant -variable [myvar base_typ] -value const 640 spinbox ${config}.base_field -from 1 -to 4095 \ 641 -increment 5 -width 10 -textvariable [myvar base_val] \ 642 -validate all -vcmd {::mca::validate 4095 %P} 643 644 frame ${config}.spc5 -width 10 -height 10 645 646 button ${config}.acquire -text Acquire \ 647 -bg green -activebackground green -command [myproc acquire] 648 button ${config}.restart -text Restart \ 649 -bg yellow -activebackground yellow -command [myproc restart] 443 -validate all -vcmd {::mca::validate 4095 4 %P} 444 445 frame ${config}.spc4 -width 170 -height 30 446 447 label ${config}.cntr -text {time of exposure} 448 frame ${config}.cntr_frame -borderwidth 0 -width 170 449 450 label ${config}.cntr_frame.h -width 3 -anchor w -text {h} 451 entry ${config}.cntr_frame.h_field -width 3 -textvariable [myvar cntr_h] \ 452 -validate all -vcmd {::mca::validate 999 3 %P} 453 label ${config}.cntr_frame.m -width 3 -anchor w -text {m} 454 entry ${config}.cntr_frame.m_field -width 3 -textvariable [myvar cntr_m] \ 455 -validate all -vcmd {::mca::validate 59 2 %P} 456 label ${config}.cntr_frame.s -width 3 -anchor w -text {s} 457 entry ${config}.cntr_frame.s_field -width 6 -textvariable [myvar cntr_s] \ 458 -validate all -vcmd {::mca::doublevalidate 59.999 %P} 459 460 grid ${config}.cntr_frame.h_field ${config}.cntr_frame.h \ 461 ${config}.cntr_frame.m_field ${config}.cntr_frame.m ${config}.cntr_frame.s_field ${config}.cntr_frame.s 462 463 frame ${config}.spc5 -width 170 -height 10 464 465 button ${config}.start -text Start \ 466 -bg yellow -activebackground yellow -command [myproc cntr_start] 467 button ${config}.reset -text Reset \ 468 -bg red -activebackground red -command [myproc cntr_reset] 469 470 frame ${config}.spc6 -width 170 -height 30 471 472 650 473 button ${config}.register -text Register \ 651 474 -bg lightblue -activebackground lightblue -command [myproc register] … … 653 476 grid ${config}.axis_check -sticky w 654 477 grid ${config}.spc1 655 grid ${config}. auto_check -sticky w478 grid ${config}.rate_frame -sticky ew -padx 5 656 479 grid ${config}.spc2 657 grid ${config}. peak_check -sticky w480 grid ${config}.chan_frame -sticky ew -padx 5 658 481 grid ${config}.spc3 659 482 grid ${config}.thrs_check -sticky w 660 483 grid ${config}.thrs_field -sticky ew -pady 1 -padx 5 661 484 grid ${config}.spc4 662 grid ${config}.base_check -sticky w 663 grid ${config}.base_auto -sticky w 664 grid ${config}.base_const -sticky w 665 grid ${config}.base_field -sticky ew -pady 1 -padx 5 485 grid ${config}.cntr -sticky w -pady 1 -padx 3 486 grid ${config}.cntr_frame -sticky ew -padx 5 666 487 grid ${config}.spc5 667 grid ${config}.acquire -sticky ew -pady 3 -padx 5 668 grid ${config}.restart -sticky ew -pady 3 -padx 5 488 grid ${config}.start -sticky ew -pady 3 -padx 5 489 grid ${config}.reset -sticky ew -pady 3 -padx 5 490 grid ${config}.spc6 669 491 grid ${config}.register -sticky ew -pady 3 -padx 5 670 492 … … 676 498 grid columnconfigure ${master} 1 -weight 0 -minsize 80 677 499 500 grid columnconfigure ${config}.rate_frame 1 -weight 1 501 grid columnconfigure ${config}.chan_frame 1 -weight 1 502 678 503 # enable zooming 679 504 Blt_ZoomStack $graph 680 505 506 my crosshairs $graph 507 681 508 #bind .graph <Motion> {%W crosshairs configure -position @%x,%y} 682 509 683 510 # create one element with data for the x and y axis, no dots 684 $graph element create Spectrum1 -symbol none -smooth step -xdata $xvec -ydata $yvec 511 $graph element create Spectrum1 -color blue -linewidth 2 -symbol none -smooth step -xdata [myvar xvec] -ydata [myvar yvec] 512 } 513 514 # ------------------------------------------------------------------------- 515 516 HstDisplay instproc coor_update {W x y} { 517 my instvar config graph 518 519 $W crosshairs configure -position @${x},${y} 520 521 set index [$W axis invtransform x $x] 522 set index [::tcl::mathfunc::round $index] 523 catch { 524 ${config}.chan_frame.axisy_value configure -text [[myvar yvec] index $index] 525 ${config}.chan_frame.axisx_value configure -text ${index}.0 526 } 527 } 528 # ------------------------------------------------------------------------- 529 530 HstDisplay instproc crosshairs {graph} { 531 set method [myproc coor_update] 532 bind $graph <Motion> [list [self] coor_update %W %x %y] 533 bind $graph <Leave> { 534 %W crosshairs off 535 } 536 bind $graph <Enter> { 537 %W crosshairs on 538 } 685 539 } 686 540 … … 698 552 # ------------------------------------------------------------------------- 699 553 700 HstDisplay instproc data_update args {701 my instvar data yvec702 $yvec set $data703 }704 705 # -------------------------------------------------------------------------706 707 HstDisplay instproc auto_update args {708 my instvar auto after_handle709 my instvar config710 if {$auto} {711 ${config}.acquire configure -state disabled712 ${config}.register configure -state disabled713 714 my acquire_loop715 } else {716 if {[my exists after_handle]} {717 after cancel $after_handle718 }719 ${config}.acquire configure -state active720 ${config}.register configure -state active721 }722 }723 724 # -------------------------------------------------------------------------725 726 HstDisplay instproc mux {} {727 my instvar base_mux peak_mux728 729 format {00%x%x} $base_mux $peak_mux730 }731 732 # -------------------------------------------------------------------------733 734 HstDisplay instproc peak_update args {735 my instvar number peak peak_mux736 737 set mux_addr [format %04x [expr {23 + ${number}}]]738 739 if {$peak} {740 set peak_mux 1741 my usbCmd ${mux_addr}[my mux]742 } else {743 set peak_mux 0744 my usbCmd ${mux_addr}[my mux]745 }746 }747 748 # -------------------------------------------------------------------------749 750 554 HstDisplay instproc thrs_update args { 751 my instvar config number thrs thrs_val 752 753 set val_addr [format %04x [expr {14 + ${number}}]] 555 my instvar controller config number thrs thrs_val 556 557 if {[string equal $thrs_val {}]} { 558 set thrs_val 0 559 } 560 561 set val_addr [format %02x [expr {6 + 2 * ${number}}]] 754 562 755 563 if {$thrs} { 756 564 ${config}.thrs_field configure -state normal 757 my thrs_val_update565 set value [format %03x $thrs_val] 758 566 } else { 759 567 ${config}.thrs_field configure -state disabled 760 my usbCmd ${val_addr}0000 761 } 762 } 763 764 # ------------------------------------------------------------------------- 765 766 HstDisplay instproc thrs_val_update args { 767 my instvar config number thrs_val 568 set value 000 569 } 570 571 $controller usbCmd 000200${val_addr}00040${value} 572 } 573 574 # ------------------------------------------------------------------------- 575 576 HstDisplay instproc rate_val_update {name key op} { 577 my instvar config rate_val 578 579 ${config}.rate_frame.${key}_value configure -text [format {%.2e} $rate_val(${key})] 580 } 581 582 # ------------------------------------------------------------------------- 583 584 HstDisplay instproc cntr_val_update args { 585 my instvar cntr_val cntr_h cntr_m cntr_s 586 587 set cntr_tmp [expr {${cntr_val}/20000}] 588 set cntr_h [expr {${cntr_tmp}/3600000}] 589 set cntr_m [expr {${cntr_tmp}%3600000/60000}] 590 set cntr_s [expr {${cntr_tmp}%3600000%60000/1000.0}] 591 } 592 593 # ------------------------------------------------------------------------- 594 595 HstDisplay instproc cntr_setup {} { 596 my instvar controller number cntr_val 597 598 set word0 [format %08x [expr {${cntr_val} & 0xFFFFFFFF}]] 599 set word1 [format %08x [expr {${cntr_val} >> 32}]] 600 601 set prefix [format %x [expr {5 + ${number}}]] 602 603 set command {} 604 append command 0001${prefix}000000200000004[string range $word0 4 7] 605 append command 0001${prefix}000000200010004[string range $word0 0 3] 606 append command 0001${prefix}000000200020004[string range $word1 4 7] 607 append command 0001${prefix}000000200030004[string range $word1 0 3] 608 609 # send counter value 610 $controller usbCmd $command 611 612 # load counter value 613 # set val_addr [format %02x [expr {12 + ${number}}]] 614 # $controller usbCmd 000200${val_addr}00040001000200${val_addr}00040000 615 } 616 617 # ------------------------------------------------------------------------- 618 619 HstDisplay instproc cntr_reset {} { 620 my instvar controller number after_handle 621 my instvar cntr_val cntr_bak cntr_old yvec_bak yvec_old 622 623 my cntr_stop 624 625 set value [format %04x [expr {1 << (5 + ${number})}]] 626 $controller usbCmd 000200000004${value}0002000000040000 627 628 set cntr_val $cntr_bak 629 my cntr_setup 630 631 set cntr_old $cntr_bak 632 set yvec_bak 0.0 633 set yvec_old 0.0 634 635 my acquire 636 637 my cntr_ready 638 } 639 640 # ------------------------------------------------------------------------- 641 642 HstDisplay instproc cntr_ready {} { 643 my instvar config cntr_val cntr_bak 644 645 set cntr_val $cntr_bak 646 647 ${config}.start configure -text Start -command [myproc cntr_start] 648 ${config}.reset configure -state active 649 650 ${config}.cntr_frame.h_field configure -state normal 651 ${config}.cntr_frame.m_field configure -state normal 652 ${config}.cntr_frame.s_field configure -state normal 653 } 654 655 # ------------------------------------------------------------------------- 656 657 HstDisplay instproc cntr_start {} { 658 my instvar config 659 my instvar cntr_h cntr_m cntr_s 660 my instvar cntr_val cntr_bak cntr_old yvec_bak yvec_old 661 662 set h $cntr_h 663 set m $cntr_m 664 set s $cntr_s 665 666 if {[string equal $h {}]} { 667 set h 0 668 } 669 if {[string equal $m {}]} { 670 set m 0 671 } 672 if {[string equal $s {}]} { 673 set s 0 674 } 675 676 set cntr_tmp [expr {${h}*3600000 + ${m}*60000 + ${s}*1000}] 677 set cntr_tmp [expr {entier(20000 * ${cntr_tmp})}] 678 679 if {$cntr_tmp > 0} { 680 ${config}.cntr_frame.h_field configure -state disabled 681 ${config}.cntr_frame.m_field configure -state disabled 682 ${config}.cntr_frame.s_field configure -state disabled 683 684 set cntr_val $cntr_tmp 685 set cntr_bak $cntr_tmp 686 set cntr_old $cntr_tmp 687 set yvec_bak [usb::integrateBlt [myvar yvec] 0] 688 set yvec_old $yvec_bak 689 690 my cntr_setup 691 692 my cntr_resume 693 } 694 } 695 696 # ------------------------------------------------------------------------- 697 698 HstDisplay instproc cntr_pause {} { 699 my instvar config 700 701 my cntr_stop 702 703 ${config}.start configure -text Resume -command [myproc cntr_resume] 704 # ${config}.reset configure -state active 705 706 } 707 708 # ------------------------------------------------------------------------- 709 710 HstDisplay instproc cntr_resume {} { 711 my instvar controller config number auto 712 713 set val_addr [format %02x [expr {13 + ${number}}]] 714 715 ${config}.start configure -text Pause -command [myproc cntr_pause] 716 # ${config}.reset configure -state disabled 717 718 $controller usbCmd 000200${val_addr}00040002 719 720 set auto 1 721 722 after 100 [myproc acquire_loop] 723 } 724 725 # ------------------------------------------------------------------------- 726 727 HstDisplay instproc cntr_stop {} { 728 my instvar controller config number auto 729 730 set val_addr [format %02x [expr {13 + ${number}}]] 731 732 $controller usbCmd 000200${val_addr}00040000 733 734 set auto 0 735 } 736 737 # ------------------------------------------------------------------------- 738 739 HstDisplay instproc data_update args { 740 my instvar data 741 usb::convertBlt $data 4 [myvar yvec] 742 } 743 744 # ------------------------------------------------------------------------- 745 746 HstDisplay instproc acquire_loop {} { 747 my instvar cntr_val auto 748 749 my acquire 750 751 if {$cntr_val == 0} { 752 my cntr_stop 753 my cntr_ready 754 } elseif {$auto} { 755 after 1000 [myproc acquire_loop] 756 } 757 } 758 759 # ------------------------------------------------------------------------- 760 761 HstDisplay instproc acquire {} { 762 my instvar controller config number 763 my instvar cntr_val cntr_bak cntr_old yvec_bak yvec_old rate_val 764 765 set size 4096 766 767 set prefix [format {%x} [expr {$number + 2}]] 768 769 set value [format {%08x} [expr {$size * 2}]] 770 771 set command 0001${prefix}000000200000001[string range $value 0 3]0003[string range $value 4 7]00050000 772 773 $controller usbCmdReadRaw $command [expr {$size * 4}] [myvar data] 774 set yvec_new [usb::integrateBlt [myvar yvec] 0] 775 776 set prefix [format {%x} [expr {$number + 5}]] 777 set command 0001${prefix}000000200000003000400050000 778 779 $controller usbCmdReadHex $command 8 1 [myvar cntr_val] 780 set cntr_new $cntr_val 781 782 if {$cntr_new < $cntr_old} { 783 set rate_val(inst) [expr {($yvec_new - $yvec_old)*20000000/($cntr_old - $cntr_new)}] 784 set rate_val(mean) [expr {($yvec_new - $yvec_bak)*20000000/($cntr_bak - $cntr_new)}] 785 ${config}.chan_frame.entr_value configure -text $yvec_new 786 787 set yvec_old $yvec_new 788 set cntr_old $cntr_new 789 } 790 } 791 792 # ------------------------------------------------------------------------- 793 794 HstDisplay instproc save_data {data} { 795 my instvar number 796 797 set types { 798 {{Data Files} {.dat} } 799 {{All Files} * } 800 } 801 802 set stamp [clock format [clock seconds] -format %Y%m%d_%H%M%S] 803 set fname spectrum_[expr {$number + 1}]_${stamp}.dat 804 805 set fname [tk_getSaveFile -filetypes $types -initialfile $fname] 806 if {[string equal $fname {}]} { 807 return 808 } 809 810 set x [catch { 811 set fid [open $fname w+] 812 puts $fid $data 813 close $fid 814 }] 815 816 if { $x || ![file exists $fname] || ![file isfile $fname] || ![file readable $fname] } { 817 tk_messageBox -icon error \ 818 -message "An error occurred while writing to \"$fname\"" 819 } else { 820 tk_messageBox -icon info \ 821 -message "File \"$fname\" written successfully" 822 } 823 } 824 825 # ------------------------------------------------------------------------- 826 827 HstDisplay instproc register {} { 828 my save_data [join [[myvar yvec] range 0 4095] \n] 829 } 830 831 # ------------------------------------------------------------------------- 832 833 Class CntDisplay -parameter { 834 {master} 835 {controller} 836 } 837 838 # ------------------------------------------------------------------------- 839 840 CntDisplay instproc init {} { 841 842 my set data {} 843 my set cntr 0 844 my set recs 0 845 846 vector create [myvar xvec](16384) 847 vector create [myvar yvec](16384) 848 849 # fill one vector for the x axis with 16384 points 850 [myvar xvec] seq -0.5 16384.5 851 852 my setup 853 854 next 855 } 856 857 # ------------------------------------------------------------------------- 858 859 CntDisplay instproc destroy {} { 860 next 861 } 862 863 # ------------------------------------------------------------------------- 864 865 CntDisplay instproc start {} { 866 my instvar config 867 868 trace add variable [myvar data] write [myproc data_update] 869 870 trace add variable [myvar thrs] write [myproc thrs_update] 871 trace add variable [myvar thrs_val] write [myproc thrs_update] 872 873 trace add variable [myvar cntr] write [myproc cntr_update] 874 trace add variable [myvar recs] write [myproc recs_update] 875 876 trace add variable [myvar axis] write [myproc axis_update] 877 878 ${config}.axis_check select 879 880 ${config}.thrs_check select 881 ${config}.thrs_field set 25 882 883 my set cntr_val 100 884 my set cntr_bak 100 885 my set recs_val 100 886 my set recs_bak 100 887 888 # my cntr_reset 889 } 890 891 # ------------------------------------------------------------------------- 892 893 CntDisplay instproc setup {} { 894 my instvar master 895 my instvar xvec yvec graph 896 my instvar config 897 my instvar cntr_ms 898 899 # create a graph widget and show a grid 900 set graph [graph ${master}.graph -height 250 -leftmargin 80] 901 $graph crosshairs configure -hide no -linewidth 1 -color darkblue -dashes {2 2} 902 $graph grid configure -hide no 903 $graph legend configure -hide yes 904 $graph axis configure x -min 0 -max 16384 905 906 set config [frame ${master}.config -width 170] 907 908 checkbutton ${config}.axis_check -text {log scale} -variable [myvar axis] 909 910 frame ${config}.spc1 -width 170 -height 30 911 912 frame ${config}.chan_frame -borderwidth 0 -width 170 913 legendLabel ${config}.chan_frame 0 mean {Mean value} 914 legendLabel ${config}.chan_frame 1 entr {Total entries} 915 legendLabel ${config}.chan_frame 2 empty {} 916 legendLabel ${config}.chan_frame 3 axisy {Bin entries} 917 legendLabel ${config}.chan_frame 4 axisx {Bin number} 918 919 frame ${config}.spc3 -width 170 -height 30 920 921 checkbutton ${config}.thrs_check -text {amplitude threshold} -variable [myvar thrs] 922 spinbox ${config}.thrs_field -from 1 -to 4095 \ 923 -increment 5 -width 10 -textvariable [myvar thrs_val] \ 924 -validate all -vcmd {::mca::validate 4095 4 %P} 925 926 frame ${config}.spc4 -width 170 -height 30 927 928 label ${config}.cntr -text {time of exposure (ms)} 929 spinbox ${config}.cntr_field -from 0 -to 9999 \ 930 -increment 10 -width 10 -textvariable [myvar cntr_val] \ 931 -validate all -vcmd {::mca::validate 9999 4 %P} 932 933 frame ${config}.spc5 -width 170 -height 10 934 935 label ${config}.recs -text {number of exposures} 936 spinbox ${config}.recs_field -from 0 -to 99999 \ 937 -increment 10 -width 10 -textvariable [myvar recs_val] \ 938 -validate all -vcmd {::mca::validate 99999 5 %P} 939 940 frame ${config}.spc6 -width 170 -height 10 941 942 button ${config}.start -text {Start} \ 943 -bg yellow -activebackground yellow -command [myproc recs_start] 944 945 button ${config}.reset -text Reset \ 946 -bg red -activebackground red -command [myproc cntr_reset] 947 948 frame ${config}.spc7 -width 170 -height 30 949 950 button ${config}.register -text Register \ 951 -bg lightblue -activebackground lightblue -command [myproc register] 952 953 grid ${config}.axis_check -sticky w 954 grid ${config}.spc1 955 grid ${config}.chan_frame -sticky ew -padx 5 956 grid ${config}.spc3 957 grid ${config}.thrs_check -sticky w 958 grid ${config}.thrs_field -sticky ew -pady 1 -padx 5 959 grid ${config}.spc4 960 grid ${config}.cntr -sticky w -pady 1 -padx 3 961 grid ${config}.cntr_field -sticky ew -pady 1 -padx 5 962 grid ${config}.spc5 963 grid ${config}.recs -sticky w -pady 1 -padx 3 964 grid ${config}.recs_field -sticky ew -pady 1 -padx 5 965 grid ${config}.spc6 966 grid ${config}.start -sticky ew -pady 3 -padx 5 967 grid ${config}.reset -sticky ew -pady 3 -padx 5 968 grid ${config}.spc7 969 grid ${config}.register -sticky ew -pady 3 -padx 5 970 971 grid ${graph} -row 0 -column 0 -sticky news 972 grid ${config} -row 0 -column 1 973 974 grid rowconfigure ${master} 0 -weight 1 975 grid columnconfigure ${master} 0 -weight 1 976 grid columnconfigure ${master} 1 -weight 0 -minsize 80 977 978 grid columnconfigure ${config}.chan_frame 1 -weight 1 979 980 # enable zooming 981 Blt_ZoomStack $graph 982 983 my crosshairs $graph 984 985 #bind .graph <Motion> {%W crosshairs configure -position @%x,%y} 986 987 # create one element with data for the x and y axis, no dots 988 $graph element create Spectrum1 -color blue -linewidth 2 -symbol none -smooth step -xdata [myvar xvec] -ydata [myvar yvec] 989 } 990 991 # ------------------------------------------------------------------------- 992 993 CntDisplay instproc coor_update {W x y} { 994 my instvar config graph 995 996 $W crosshairs configure -position @${x},${y} 997 998 set index [$W axis invtransform x $x] 999 set index [::tcl::mathfunc::round $index] 1000 catch { 1001 ${config}.chan_frame.axisy_value configure -text [[myvar yvec] index $index] 1002 ${config}.chan_frame.axisx_value configure -text ${index}.0 1003 } 1004 } 1005 # ------------------------------------------------------------------------- 1006 1007 CntDisplay instproc crosshairs {graph} { 1008 set method [myproc coor_update] 1009 bind $graph <Motion> [list [self] coor_update %W %x %y] 1010 bind $graph <Leave> { 1011 %W crosshairs off 1012 } 1013 bind $graph <Enter> { 1014 %W crosshairs on 1015 } 1016 } 1017 1018 # ------------------------------------------------------------------------- 1019 1020 CntDisplay instproc thrs_update args { 1021 my instvar controller config thrs thrs_val 768 1022 769 1023 if {[string equal $thrs_val {}]} { … … 771 1025 } 772 1026 773 set val_addr [format %04x [expr {14 + ${number}}]] 774 set value [format %04x $thrs_val] 775 776 my usbCmd ${val_addr}${value} 777 } 778 779 # ------------------------------------------------------------------------- 780 781 HstDisplay instproc base_update args { 782 my instvar config number base base_val base_mux 783 784 set mux_addr [format %04x [expr {23 + ${number}}]] 785 set val_addr [format %04x [expr {11 + ${number}}]] 786 787 if {$base} { 788 ${config}.base_auto configure -state normal 789 ${config}.base_const configure -state normal 790 my base_typ_update 1027 set number 0 1028 set val_addr [format %02x [expr {7 + 2 * ${number}}]] 1029 1030 if {$thrs} { 1031 ${config}.thrs_field configure -state normal 1032 set value [format %03x $thrs_val] 791 1033 } else { 792 ${config}.base_auto configure -state disabled 793 ${config}.base_const configure -state disabled 794 ${config}.base_field configure -state disabled 795 set base_mux 0 796 my usbCmd ${mux_addr}[my mux]${val_addr}0000 797 } 798 } 799 800 # ------------------------------------------------------------------------- 801 802 HstDisplay instproc base_typ_update args { 803 my instvar config number base_typ base_val base_mux 804 805 set mux_addr [format %04x [expr {23 + ${number}}]] 806 set val_addr [format %04x [expr {11 + ${number}}]] 807 set value [format %04x $base_val] 808 809 switch -- $base_typ { 810 auto { 811 ${config}.base_field configure -state disabled 812 set base_mux 1 813 my usbCmd ${mux_addr}[my mux] 814 } 815 const { 816 ${config}.base_field configure -state normal 817 set base_mux 0 818 my usbCmd ${mux_addr}[my mux]${val_addr}${value} 819 } 820 } 821 } 822 823 # ------------------------------------------------------------------------- 824 825 HstDisplay instproc base_val_update args { 826 my instvar number base_val 827 828 if {[string equal $base_val {}]} { 829 set base_val 0 830 } 831 832 set val_addr [format %04x [expr {11 + ${number}}]] 833 set value [format %04x $base_val] 834 835 my usbCmd ${val_addr}${value} 836 } 837 838 # ------------------------------------------------------------------------- 839 840 HstDisplay instproc acquire {} { 841 my instvar number 842 my usbCmdRead 0002001${number} 4 4096 1034 ${config}.thrs_field configure -state disabled 1035 set value 000 1036 } 1037 1038 $controller usbCmd 000200${val_addr}00040${value} 1039 } 1040 1041 # ------------------------------------------------------------------------- 1042 1043 CntDisplay instproc cntr_update args { 1044 my instvar cntr cntr_val 1045 set cntr_val [expr {${cntr}/20000}] 1046 1047 } 1048 1049 # ------------------------------------------------------------------------- 1050 1051 CntDisplay instproc recs_update args { 1052 my instvar recs recs_val 1053 set recs_val [expr {${recs}*1}] 1054 } 1055 1056 # ------------------------------------------------------------------------- 1057 1058 CntDisplay instproc cntr_setup {} { 1059 my instvar controller cntr_val 1060 1061 set cntr_tmp [expr {${cntr_val} * 20000}] 1062 set word0 [format {%08x} [expr {${cntr_tmp} & 0xFFFFFFFF}]] 1063 set word1 [format {%08x} [expr {${cntr_tmp} >> 32}]] 1064 1065 set prefix [format {%x} 9] 1066 1067 set command {} 1068 append command 0001${prefix}000000200000004[string range $word0 4 7] 1069 append command 0001${prefix}000000200010004[string range $word0 0 3] 1070 append command 0001${prefix}000000200020004[string range $word1 4 7] 1071 append command 0001${prefix}000000200030004[string range $word1 0 3] 1072 1073 # send counter value 1074 $controller usbCmd $command 1075 } 1076 1077 # ------------------------------------------------------------------------- 1078 1079 CntDisplay instproc recs_setup {} { 1080 my instvar controller recs_val 1081 1082 set word0 [format {%08x} [expr {${recs_val} & 0xFFFFFFFF}]] 1083 set word1 [format {%08x} [expr {${recs_val} >> 32}]] 1084 1085 set prefix [format {%x} 10] 1086 1087 set command {} 1088 append command 0001${prefix}000000200000004[string range $word0 4 7] 1089 append command 0001${prefix}000000200010004[string range $word0 0 3] 1090 append command 0001${prefix}000000200020004[string range $word1 4 7] 1091 append command 0001${prefix}000000200030004[string range $word1 0 3] 1092 1093 # send counter value 1094 $controller usbCmd $command 1095 } 1096 1097 # ------------------------------------------------------------------------- 1098 1099 CntDisplay instproc cntr_reset {} { 1100 my instvar controller after_handle 1101 my instvar cntr_val cntr_bak recs_val recs_bak 1102 1103 my cntr_stop 1104 1105 set value [format {%04x} [expr {1 << 11}]] 1106 $controller usbCmd 000200000004${value}0002000000040000 1107 1108 my recs_stop 1109 } 1110 1111 # ------------------------------------------------------------------------- 1112 1113 CntDisplay instproc cntr_ready {} { 1114 my instvar config cntr_val cntr_bak recs_val recs_bak 1115 1116 set cntr_val $cntr_bak 1117 set recs_val $recs_bak 1118 1119 ${config}.start configure -text Start -command [myproc recs_start] 1120 ${config}.reset configure -state active 1121 1122 ${config}.start configure -state active 1123 ${config}.cntr_field configure -state normal 1124 ${config}.recs_field configure -state normal 1125 } 1126 1127 # ------------------------------------------------------------------------- 1128 1129 CntDisplay instproc recs_start {} { 1130 my instvar controller config auto 1131 my instvar cntr_val cntr_bak recs_val recs_bak 1132 1133 if {$cntr_val > 0 && $recs_val > 0} { 1134 ${config}.start configure -text {Stop} -command [myproc recs_stop] 1135 ${config}.cntr_field configure -state disabled 1136 ${config}.recs_field configure -state disabled 1137 1138 set cntr_bak $cntr_val 1139 set recs_bak $recs_val 1140 1141 my cntr_setup 1142 my recs_setup 1143 1144 set val_addr [format {%02x} 16] 1145 1146 $controller usbCmd 000200${val_addr}00040002 1147 1148 set auto 1 1149 1150 after 100 [myproc acquire_loop] 1151 } 1152 } 1153 1154 # ------------------------------------------------------------------------- 1155 1156 CntDisplay instproc recs_stop {} { 1157 my instvar cntr_val cntr_bak recs_val recs_bak 1158 1159 my cntr_stop 1160 1161 set cntr_val $cntr_bak 1162 my cntr_setup 1163 1164 set recs_val $recs_bak 1165 my recs_setup 1166 1167 my acquire 1168 1169 my cntr_ready 1170 } 1171 1172 # ------------------------------------------------------------------------- 1173 1174 CntDisplay instproc cntr_stop {} { 1175 my instvar controller config auto 1176 1177 set val_addr [format {%02x} 16] 1178 1179 $controller usbCmd 000200${val_addr}00040000 1180 1181 set auto 0 1182 } 1183 1184 # ------------------------------------------------------------------------- 1185 1186 CntDisplay instproc acquire_loop {} { 1187 my instvar recs_val auto 1188 1189 my acquire 1190 1191 if {$recs_val == 0} { 1192 my cntr_stop 1193 my cntr_ready 1194 } elseif {$auto} { 1195 after 1000 [myproc acquire_loop] 1196 } 1197 } 1198 1199 # ------------------------------------------------------------------------- 1200 1201 CntDisplay instproc data_update args { 1202 my instvar config data 1203 usb::convertBlt $data 2 [myvar yvec] 1204 1205 ${config}.chan_frame.mean_value configure \ 1206 -text [format {%.2e} [usb::integrateBlt [myvar yvec] 1]] 1207 ${config}.chan_frame.entr_value configure \ 1208 -text [usb::integrateBlt [myvar yvec] 0] 1209 1210 } 1211 1212 # ------------------------------------------------------------------------- 1213 1214 CntDisplay instproc axis_update args { 1215 my instvar axis graph 1216 if {$axis} { 1217 $graph axis configure y -min 1 -max 1E5 -logscale yes 1218 } else { 1219 $graph axis configure y -min {} -max {} -logscale no 1220 } 1221 } 1222 1223 # ------------------------------------------------------------------------- 1224 1225 CntDisplay instproc acquire {} { 1226 my instvar controller config 1227 my instvar cntr cntr_val recs recs_val 1228 1229 set size 16384 1230 1231 set prefix [format {%x} 8] 1232 1233 set value [format {%08x} $size] 1234 1235 set command 0001${prefix}000000200000001[string range $value 0 3]0003[string range $value 4 7]00050000 1236 1237 $controller usbCmdReadRaw $command [expr {$size * 2}] [myvar data] 1238 1239 set prefix [format {%x} 9] 1240 set command 0001${prefix}000000200000003000400050000 1241 1242 $controller usbCmdReadHex $command 8 1 [myvar cntr] 1243 1244 set prefix [format {%x} 10] 1245 set command 0001${prefix}000000200000003000400050000 1246 1247 $controller usbCmdReadHex $command 8 1 [myvar recs] 843 1248 } 844 1249 845 1250 # ------------------------------------------------------------------------- 846 1251 847 HstDisplay instproc restart {} { 848 my instvar number 849 my usbCmd 0001001${number} 850 } 851 852 # ------------------------------------------------------------------------- 853 854 HstDisplay instproc save_data {data} { 855 set file [tk_getSaveFile] 856 if {[string equal $file {}]} { 1252 CntDisplay instproc save_data {data} { 1253 1254 set types { 1255 {{Data Files} {.dat} } 1256 {{All Files} * } 1257 } 1258 1259 set stamp [clock format [clock seconds] -format %Y%m%d_%H%M%S] 1260 set fname counts_${stamp}.dat 1261 1262 set fname [tk_getSaveFile -filetypes $types -initialfile $fname] 1263 if {[string equal $fname {}]} { 857 1264 return 858 1265 } 859 1266 860 set x [catch {set fid [open $file w+]}] 861 set y [catch {puts $fid $data}] 862 set z [catch {close $fid}] 863 864 if { $x || $y || $z || ![file exists $file] || ![file isfile $file] || ![file readable $file] } { 1267 set x [catch { 1268 set fid [open $fname w+] 1269 puts $fid $data 1270 close $fid 1271 }] 1272 1273 if { $x || ![file exists $fname] || ![file isfile $fname] || ![file readable $fname] } { 865 1274 tk_messageBox -icon error \ 866 -message "An error occurred while writing to \"$f ile\""1275 -message "An error occurred while writing to \"$fname\"" 867 1276 } else { 868 1277 tk_messageBox -icon info \ 869 -message "File \"$file\" written successfully" 870 } 871 } 872 873 # ------------------------------------------------------------------------- 874 875 HstDisplay instproc register {} { 876 my save_data [my set data] 877 } 878 879 # ------------------------------------------------------------------------- 880 881 HstDisplay instproc acquire_loop {} { 882 my instvar number after_handle 883 884 my acquire 885 886 set after_handle [after 1000 [myproc acquire_loop]] 887 } 888 889 # ------------------------------------------------------------------------- 890 891 Class EptDisplay -superclass Display -parameter { 892 {number} 1278 -message "File \"$fname\" written successfully" 1279 } 1280 } 1281 1282 # ------------------------------------------------------------------------- 1283 1284 CntDisplay instproc register {} { 1285 my save_data [join [[myvar yvec] range 0 16383] \n] 1286 } 1287 1288 # ------------------------------------------------------------------------- 1289 1290 Class OscDisplay -parameter { 893 1291 {master} 894 } 895 896 # ------------------------------------------------------------------------- 897 898 EptDisplay instproc init {} { 899 my instvar data xvec yvec 900 901 set xvec [vector #auto] 902 903 for {set i 0} {$i < 11} {incr i} { 904 set yvec($i) [vector #auto] 1292 {controller} 1293 } 1294 1295 # ------------------------------------------------------------------------- 1296 1297 OscDisplay instproc init {} { 1298 my instvar sequence data xvec yvec 1299 1300 set data {} 1301 1302 set sequence 0 1303 1304 # set xvec [vector create #auto(262144)] 1305 set xvec [vector create #auto(10000)] 1306 1307 for {set i 1} {$i <= 9} {incr i} { 1308 # dict set yvec $i [vector create #auto(262144)] 1309 dict set yvec $i [vector create #auto(10000)] 905 1310 } 906 1311 907 1312 # fill one vector for the x axis 1313 # $xvec seq 0 262143 908 1314 $xvec seq 0 10000 909 1315 910 my reset911 912 1316 my setup 913 1317 … … 917 1321 # ------------------------------------------------------------------------- 918 1322 919 EptDisplay instproc destroy {} {1323 OscDisplay instproc destroy {} { 920 1324 next 921 1325 } … … 923 1327 # ------------------------------------------------------------------------- 924 1328 925 EptDisplay instproc reset {} { 926 my instvar data xvec yvec 927 my instvar number_val directory 928 929 set data {} 1329 OscDisplay instproc start {} { 1330 my instvar config 1331 my instvar recs_val directory 930 1332 931 1333 set directory $::env(HOMEPATH) 932 set number_val 10 933 934 for {set i 0} {$i < 11} {incr i} { 935 $yvec($i) set {} 936 } 937 } 938 939 # ------------------------------------------------------------------------- 940 941 EptDisplay instproc start {} { 1334 set recs_val 100 1335 1336 trace add variable [myvar chan] write [myproc chan_update] 1337 1338 trace add variable [myvar data] write [myproc data_update] 1339 1340 trace add variable [myvar auto] write [myproc auto_update] 1341 1342 trace add variable [myvar thrs] write [myproc thrs_update 0] 1343 trace add variable [myvar thrs_val] write [myproc thrs_update 0] 1344 1345 trace add variable [myvar recs_val] write [myproc recs_val_update] 1346 1347 trace add variable [myvar last] write [myproc last_update] 1348 1349 ${config}.chan_frame.chan1_check select 1350 ${config}.chan_frame.chan2_check select 1351 ${config}.chan_frame.chan3_check select 1352 ${config}.chan_frame.chan4_check select 1353 ${config}.chan_frame.chan5_check select 1354 ${config}.chan_frame.chan6_check select 1355 1356 ${config}.thrs_check select 1357 ${config}.thrs_field set 100 1358 } 1359 1360 # ------------------------------------------------------------------------- 1361 1362 OscDisplay instproc setup {} { 1363 my instvar master 1364 my instvar xvec yvec graph 942 1365 my instvar config 943 1366 944 trace add variable [myvar recs_val] write [myproc recs_val_update]945 trace add variable [myvar data] write [myproc data_update]946 trace add variable [myvar last] write [myproc data_update]947 948 }949 950 # -------------------------------------------------------------------------951 952 EptDisplay instproc setup {} {953 my instvar master954 my instvar data xvec yvec graph955 my instvar config number_val956 957 1367 # create a graph widget and show a grid 958 set display [frame ${master}.display] 959 960 set graph(0) [graph ${display}.graph0 -height 200 -leftmargin 80] 961 $graph(0) crosshairs configure -hide no -linewidth 2 -dashes { 1 1 } 962 $graph(0) grid configure -hide no 963 $graph(0) legend configure -hide yes 964 $graph(0) axis configure x -min 0 -max 10000 965 $graph(0) axis configure y -min 0 -max 4100 966 967 set graph(1) [graph ${display}.graph1 -height 200 -leftmargin 80] 968 $graph(1) crosshairs configure -hide no -linewidth 2 -dashes { 1 1 } 969 $graph(1) grid configure -hide no 970 $graph(1) legend configure -hide yes 971 $graph(1) axis configure x -min 0 -max 10000 -hide yes 972 $graph(1) axis configure y -min 0 -max 4100 973 974 set graph(2) [graph ${display}.graph2 -height 200 -leftmargin 80] 975 $graph(2) crosshairs configure -hide no -linewidth 2 -dashes { 1 1 } 976 $graph(2) grid configure -hide no 977 $graph(2) legend configure -hide yes 978 $graph(2) axis configure x -min 0 -max 10000 -hide yes 979 $graph(2) axis configure y -min 0 -max 4100 980 981 set graph(3) [graph ${display}.graph3 -height 100 -leftmargin 80] 982 $graph(3) crosshairs configure -hide no -linewidth 2 -dashes { 1 1 } 983 $graph(3) grid configure -hide no 984 $graph(3) legend configure -hide yes 985 $graph(3) axis configure x -min 0 -max 10000 -hide yes 986 $graph(3) axis configure y -min 0 -max 25 987 988 scale ${master}.last -orient horizontal -from 1 -to 35 -tickinterval 0 -showvalue no -variable [myvar last] 989 990 set config [frame ${master}.config -width 120] 991 992 label ${config}.recs -text {number of records} 993 spinbox ${config}.recs_field -from 5 -to 100 \ 994 -increment 5 -width 10 -textvariable [myvar recs_val] \ 995 -validate all -vcmd {::mca::validate 100 %P} 996 997 frame ${config}.spc1 -width 10 -height 10 998 999 button ${config}.sequence -text {Start Recording} \ 1000 -bg red -activebackground red -command [myproc sequence] 1001 1002 frame ${config}.spc2 -width 10 -height 10 1003 1004 label ${config}.stat -text {} 1005 1006 frame ${config}.spc3 -width 10 -height 20 1368 set graph [graph ${master}.graph -height 250 -leftmargin 80] 1369 $graph crosshairs configure -hide no -linewidth 1 -color darkblue -dashes {2 2} 1370 $graph grid configure -hide no 1371 $graph legend configure -hide yes 1372 $graph axis configure x -min 0 -max 10000 1373 $graph axis configure y -min 0 -max 4100 1374 1375 # scale ${master}.last -orient horizontal -from 1 -to 27 -tickinterval 0 -showvalue no -variable [myvar last] 1376 1377 set config [frame ${master}.config -width 170] 1378 1379 frame ${config}.chan_frame -width 170 1380 legendButton ${config}.chan_frame 0 chan1 {Channel 1} [myvar chan(1)] turquoise2 1381 legendButton ${config}.chan_frame 1 chan2 {Channel 2} [myvar chan(2)] SpringGreen2 1382 legendButton ${config}.chan_frame 2 chan3 {Channel 3} [myvar chan(3)] orchid2 1383 legendButton ${config}.chan_frame 3 chan4 {Channel 4} [myvar chan(4)] orange2 1384 legendButton ${config}.chan_frame 4 chan5 {Channel 5} [myvar chan(5)] blue1 white 1385 legendButton ${config}.chan_frame 5 chan6 {Channel 6} [myvar chan(6)] gray65 white 1386 legendLabel ${config}.chan_frame 6 axisx {Time axis} 1387 1388 frame ${config}.spc1 -width 170 -height 30 1389 1390 checkbutton ${config}.auto_check -text {auto update} -variable [myvar auto] 1391 1392 frame ${config}.spc2 -width 170 -height 30 1393 1394 checkbutton ${config}.thrs_check -text threshold -variable [myvar thrs] 1395 spinbox ${config}.thrs_field -from 1 -to 4095 \ 1396 -increment 5 -width 10 -textvariable [myvar thrs_val] \ 1397 -validate all -vcmd {::mca::validate 4095 4 %P} 1398 1399 frame ${config}.spc3 -width 170 -height 30 1007 1400 1008 1401 button ${config}.acquire -text Acquire \ 1009 -bg green -activebackground green -command [myproc acquire ]1402 -bg green -activebackground green -command [myproc acquire_start] 1010 1403 button ${config}.register -text Register \ 1011 1404 -bg lightblue -activebackground lightblue -command [myproc register] 1012 1405 1013 1014 grid ${config}.recs -sticky w -pady 1 -padx 3 1015 grid ${config}.recs_field -sticky ew -pady 1 -padx 5 1406 frame ${config}.spc4 -width 170 -height 30 1407 1408 label ${config}.recs -text {number of records} 1409 spinbox ${config}.recs_field -from 0 -to 10000 \ 1410 -increment 10 -width 10 -textvariable [myvar recs_val] \ 1411 -validate all -vcmd {::mca::validate 10000 5 %P} 1412 1413 frame ${config}.spc5 -width 170 -height 10 1414 1415 button ${config}.sequence -text {Start Recording} -command [myproc sequence_start] \ 1416 -bg yellow -activebackground yellow 1417 1418 frame ${config}.spc6 -width 170 -height 10 1419 1420 button ${config}.recover -text {Read file} \ 1421 -bg lightblue -activebackground lightblue -command [myproc recover] 1422 1423 grid ${config}.chan_frame -sticky ew 1016 1424 grid ${config}.spc1 1017 grid ${config}. sequence -sticky ew -pady 3 -padx 51425 grid ${config}.auto_check -sticky w 1018 1426 grid ${config}.spc2 1019 grid ${config}.stat -sticky w -pady 1 -padx 3 1427 grid ${config}.thrs_check -sticky w 1428 grid ${config}.thrs_field -sticky ew -pady 1 -padx 5 1020 1429 grid ${config}.spc3 1021 1430 grid ${config}.acquire -sticky ew -pady 3 -padx 5 1022 1431 grid ${config}.register -sticky ew -pady 3 -padx 5 1023 1024 grid ${graph(3)} -row 0 -column 0 -sticky news 1025 grid ${graph(2)} -row 1 -column 0 -sticky news 1026 grid ${graph(1)} -row 2 -column 0 -sticky news 1027 grid ${graph(0)} -row 3 -column 0 -sticky news 1028 1029 grid ${display} -row 0 -column 0 -sticky news 1432 grid ${config}.spc4 1433 grid ${config}.recs -sticky w -pady 1 -padx 3 1434 grid ${config}.recs_field -sticky ew -pady 1 -padx 5 1435 grid ${config}.spc5 1436 grid ${config}.sequence -sticky ew -pady 3 -padx 5 1437 grid ${config}.spc6 1438 grid ${config}.recover -sticky ew -pady 3 -padx 5 1439 1440 grid ${graph} -row 0 -column 0 -sticky news 1030 1441 grid ${config} -row 0 -column 1 1031 1442 1032 grid ${master}.last -row 1 -column 0 -columnspan 2 -sticky ew1443 # grid ${master}.last -row 1 -column 0 -columnspan 2 -sticky ew 1033 1444 1034 1445 grid rowconfigure ${master} 0 -weight 1 … … 1036 1447 grid columnconfigure ${master} 1 -weight 0 -minsize 120 1037 1448 1038 grid columnconfigure ${display} 0 -weight 1 1039 grid rowconfigure ${display} 0 -weight 1 1040 grid rowconfigure ${display} 1 -weight 1 1041 grid rowconfigure ${display} 2 -weight 1 1042 grid rowconfigure ${display} 3 -weight 1 1449 grid columnconfigure ${config}.chan_frame 2 -weight 1 1043 1450 1044 1451 # enable zooming 1045 Blt_ZoomStack $graph(0) 1046 Blt_ZoomStack $graph(1) 1047 Blt_ZoomStack $graph(2) 1048 Blt_ZoomStack $graph(3) 1049 1050 #bind .graph <Motion> {%W crosshairs configure -position @%x,%y} 1452 Blt_ZoomStack $graph 1453 1454 my crosshairs $graph 1051 1455 1052 1456 # create one element with data for the x and y axis, no dots 1053 $graph(0) element create Spectrum0 -symbol none -xdata $xvec -ydata $yvec(0) 1054 $graph(1) element create Spectrum1 -symbol none -xdata $xvec -ydata $yvec(1) 1055 $graph(2) element create Spectrum2 -symbol none -xdata $xvec -ydata $yvec(2) 1056 for {set i 3} {$i < 11} {incr i} { 1057 $graph(3) element create Spectrum$i -symbol none -xdata $xvec -ydata $yvec($i) 1058 } 1059 } 1060 1061 # ------------------------------------------------------------------------- 1062 1063 EptDisplay instproc recs_val_update args { 1457 $graph pen create pen1 -color turquoise3 -linewidth 2 -symbol none 1458 $graph pen create pen2 -color SpringGreen3 -linewidth 2 -symbol none 1459 $graph pen create pen3 -color orchid3 -linewidth 2 -symbol none 1460 $graph pen create pen4 -color orange3 -linewidth 2 -symbol none 1461 $graph pen create pen5 -color blue2 -linewidth 2 -symbol none 1462 $graph pen create pen6 -color gray55 -linewidth 2 -symbol none 1463 1464 $graph element create Spectrum1 -pen pen1 -xdata $xvec -ydata [dict get $yvec 1] 1465 $graph element create Spectrum2 -pen pen2 -xdata $xvec -ydata [dict get $yvec 2] 1466 $graph element create Spectrum3 -pen pen3 -xdata $xvec -ydata [dict get $yvec 3] 1467 $graph element create Spectrum4 -pen pen4 -xdata $xvec -ydata [dict get $yvec 4] 1468 $graph element create Spectrum5 -pen pen5 -xdata $xvec -ydata [dict get $yvec 5] 1469 $graph element create Spectrum6 -pen pen6 -xdata $xvec -ydata [dict get $yvec 6] 1470 } 1471 1472 # ------------------------------------------------------------------------- 1473 1474 OscDisplay instproc coor_update {W x y} { 1475 my instvar xvec yvec graph 1476 my instvar config 1477 1478 $W crosshairs configure -position @${x},${y} 1479 1480 set index [$W axis invtransform x $x] 1481 set index [::tcl::mathfunc::round $index] 1482 catch { 1483 ${config}.chan_frame.chan1_value configure -text [[dict get $yvec 1] index $index] 1484 ${config}.chan_frame.chan2_value configure -text [[dict get $yvec 2] index $index] 1485 ${config}.chan_frame.chan3_value configure -text [[dict get $yvec 3] index $index] 1486 ${config}.chan_frame.chan4_value configure -text [[dict get $yvec 4] index $index] 1487 ${config}.chan_frame.chan5_value configure -text [[dict get $yvec 5] index $index] 1488 ${config}.chan_frame.chan6_value configure -text [[dict get $yvec 6] index $index] 1489 ${config}.chan_frame.axisx_value configure -text ${index}.0 1490 } 1491 } 1492 # ------------------------------------------------------------------------- 1493 1494 OscDisplay instproc crosshairs {graph} { 1495 set method [myproc coor_update] 1496 bind $graph <Motion> [list [self] coor_update %W %x %y] 1497 bind $graph <Leave> { 1498 %W crosshairs off 1499 } 1500 bind $graph <Enter> { 1501 %W crosshairs on 1502 } 1503 } 1504 1505 # ------------------------------------------------------------------------- 1506 1507 OscDisplay instproc chan_update {name key op} { 1508 my instvar config graph chan 1509 1510 if {$chan(${key})} { 1511 $graph pen configure pen${key} -linewidth 2 1512 } else { 1513 $graph pen configure pen${key} -linewidth 0 1514 } 1515 } 1516 1517 # ------------------------------------------------------------------------- 1518 1519 OscDisplay instproc recs_val_update args { 1064 1520 my instvar recs_val 1065 1521 if {[string equal $recs_val {}]} { 1066 set number_val 01067 } 1068 } 1069 1070 # ------------------------------------------------------------------------- 1071 1072 EptDisplay instproc data_update args {1073 my instvar data xvec yvecgraph last1522 set recs_val 0 1523 } 1524 } 1525 1526 # ------------------------------------------------------------------------- 1527 1528 OscDisplay instproc last_update args { 1529 my instvar graph last 1074 1530 1075 1531 set first [expr {$last - 1}] 1532 1533 $graph axis configure x -min ${first}0000 -max ${last}0000 1534 } 1535 1536 # ------------------------------------------------------------------------- 1537 1538 OscDisplay instproc thrs_update {reset args} { 1539 my instvar controller config thrs thrs_val 1540 1541 if {[string equal $thrs_val {}]} { 1542 set thrs_val 0 1543 } 1544 1545 if {$thrs} { 1546 ${config}.thrs_field configure -state normal 1547 set value [format %03x $thrs_val] 1548 } else { 1549 ${config}.thrs_field configure -state disabled 1550 set value 000 1551 } 1552 1553 set command {} 1554 if {$reset} { 1555 append command 0002000500041${value} 1556 } 1557 append command 0002000500040${value} 1558 1559 $controller usbCmd $command 1560 } 1561 1562 # ------------------------------------------------------------------------- 1563 1564 OscDisplay instproc data_update args { 1565 my instvar data yvec 1566 my instvar graph chan waiting sequence auto 1567 1568 usb::convertOsc $data $yvec 1569 1570 foreach {key value} [array get chan] { 1571 $graph pen configure pen${key} -dashes 0 1572 } 1573 1574 set waiting 0 1575 1576 if {$sequence} { 1577 my sequence_register 1578 } elseif {$auto} { 1579 after 1000 [myproc acquire_start] 1580 } 1581 } 1582 1583 # ------------------------------------------------------------------------- 1584 1585 OscDisplay instproc acquire_start {} { 1586 my instvar graph chan controller waiting 1587 1588 foreach {key value} [array get chan] { 1589 $graph pen configure pen${key} -dashes dot 1590 } 1591 1592 # restart 1593 my thrs_update 1 1594 1595 set waiting 1 1596 1597 after 200 [myproc acquire_loop] 1598 } 1599 1600 # ------------------------------------------------------------------------- 1601 1602 OscDisplay instproc acquire_loop {} { 1603 my instvar controller waiting 1604 1605 # set size 262144 1606 set size 10000 1607 1608 set value [format {%08x} [expr {$size * 4}]] 1609 1610 set command 00011000000200000001[string range $value 0 3]0003[string range $value 4 7]00050000 1076 1611 1077 $xvec seq ${first}0000 ${last}0000 1078 for {set i 0} {$i < 4} {incr i} { 1079 $graph($i) axis configure x -min ${first}0000 -max ${last}0000 1080 } 1081 1082 for {set i 0} {$i < 11} {incr i} { 1083 $yvec($i) set [lrange [lindex $data $i] ${first}0000 ${last}0000] 1084 } 1085 } 1086 1087 1088 # ------------------------------------------------------------------------- 1089 1090 EptDisplay instproc save_data {data} { 1091 set file [tk_getSaveFile] 1092 if {[string equal $file {}]} { 1612 $controller usbCmdReadRaw $command [expr {$size * 8}] [myvar data] 1613 1614 if {$waiting} { 1615 after 200 [myproc acquire_loop] 1616 } 1617 } 1618 1619 # ------------------------------------------------------------------------- 1620 1621 OscDisplay instproc auto_update args { 1622 my instvar config auto 1623 1624 if {$auto} { 1625 ${config}.recs_field configure -state disabled 1626 ${config}.sequence configure -state disabled 1627 ${config}.acquire configure -state disabled 1628 ${config}.register configure -state disabled 1629 ${config}.recover configure -state disabled 1630 1631 my acquire_start 1632 } else { 1633 ${config}.recs_field configure -state normal 1634 ${config}.sequence configure -state active 1635 ${config}.acquire configure -state active 1636 ${config}.register configure -state active 1637 ${config}.recover configure -state active 1638 } 1639 } 1640 1641 # ------------------------------------------------------------------------- 1642 1643 OscDisplay instproc save_data {fname} { 1644 my instvar data 1645 1646 set fid [open $fname w+] 1647 fconfigure $fid -translation binary -encoding binary 1648 1649 # puts -nonewline $fid [binary format "H*iH*" "1f8b0800" [clock seconds] "0003"] 1650 # puts -nonewline $fid [zlib deflate $data] 1651 puts -nonewline $fid $data 1652 # puts -nonewline $fid [binary format i [zlib crc32 $data]] 1653 # puts -nonewline $fid [binary format i [string length $data]] 1654 1655 close $fid 1656 } 1657 1658 # ------------------------------------------------------------------------- 1659 1660 OscDisplay instproc open_data {} { 1661 set types { 1662 {{Data Files} {.dat} } 1663 {{All Files} * } 1664 } 1665 1666 set fname [tk_getOpenFile -filetypes $types] 1667 if {[string equal $fname {}]} { 1093 1668 return 1094 1669 } 1095 1670 1096 set x [catch {set fid [open $file w+]}] 1097 set y [catch {puts $fid $data}] 1098 set z [catch {close $fid}] 1099 1100 if { $x || $y || $z || ![file exists $file] || ![file isfile $file] || ![file readable $file] } { 1671 set x [catch { 1672 set fid [open $fname r+] 1673 fconfigure $fid -translation binary -encoding binary 1674 # set size [file size $fname] 1675 # seek $fid 10 1676 # my set data [zlib inflate [read $fid [expr {$size - 18}]]] 1677 my set data [read $fid] 1678 close $fid 1679 }] 1680 1681 if { $x || ![file exists $fname] || ![file isfile $fname] || ![file readable $fname] } { 1101 1682 tk_messageBox -icon error \ 1102 -message "An error occurred while writing to \"$file\""1683 -message "An error occurred while reading \"$fname\"" 1103 1684 } else { 1104 1685 tk_messageBox -icon info \ 1105 -message "File \"$file\" written successfully" 1106 } 1107 } 1108 1109 # ------------------------------------------------------------------------- 1110 1111 EptDisplay instproc acquire {} { 1112 my usbCmdReadEpt 00060000 2097152 1113 } 1114 1115 # ------------------------------------------------------------------------- 1116 1117 EptDisplay instproc register {} { 1118 my save_data [my set data] 1119 } 1120 1121 # ------------------------------------------------------------------------- 1122 1123 EptDisplay instproc sequence {} { 1124 my instvar config recs_val directory counter 1686 -message "File \"$fname\" read successfully" 1687 } 1688 } 1689 1690 # ------------------------------------------------------------------------- 1691 1692 OscDisplay instproc register {} { 1693 set types { 1694 {{Data Files} {.dat} } 1695 {{All Files} * } 1696 } 1697 1698 set stamp [clock format [clock seconds] -format %Y%m%d_%H%M%S] 1699 set fname oscillogram_${stamp}.dat 1700 1701 set fname [tk_getSaveFile -filetypes $types -initialfile $fname] 1702 if {[string equal $fname {}]} { 1703 return 1704 } 1705 1706 if {[catch {my save_data $fname} result]} { 1707 tk_messageBox -icon error \ 1708 -message "An error occurred while writing to \"$fname\"" 1709 } else { 1710 tk_messageBox -icon info \ 1711 -message "File \"$fname\" written successfully" 1712 } 1713 } 1714 1715 # ------------------------------------------------------------------------- 1716 1717 OscDisplay instproc recover {} { 1718 my open_data 1719 } 1720 1721 # ------------------------------------------------------------------------- 1722 1723 OscDisplay instproc sequence_start {} { 1724 my instvar config recs_val recs_bak directory counter sequence 1725 1726 set counter 1 1727 if {$counter > $recs_val} { 1728 return 1729 } 1125 1730 1126 1731 set directory [tk_chooseDirectory -initialdir $directory -title {Choose a directory}] … … 1131 1736 1132 1737 ${config}.recs_field configure -state disabled 1133 ${config}.sequence configure - state disabled1738 ${config}.sequence configure -text {Stop Recording} -command [myproc sequence_stop] 1134 1739 ${config}.acquire configure -state disabled 1135 1740 ${config}.register configure -state disabled 1741 ${config}.recover configure -state disabled 1136 1742 1137 set counter 1 1743 set recs_bak $recs_val 1744 1745 set sequence 1 1746 1747 my acquire_start 1748 } 1749 1750 # ------------------------------------------------------------------------- 1751 1752 OscDisplay instproc sequence_register {} { 1753 my instvar config recs_val recs_bak directory counter 1754 1755 set fname [file join $directory oscillogram_$counter.dat] 1756 1757 my incr counter 1758 1759 if {[catch {my save_data $fname} result]} { 1760 tk_messageBox -icon error \ 1761 -message "An error occurred while writing to \"$fname\"" 1762 } elseif {$counter <= $recs_bak} { 1763 set recs_val [expr {$recs_bak - $counter}] 1764 my acquire_start 1765 return 1766 } 1138 1767 1139 if {$counter <= $recs_val} { 1140 ${config}.stat configure -text "record $counter of $recs_val" 1141 set after_handle [after 100 [myproc acquire_register_loop]] 1142 } 1143 } 1144 1145 # ------------------------------------------------------------------------- 1146 1147 EptDisplay instproc acquire_register_loop {} { 1148 my instvar after_handle 1149 my instvar config data recs_val directory counter 1150 1151 my acquire 1152 1153 set file [file join $directory ept_$counter.dat.gz] 1154 1155 set x [catch {set fid [open $file w+]}] 1156 fconfigure $fid -translation binary -encoding binary 1157 1158 set y [catch { 1159 puts -nonewline $fid [binary format "H*iH*" "1f8b0800" [clock seconds] "0003"] 1160 puts -nonewline $fid [zlib deflate $data] 1161 puts -nonewline $fid [binary format i [zlib crc32 $data]] 1162 puts -nonewline $fid [binary format i [string length $data]] 1163 }] 1164 1165 set z [catch {close $fid}] 1166 1167 my incr counter 1168 1169 if { $x || $y || $z || ![file exists $file] || ![file isfile $file] || ![file readable $file] } { 1170 tk_messageBox -icon error -message "An error occurred while writing to \"$file\"" 1171 } elseif {$counter <= $recs_val} { 1172 ${config}.stat configure -text "record $counter of $recs_val" 1173 set after_handle [after 100 [myproc acquire_register_loop]] 1174 return 1175 } 1768 my sequence_stop 1769 } 1770 1771 # ------------------------------------------------------------------------- 1772 1773 OscDisplay instproc sequence_stop {} { 1774 my instvar config recs_val recs_bak sequence 1775 1776 set sequence 0 1176 1777 1177 ${config}.stat configure -text {} 1778 set recs_val $recs_bak 1779 1178 1780 ${config}.recs_field configure -state normal 1179 ${config}.sequence configure - state active1781 ${config}.sequence configure -text {Start Recording} -command [myproc sequence_start] 1180 1782 ${config}.acquire configure -state active 1181 1783 ${config}.register configure -state active 1182 1183 } 1184 1185 # ------------------------------------------------------------------------- 1186 1187 Class MemDisplay -superclass Display -parameter { 1188 {number} 1189 {master} 1190 } 1191 1192 # ------------------------------------------------------------------------- 1193 1194 MemDisplay instproc init {} { 1195 my instvar data xvec yvec 1196 1197 set xvec [vector #auto] 1198 set yvec [vector #auto] 1199 1200 # fill one vector for the x axis 1201 $xvec seq 0 10000 1202 1203 my reset 1204 1205 my setup 1206 1207 next 1208 } 1209 1210 # ------------------------------------------------------------------------- 1211 1212 MemDisplay instproc destroy {} { 1213 next 1214 } 1215 1216 # ------------------------------------------------------------------------- 1217 1218 MemDisplay instproc reset {} { 1219 my instvar data xvec yvec 1220 1221 set data {} 1222 1223 $yvec set {} 1224 } 1225 1226 # ------------------------------------------------------------------------- 1227 1228 MemDisplay instproc start {} { 1229 my instvar config 1230 1231 trace add variable [myvar data] write [myproc data_update] 1232 trace add variable [myvar last] write [myproc data_update] 1233 } 1234 1235 # ------------------------------------------------------------------------- 1236 1237 MemDisplay instproc setup {} { 1238 my instvar master 1239 my instvar data xvec yvec 1240 my instvar config auto thrs thrs_val disp_val trig_val 1241 1242 # create a graph widget and show a grid 1243 set graph [graph ${master}.graph -height 250 -leftmargin 80] 1244 $graph crosshairs configure -hide no -linewidth 2 -dashes { 1 1 } 1245 $graph grid configure -hide no 1246 $graph legend configure -hide yes 1247 $graph axis configure x -min 0 -max 10000 1248 # $graph axis configure y -min 0 -max 4100 1249 1250 scale ${master}.last -orient horizontal -from 1 -to 105 -tickinterval 0 -variable [myvar last] 1251 1252 set config [frame ${master}.config] 1253 1254 button ${config}.acquire -text Acquire \ 1255 -bg green -activebackground green -command [myproc acquire] 1256 button ${config}.register -text Register \ 1257 -bg lightblue -activebackground lightblue -command [myproc register] 1258 1259 grid ${config}.acquire -sticky ew -pady 3 -padx 5 1260 grid ${config}.register -sticky ew -pady 3 -padx 5 1261 1262 grid ${graph} -row 0 -column 0 -sticky news 1263 grid ${config} -row 0 -column 1 1264 1265 grid ${master}.last -row 1 -column 0 -columnspan 2 -sticky ew 1266 1267 grid rowconfigure ${master} 0 -weight 1 1268 grid columnconfigure ${master} 0 -weight 1 1269 grid columnconfigure ${master} 1 -weight 0 -minsize 80 1270 1271 # enable zooming 1272 Blt_ZoomStack $graph 1273 1274 #bind .graph <Motion> {%W crosshairs configure -position @%x,%y} 1275 1276 # create one element with data for the x and y axis, no dots 1277 $graph element create Spectrum -symbol none -xdata $xvec -ydata $yvec 1278 } 1279 1280 # ------------------------------------------------------------------------- 1281 1282 MemDisplay instproc data_update args { 1283 my instvar data yvec last 1284 1285 set first [expr {$last - 1}] 1286 $yvec set [lrange $data ${first}0000 ${last}0000] 1287 } 1288 1289 # ------------------------------------------------------------------------- 1290 1291 MemDisplay instproc save_data {data} { 1292 set file [tk_getSaveFile] 1293 if {[string equal $file {}]} { 1294 return 1295 } 1296 1297 set x [catch {set fid [open $file w+]}] 1298 set y [catch {puts $fid $data}] 1299 set z [catch {close $fid}] 1300 1301 if { $x || $y || $z || ![file exists $file] || ![file isfile $file] || ![file readable $file] } { 1302 tk_messageBox -icon error \ 1303 -message "An error occurred while writing to \"$file\"" 1304 } else { 1305 tk_messageBox -icon info \ 1306 -message "File \"$file\" written successfully" 1307 } 1308 } 1309 1310 # ------------------------------------------------------------------------- 1311 1312 MemDisplay instproc acquire {} { 1313 my usbCmdRead 00040000 1 524288 1314 # my usbCmdRead 00060000 1 1048576 1315 } 1316 1317 # ------------------------------------------------------------------------- 1318 1319 MemDisplay instproc register {} { 1320 my save_data [my set data] 1321 } 1322 1323 # ------------------------------------------------------------------------- 1324 1325 namespace export MemDisplay 1326 namespace export EptDisplay 1784 ${config}.recover configure -state active 1785 } 1786 1787 # ------------------------------------------------------------------------- 1788 1789 namespace export MuxDisplay 1327 1790 namespace export HstDisplay 1791 namespace export CntDisplay 1328 1792 namespace export OscDisplay 1329 namespace export CfgDisplay1330 1793 } 1331 1794 1332 set config [frame .config]1333 1795 set notebook [::blt::tabnotebook .notebook -borderwidth 1 -selectforeground black -side bottom] 1334 1796 1335 grid ${config} -row 0 -column 0 -sticky ns -padx 3 1336 grid ${notebook} -row 0 -column 1 -sticky news -pady 5 1797 grid ${notebook} -row 0 -column 0 -sticky news -pady 5 1337 1798 1338 1799 grid rowconfigure . 0 -weight 1 1339 grid columnconfigure . 0 -weight 0 -minsize 50 1340 grid columnconfigure . 1 -weight 1 1341 1342 foreach i {0 1 2} { 1343 set channel [expr $i + 1] 1344 1345 set window [frame ${notebook}.hst_$i] 1346 $notebook insert end -text "Histogram $channel" -window $window -fill both 1347 ::mca::HstDisplay hst_$i -number $i -master $window 1348 1349 set window [frame ${notebook}.osc_$i] 1350 $notebook insert end -text "Pulse shape $channel" -window $window -fill both 1351 ::mca::OscDisplay osc_$i -number $i -master $window 1352 } 1353 1354 #set window [frame ${notebook}.cfg] 1355 #$notebook insert end -text "Configuration" -window $window -fill both 1356 ::mca::CfgDisplay cfg -master $config 1800 grid columnconfigure . 0 -weight 1 1801 1802 ::mca::UsbController usb 1803 1804 set window [frame ${notebook}.hst_0] 1805 $notebook insert end -text "Spectrum histogram" -window $window -fill both 1806 ::mca::HstDisplay hst_0 -number 0 -master $window -controller usb 1807 1808 set window [frame ${notebook}.cnt_0] 1809 $notebook insert end -text "Rate histogram" -window $window -fill both 1810 ::mca::CntDisplay cnt_0 -master $window -controller usb 1811 1812 set window [frame ${notebook}.mux] 1813 $notebook insert end -text "Interconnect" -window $window -fill both 1814 ::mca::MuxDisplay mux -master $window -controller usb 1357 1815 1358 1816 set window [frame ${notebook}.ept] 1359 $notebook insert end -text "EPT" -window $window -fill both 1360 ::mca::EptDisplay ept -master $window 1361 1362 #set window [frame ${notebook}.mem] 1363 #$notebook insert end -text "Memory test" -window $window -fill both 1364 #::mca::MemDisplay mem -master $window 1365 1366 set usb_handle {} 1367 1368 while {[catch {usb::connect 0x09FB 0x6001 1 1 0} usb_handle]} { 1369 set answer [tk_messageBox -icon error -type retrycancel \ 1370 -message {Cannot access USB device} -detail $usb_handle] 1371 if {[string equal $answer cancel]} break 1372 } 1373 1374 # cfg reset 1375 cfg reset 1376 1377 cfg start 1378 1379 foreach i {0 1 2} { 1380 hst_$i start 1381 osc_$i start 1382 1383 hst_$i restart 1384 osc_$i restart 1385 } 1386 1387 ept start 1388 #mem start 1817 $notebook insert end -text "Oscilloscope" -window $window -fill both 1818 ::mca::OscDisplay osc -master $window -controller usb 1819 1820 update 1821 1822 usb usbCmd 00000000 1823 1824 hst_0 start 1825 1826 cnt_0 start 1827 1828 mux start 1829 1830 osc start -
trunk/MultiChannelUSB/adc_lvds.v
r98 r159 1 2 (* ALTERA_ATTRIBUTE = {"{-to int_data_p} DDIO_INPUT_REGISTER=HIGH; {-to int_data_n} DDIO_INPUT_REGISTER=LOW"} *) 3 1 4 module adc_lvds 2 5 #( … … 5 8 ) 6 9 ( 10 input wire clock, 11 7 12 input wire lvds_dco, 8 13 input wire lvds_fco, 9 14 input wire [size-1:0] lvds_d, 10 15 11 output wire [size*width-1:0] adc_data 16 input wire [1:0] trig, 17 18 output wire adc_frame, 19 output wire [size*width-1+2:0] adc_data 20 12 21 ); 22 localparam width2 = width + 2; 23 13 24 14 wire [size-1:0] int_data_h, int_data_l; 15 reg [width-1:0] int_data_next [size-1:0]; 16 // reg [2*width:0] int_data_next [size-1:0]; 17 reg [width-1:0] int_data_reg [size-1:0]; 18 // reg [2*width:0] int_data_reg [size-1:0]; 25 reg state, int_rdreq, adc_frame_reg; 26 wire int_wrfull, int_rdempty; 19 27 20 reg [width-1:0] int_adc_data [size-1:0];28 reg [size-1:0] int_data_p, int_data_n; 21 29 22 integer i; 30 reg [2:0] int_edge_reg; 31 32 reg [size*width-1:0] int_fifo_reg; 33 wire [size*width-1:0] int_fifo_wire; 34 35 reg [size*width2-1:0] int_data_reg; 36 wire [size*width2-1:0] int_data_wire; 37 38 wire [size*width-1+2:0] int_q_wire; 39 reg [size*width-1+2:0] adc_data_reg; 40 41 42 23 43 genvar j; 24 44 25 altddio_in #( 45 generate 46 for (j = 0; j < size; j = j + 1) 47 begin : INT_DATA 48 // MSB first 49 // assign int_data_wire[j*width+width-1:j*width] = {int_data_reg[j*width+width-3:j*width], int_data_p[j], int_data_n[j]}; 50 // LSB first 51 // assign int_data_wire[j*width+width-1:j*width] = {int_data_n[j], int_data_p[j], int_data_reg[j*width+width-1:j*width+2]}; 52 53 assign int_data_wire[j*width2+width2-1:j*width2] = {int_data_reg[j*width2+width2-3:j*width2], int_data_p[j], int_data_n[j]}; 54 assign int_fifo_wire[j*width+width-1:j*width] = int_data_reg[j*width2+width2-1:j*width2+2]; 55 // assign int_data_wire[j*width2+width2-1:j*width2] = {int_data_n[j], int_data_p[j], int_data_reg[j*width2+width2-1:j*width2+2]}; 56 // assign int_fifo_wire[j*width+width-1:j*width] = int_data_reg[j*width2+width2-3:j*width2]; 57 end 58 endgenerate 59 60 61 dcfifo #( 26 62 .intended_device_family("Cyclone III"), 27 .invert_input_clocks("ON"), 28 // .invert_input_clocks("OFF"), 29 .lpm_type("altddio_in"), 30 .width(size)) altddio_in_unit ( 31 .datain(lvds_d), 32 .inclock(lvds_dco), 33 .aclr(1'b0), 34 .dataout_h(int_data_h), 35 .dataout_l(int_data_l), 36 .aset(1'b0), 37 .inclocken(1'b1), 38 .sclr(1'b0), 39 .sset(1'b0)); 63 .lpm_numwords(16), 64 .lpm_showahead("ON"), 65 .lpm_type("dcfifo"), 66 .lpm_width(size*width+2), 67 .lpm_widthu(4), 68 .rdsync_delaypipe(4), 69 .wrsync_delaypipe(4), 70 .overflow_checking("ON"), 71 .underflow_checking("ON"), 72 .use_eab("ON")) fifo_unit ( 73 // .data(int_data_wire), 74 .data({trig, int_fifo_reg}), 75 .rdclk(clock), 76 .rdreq((~int_rdempty) & int_rdreq), 77 .wrclk(lvds_fco), 78 .wrreq(~int_wrfull), 79 .q(int_q_wire), 80 .rdempty(int_rdempty), 81 .wrfull(int_wrfull), 82 .aclr(), 83 .rdfull(), 84 .rdusedw(), 85 .wrempty(), 86 .wrusedw()); 87 88 always @ (posedge clock) 89 begin 90 case (state) 91 1'b0: 92 begin 93 int_rdreq <= 1'b1; 94 adc_frame_reg <= 1'b0; 95 state <= 1'b1; 96 end 97 98 1'b1: 99 begin 100 if (~int_rdempty) 101 begin 102 int_rdreq <= 1'b0; 103 adc_frame_reg <= 1'b1; 104 adc_data_reg <= int_q_wire; 105 state <= 1'b0; 106 end 107 end 108 endcase 109 end 110 111 always @ (negedge lvds_dco) 112 begin 113 int_data_n <= lvds_d; 114 end 40 115 41 116 always @ (posedge lvds_dco) 42 117 begin 43 for (i = 0; i < size; i = i + 1) 118 int_data_p <= lvds_d; 119 int_data_reg <= int_data_wire; 120 int_edge_reg <= {(~int_edge_reg[1]), int_edge_reg[0], lvds_fco}; 121 if (int_edge_reg[1] & int_edge_reg[2]) 44 122 begin 45 int_ data_reg[i] <= int_data_next[i];123 int_fifo_reg <= int_fifo_wire; 46 124 end 47 125 end 48 126 49 always @ (posedge lvds_fco) 50 begin 51 for (i = 0; i < size; i = i + 1) 52 begin 53 int_adc_data[i] <= int_data_next[i]; 54 // int_data_next[i] = {int_data_reg[i][2*width-2:0], int_data_l[i], int_data_h[i]}; 55 end 56 end 57 58 always @* 59 begin 60 for (i = 0; i < size; i = i + 1) 61 begin 62 int_data_next[i] = {int_data_reg[i][width-3:0], int_data_l[i], int_data_h[i]}; 63 // int_data_next[i] = {int_data_reg[i][2*width-2:0], int_data_l[i], int_data_h[i]}; 64 end 65 end 66 67 generate 68 for (j = 0; j < size; j = j + 1) 69 begin : ADC_LVDS_OUTPUT 70 assign adc_data[j*width+width-1:j*width] = int_adc_data[j]; 71 end 72 endgenerate 127 assign adc_frame = adc_frame_reg; 128 assign adc_data = adc_data_reg; 73 129 74 130 endmodule -
trunk/MultiChannelUSB/configuration.v
r99 r159 4 4 5 5 input wire bus_ssel, bus_wren, 6 input wire [ 4:0] bus_addr,6 input wire [5:0] bus_addr, 7 7 input wire [15:0] bus_mosi, 8 8 … … 10 10 output wire bus_busy, 11 11 12 output wire [ 511:0] cfg_bits12 output wire [1023:0] cfg_bits 13 13 ); 14 14 15 wire [ 31:0] int_ssel_wire;15 wire [63:0] int_ssel_wire; 16 16 wire [15:0] int_miso_wire; 17 17 reg [15:0] int_miso_reg; 18 18 19 wire [ 511:0] int_bits_wire;19 wire [1023:0] int_bits_wire; 20 20 21 21 integer i; … … 23 23 24 24 generate 25 for (j = 0; j < 32; j = j + 1)25 for (j = 0; j < 64; j = j + 1) 26 26 begin : BUS_OUTPUT 27 27 lpm_ff #( … … 43 43 44 44 lpm_mux #( 45 .lpm_size( 32),45 .lpm_size(64), 46 46 .lpm_type("LPM_MUX"), 47 47 .lpm_width(16), 48 .lpm_widths( 5)) bus_miso_mux_unit (48 .lpm_widths(6)) bus_miso_mux_unit ( 49 49 .sel(bus_addr), 50 50 .data(int_bits_wire), … … 53 53 54 54 lpm_decode #( 55 .lpm_decodes( 32),55 .lpm_decodes(64), 56 56 .lpm_type("LPM_DECODE"), 57 .lpm_width( 5)) lpm_decode_unit (57 .lpm_width(6)) lpm_decode_unit ( 58 58 .data(bus_addr), 59 59 .eq(int_ssel_wire), -
trunk/MultiChannelUSB/counter.v
r94 r159 1 1 module counter 2 2 ( 3 input wire clock, frame, reset,3 input wire clock, frame, 4 4 5 input wire [15:0] cfg_data,5 input wire reset, setup, count, 6 6 7 7 input wire bus_ssel, bus_wren, … … 23 23 wire [63:0] reg_bits_wire; 24 24 wire [63:0] cnt_bits_wire; 25 26 reg int_load_reg; 25 27 26 28 integer i; … … 32 34 .lpm_type("LPM_COUNTER"), 33 35 .lpm_width(64)) lpm_counter_component ( 34 .sload( cfg_data[0]),36 .sload(int_load_reg | setup), 35 37 .sclr(reset), 36 38 .clock(clock), 37 39 .data(reg_bits_wire), 38 // .cnt_en(frame & cfg_data[1]), 39 .cnt_en((frame) & (|cnt_bits_wire) & (cfg_data[1])), 40 .q(cnt_bits_wire), 41 .aclr(1'b0), 42 .aload(1'b0), 43 .aset(1'b0), 44 .cin(1'b1), 45 .clk_en(1'b1), 46 .cout(), 47 .eq(), 48 .sset(1'b0), 49 .updown(1'b1)); 40 .cnt_en((frame) & (count) & (|cnt_bits_wire)), 41 .q(cnt_bits_wire)); 50 42 51 43 generate … … 60 52 .clock(clock), 61 53 .data(bus_mosi), 62 .q(reg_bits_wire[j*16+15:j*16]), 63 .aclr(), 64 .aload(), 65 .aset(), 66 .sload(), 67 .sset()); 54 .q(reg_bits_wire[j*16+15:j*16])); 68 55 end 69 56 endgenerate … … 84 71 .lpm_width(2)) lpm_decode_unit ( 85 72 .data(bus_addr), 86 .eq(int_ssel_wire), 87 .aclr(), 88 .clken(), 89 .clock(), 90 .enable()); 73 .eq(int_ssel_wire)); 91 74 92 75 always @(posedge clock) … … 96 79 int_miso_reg <= 16'd0; 97 80 cnt_good_reg <= 1'b0; 81 int_load_reg <= 1'b0; 98 82 end 99 83 else 100 84 begin 101 85 int_miso_reg <= int_miso_wire; 102 cnt_good_reg <= (|cnt_bits_wire) & (cfg_data[1]); 86 cnt_good_reg <= |cnt_bits_wire; 87 int_load_reg <= bus_ssel & bus_wren; 103 88 end 104 89 end -
trunk/MultiChannelUSB/oscilloscope.v
r103 r159 130 130 if (bus_ssel) 131 131 begin 132 bus_miso_next = {ram_data[17:10], ram_data[8:1]};132 bus_miso_next = ram_data[15:0]; 133 133 ram_wren_next[0] = bus_wren; 134 134 if (bus_wren) 135 135 begin 136 136 ram_addr_next = bus_addr; 137 ram_data_next[0] = { bus_mosi[15:8], 1'b0, bus_mosi[7:0], 1'b0};137 ram_data_next[0] = {2'd0, bus_mosi[15:0]}; 138 138 end 139 139 else … … 183 183 ram_addr_next = ram_addr_reg + 20'd1; 184 184 ram_wren_next[0] = 1'b1; 185 ram_data_next[0] = { osc_data[15:8], 1'b0, osc_data[7:0], 1'b0};185 ram_data_next[0] = {2'd0, osc_data[15:0]}; 186 186 187 187 int_case_next = 3'd3; … … 211 211 ram_addr_next = ram_addr_reg + 20'd1; 212 212 ram_wren_next[0] = 1'b1; 213 ram_data_next[0] = { osc_data_reg[31:24], 1'b0, osc_data_reg[23:16], 1'b0};213 ram_data_next[0] = {2'd0, osc_data_reg[31:16]}; 214 214 int_case_next = 3'd4; 215 215 end … … 219 219 ram_addr_next = ram_addr_reg + 20'd1; 220 220 ram_wren_next[0] = 1'b1; 221 ram_data_next[0] = { osc_data_reg[47:40], 1'b0, osc_data_reg[39:32], 1'b0};221 ram_data_next[0] = {2'd0, osc_data_reg[47:32]}; 222 222 int_case_next = 3'd5; 223 223 end … … 227 227 ram_addr_next = ram_addr_reg + 20'd1; 228 228 ram_wren_next[0] = 1'b1; 229 ram_data_next[0] = { osc_data_reg[63:56], 1'b0, osc_data_reg[55:48], 1'b0};229 ram_data_next[0] = {2'd0, osc_data_reg[63:48]}; 230 230 if (|int_cntr_reg[0]) 231 231 begin -
trunk/MultiChannelUSB/usb_fifo.v
r104 r159 5 5 input wire usb_full, usb_empty, 6 6 output wire usb_wrreq, usb_rdreq, usb_rden, usb_pktend, 7 output wire [1:0]usb_addr,7 output wire usb_addr, 8 8 9 9 input wire clock, … … 116 116 assign usb_wrreq = int_wrreq; 117 117 assign usb_rden = int_rdreq; 118 assign usb_addr = {1'b1, ~rx_ready};118 assign usb_addr = rx_ready; 119 119 assign usb_data = int_wrreq ? int_tx_q : 8'bz; 120 120
Note:
See TracChangeset
for help on using the changeset viewer.