Ignore:
Timestamp:
Jan 15, 2014, 1:30:27 AM (11 years ago)
Author:
demin
Message:

add classifier and remove unneeded modules

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/3DEES/UserInterface.tcl

    r143 r180  
    3838        5 {ADC 5}
    3939        6 {ADC 6}
    40         7 {ADC 7}
    41         8 {ADC 8}
    42         9 {ADC 9}
    43        10 {ADC 10}
    44        11 {ADC 11}
    45        12 {ADC 12}
    4640    }
    4741
     
    114108# -------------------------------------------------------------------------
    115109
     110    UsbController instproc init {} {
     111
     112        my set ignore false
     113
     114        next
     115    }
     116
     117# -------------------------------------------------------------------------
     118
    116119    UsbController instproc usbConnect {} {
    117         my instvar handle
     120        my instvar handle ignore
    118121
    119122        puts usbConnect
     
    123126            unset handle
    124127        }
    125 if {1} {
    126         while {[catch {usb::connect 0x09FB 0x6001 1 1 0} result]} {
    127             set answer [tk_messageBox -icon error -type retrycancel \
    128                 -message {Cannot access USB device} -detail $result]
    129 #            puts $result
    130             if {[string equal $answer cancel]} exit
    131         }
    132 
    133         set handle $result
    134 
    135 }
     128        if {!$ignore} {
     129            while {[catch {usb::connect 0x09FB 0x6001 1 1 0} result]} {
     130                set answer [tk_messageBox -icon error -type abortretryignore \
     131                    -message {Cannot access USB device} -detail $result]
     132                if {[string equal $answer abort]} exit
     133                if {[string equal $answer ignore]} {
     134                    set ignore true
     135                    return
     136                }
     137            }
     138
     139            set handle $result
     140
     141        }
    136142    }
    137143
     
    139145
    140146    UsbController instproc usbHandle {} {
    141         my instvar handle
     147        my instvar handle ignore
    142148
    143149        if {[my exists handle]} {
    144150            return $handle
    145         } else {
     151        } elseif {!$ignore} {
    146152            my usbConnect
    147153        }
     
    223229# -------------------------------------------------------------------------
    224230
    225     Class SpiDisplay -parameter {
     231    Class CfgDisplay -parameter {
    226232        {master}
    227233        {controller}
     
    230236# -------------------------------------------------------------------------
    231237
    232     SpiDisplay instproc init {} {
     238    CfgDisplay instproc init {} {
    233239
    234240        my setup
     
    239245# -------------------------------------------------------------------------
    240246
    241     SpiDisplay instproc destroy {} {
     247    CfgDisplay instproc destroy {} {
    242248        next
    243249    }
     
    245251# -------------------------------------------------------------------------
    246252
    247     SpiDisplay instproc start {} {
     253    CfgDisplay instproc start {} {
     254        variable adcCodes
    248255        my instvar config
    249256
    250         trace add variable [myvar dac1] write [myproc dac1_update]
    251         trace add variable [myvar dac2] write [myproc dac2_update]
    252 
    253         ${config(1)}.dac1 set 0
    254         ${config(1)}.dac2 set 0
    255     }
    256 
    257 # -------------------------------------------------------------------------
    258 
    259     SpiDisplay instproc setup {} {
     257        trace add variable [myvar decay] write [myproc decay_update]
     258        trace add variable [myvar delay] write [myproc delay_update]
     259        trace add variable [myvar thrs] write [myproc thrs_update]
     260
     261        foreach {ch id} [array get adcCodes] {
     262            ${config(clip)}.delay_${ch} set 32
     263            ${config(clip)}.decay_${ch} set 1000
     264        }
     265
     266        for {set i 0} {$i <= 3} {incr i} {
     267            ${config(thrs)}.thrs_${i} set 100
     268        }
     269
     270        for {set i 4} {$i <= 19} {incr i} {
     271            ${config(bins)}.thrs_${i} set 100
     272        }
     273    }
     274
     275# -------------------------------------------------------------------------
     276
     277    CfgDisplay instproc setup {} {
     278        variable adcCodes
    260279        my instvar number master
    261280        my instvar config
    262281
    263         set config(1) [labelframe ${master}.cfg1 -borderwidth 1 -relief sunken -text {DAC}]
    264 
    265         frame ${config(1)}.limits
    266         label ${config(1)}.limits.min -text {2.5V}
    267         label ${config(1)}.limits.max -text {0.0V}
    268 
    269         scale ${config(1)}.dac1 -orient vertical -from 4095 -to 0 -tickinterval 0 -variable [myvar dac1]
    270         scale ${config(1)}.dac2 -orient vertical -from 4095 -to 0 -tickinterval 0 -variable [myvar dac2]
    271 
    272         pack ${config(1)}.limits.min -anchor n -side top -pady 10
    273         pack ${config(1)}.limits.max -anchor s -side bottom -pady 9
    274 
    275         grid ${config(1)}.dac1 ${config(1)}.dac2 ${config(1)}.limits -sticky ns -pady 7
    276 
    277        
    278         set config(2) [labelframe ${master}.cfg2 -borderwidth 1 -relief sunken -text {ADC}]
    279 
    280         frame ${config(2)}.spc1 -width 130 -height 10
    281         frame ${config(2)}.spc2 -width 130 -height 10
    282         frame ${config(2)}.spc3 -width 130 -height 10
    283 
    284         button ${config(2)}.reset -text {Reset} -command [myproc adc_reset]
    285         button ${config(2)}.pattern -text {Test pattern} -command [myproc adc_pattern]
    286         button ${config(2)}.ramp -text {Test ramp} -command [myproc adc_ramp]
    287         button ${config(2)}.100mV -text {Test 100 mV} -command [myproc adc_100mV]
    288         button ${config(2)}.150mV -text {Test 150 mV} -command [myproc adc_150mV]
    289         button ${config(2)}.fltr0 -text {Filter 14MHz} -command [myproc adc_fltr0]
    290         button ${config(2)}.fltr1 -text {Filter 10MHz} -command [myproc adc_fltr1]
    291         button ${config(2)}.fltr2 -text {Filter 7.5MHz} -command [myproc adc_fltr2]
    292 
    293         grid ${config(2)}.spc1
    294         grid ${config(2)}.reset -sticky ew -pady 3 -padx 5
    295         grid ${config(2)}.spc2
    296         grid ${config(2)}.pattern -sticky ew -pady 3 -padx 5
    297         grid ${config(2)}.ramp -sticky ew -pady 3 -padx 5
    298         grid ${config(2)}.100mV -sticky ew -pady 3 -padx 5
    299         grid ${config(2)}.150mV -sticky ew -pady 3 -padx 5
    300         grid ${config(2)}.spc3
    301         grid ${config(2)}.fltr0 -sticky ew -pady 3 -padx 5
    302         grid ${config(2)}.fltr1 -sticky ew -pady 3 -padx 5
    303         grid ${config(2)}.fltr2 -sticky ew -pady 3 -padx 5
    304 
    305         grid ${config(1)} -row 1 -column 1 -sticky ns
    306         grid ${config(2)} -row 1 -column 2 -sticky ns
    307 
    308                 grid columnconfigure ${master} 0 -weight 1
    309                 grid columnconfigure ${master} 1 -weight 1
    310                 grid columnconfigure ${master} 2 -weight 1
    311                 grid columnconfigure ${master} 3 -weight 1
    312 
    313                 grid rowconfigure ${master} 0 -weight 0
    314                 grid rowconfigure ${master} 1 -weight 1
    315                 grid rowconfigure ${master} 2 -weight 0
    316 
    317         grid rowconfigure ${config(1)} 0 -weight 1
    318     }
    319 
    320 # -------------------------------------------------------------------------
    321 
    322     SpiDisplay instproc dac1_update args {
    323         my instvar controller dac1
    324 
    325         set value [format {3%03x} $dac1]
    326 
    327         set prefix [format {%x} 12]
     282        set thrs [frame ${master}.thrs]
     283        set bins [frame ${master}.bins]
     284        set clip [frame ${master}.clip]
     285
     286        set config(thrs) [labelframe ${thrs}.frame -borderwidth 1 -relief sunken -text {Thresholds}]
     287
     288        set column 0
     289        foreach {input} [list "ADC" "noise thrs" "e/p thrs"] {
     290            label ${config(thrs)}.label_${column} -text "${input}"
     291            grid ${config(thrs)}.label_${column} -row 0 -column ${column} -sticky ew -padx 5 -pady 7
     292            incr column
     293        }
     294
     295        foreach {ch id} [array get adcCodes {[1-2]}] {
     296            label ${config(thrs)}.chan_${ch} -text "${ch} "
     297            grid ${config(thrs)}.chan_${ch} -row ${ch} -column 0 -sticky ew -padx 5 -pady 7
     298            foreach {num} [list 0 1] {
     299                set column [expr {$num + 1}]
     300                set value [expr {2 * ($ch - 1) + $num}]
     301                puts "${num} ${ch} ${value}"
     302                spinbox ${config(thrs)}.thrs_${value} -from 0 -to 4095 \
     303                  -increment 10 -width 10 -textvariable [myvar thrs($value)] \
     304                  -validate all -vcmd {::mca::validate 4095 4 %P}
     305                grid ${config(thrs)}.thrs_${value} -row ${ch} -column ${column} -sticky w -padx 5 -pady 7
     306            }
     307        }
     308
     309        grid $config(thrs) -row 0 -column 0 -sticky news -padx 10
     310
     311        set config(bins) [labelframe ${bins}.frame -borderwidth 1 -relief sunken -text {Thresholds}]
     312
     313        set column 0
     314        foreach {input} [list "ADC" "thrs 1" "thrs 2" "thrs 3" "thrs 4"] {
     315            label ${config(bins)}.label_${column} -text "${input}"
     316            grid ${config(bins)}.label_${column} -row 0 -column ${column} -sticky ew -padx 5 -pady 7
     317            incr column
     318        }
     319
     320        foreach {ch id} [array get adcCodes {[3-6]}] {
     321            label ${config(bins)}.chan_${ch} -text "${ch} "
     322            grid ${config(bins)}.chan_${ch} -row ${ch} -column 0 -sticky ew -padx 5 -pady 7
     323            foreach {num} [list 0 1 2 3] {
     324                set column [expr {$num + 1}]
     325                set value [expr {4 * ($ch - 2) + $num}]
     326                puts "${num} ${ch} ${value}"
     327                spinbox ${config(bins)}.thrs_${value} -from 0 -to 4095 \
     328                  -increment 10 -width 10 -textvariable [myvar thrs($value)] \
     329                  -validate all -vcmd {::mca::validate 4095 4 %P}
     330                grid ${config(bins)}.thrs_${value} -row ${ch} -column ${column} -sticky w -padx 5 -pady 7
     331            }
     332        }
     333
     334        grid $config(bins) -row 0 -column 0 -sticky news -padx 10
     335
     336        set config(clip) [labelframe ${clip}.frame -borderwidth 1 -relief sunken -text {Signal clipping}]
     337
     338        set column 0
     339        foreach {input} [list "ADC" "delay" "decay"] {
     340            label ${config(clip)}.label_${column} -text "${input}"
     341            grid ${config(clip)}.label_${column} -row 0 -column ${column} -sticky ew -padx 5 -pady 7
     342            incr column
     343        }
     344
     345        foreach {ch id} [array get adcCodes] {
     346            label ${config(clip)}.chan_${ch} -text "${ch} "
     347            grid ${config(clip)}.chan_${ch} -row ${ch} -column 0 -sticky ew -padx 5 -pady 7
     348            spinbox ${config(clip)}.delay_${ch} -from 0 -to 62 \
     349                -increment 2 -width 10 -textvariable [myvar delay($ch)] \
     350                -validate all -vcmd {::mca::validate 63 5 %P}
     351            grid ${config(clip)}.delay_${ch} -row ${ch} -column 1 -sticky w -padx 5 -pady 7
     352            spinbox ${config(clip)}.decay_${ch} -from 0 -to 65535 \
     353                -increment 10 -width 10 -textvariable [myvar decay($ch)] \
     354                -validate all -vcmd {::mca::validate 65535 5 %P}
     355            grid ${config(clip)}.decay_${ch} -row ${ch} -column 2 -sticky w -padx 5 -pady 7
     356        }
     357
     358        grid $config(clip) -row 0 -column 0 -sticky news -padx 10
     359
     360        grid ${thrs} -row 0 -column 2 -sticky news
     361        grid ${bins} -row 0 -column 1 -sticky news
     362        grid ${clip} -row 0 -column 0 -sticky news
     363
     364        grid columnconfigure ${master} 0 -weight 1
     365        grid columnconfigure ${master} 1 -weight 1
     366        grid columnconfigure ${master} 2 -weight 1
     367        grid rowconfigure ${master} 0 -weight 1
     368
     369        grid rowconfigure ${thrs} 0 -weight 0
     370        grid rowconfigure ${bins} 0 -weight 0
     371        grid rowconfigure ${clip} 0 -weight 0
     372    }
     373
     374# -------------------------------------------------------------------------
     375
     376    CfgDisplay instproc decay_update args {
     377        my instvar controller decay delay
    328378
    329379        set command {}
    330         append command 0001${prefix}00000020000000402[string range $value 0 1]
    331         append command 0001${prefix}000000200000004[string range $value 2 3]00
     380        for {set i 1} {$i <= 6} {incr i} {
     381            set a $delay($i).0
     382            set b $decay($i).0
     383            set value [expr int(exp(-${a}/${b})*1024*17)]
     384            append command [format {000200%02x0004%04x} [expr {30 + 2 * (${i} - 1)}] $value]
     385        }
    332386
    333387        $controller usbCmd $command
     
    336390# -------------------------------------------------------------------------
    337391
    338     SpiDisplay instproc dac2_update args {
    339         my instvar controller dac2
    340 
    341         set value [format {b%03x} $dac1]
    342 
    343         set prefix [format {%x} 12]
     392    CfgDisplay instproc delay_update args {
     393        my instvar controller delay
    344394
    345395        set command {}
    346         append command 0001${prefix}00000020000000402[string range $value 0 1]
    347         append command 0001${prefix}000000200000004[string range $value 2 3]00
     396        for {set i 1} {$i <= 6} {incr i} {
     397            append command [format {000200%02x0004%04x} [expr {31 + 2 * (${i} - 1)}] $delay($i)]
     398        }
    348399
    349400        $controller usbCmd $command
    350     }
    351 
    352 # -------------------------------------------------------------------------
    353 
    354     SpiDisplay instproc adc_reset args {
    355         my instvar controller
    356 
    357         set prefix [format {%x} 12]
    358        
     401
     402        my decay_update
     403    }
     404
     405# -------------------------------------------------------------------------
     406
     407    CfgDisplay instproc thrs_update args {
     408        my instvar controller thrs
     409
    359410        set command {}
    360 
    361         set value {000001}
    362         append command 0001${prefix}00000020000000401[string range $value 0 1]
    363         append command 0001${prefix}000000200000004[string range $value 2 5]
    364 
    365         set value {040008}
    366         append command 0001${prefix}00000020000000401[string range $value 0 1]
    367         append command 0001${prefix}000000200000004[string range $value 2 5]
    368 
    369         $controller usbCmd $command
    370     }
    371 
    372 # -------------------------------------------------------------------------
    373 
    374     SpiDisplay instproc adc_pattern args {
    375         my instvar controller
    376 
    377         set value {022000}
    378 
    379         set prefix [format {%x} 12]
    380        
    381         set command {}
    382         append command 0001${prefix}00000020000000401[string range $value 0 1]
    383         append command 0001${prefix}000000200000004[string range $value 2 5]
    384 
    385         $controller usbCmd $command
    386     }
    387 
    388 # -------------------------------------------------------------------------
    389 
    390     SpiDisplay instproc adc_ramp args {
    391         my instvar controller
    392 
    393         set value {02E000}
    394 
    395         set prefix [format {%x} 12]
    396        
    397         set command {}
    398         append command 0001${prefix}00000020000000401[string range $value 0 1]
    399         append command 0001${prefix}000000200000004[string range $value 2 5]
    400 
    401         $controller usbCmd $command
    402     }
    403 
    404 # -------------------------------------------------------------------------
    405 
    406     SpiDisplay instproc adc_100mV args {
    407         my instvar controller
    408 
    409         set value {070080}
    410 
    411         set prefix [format {%x} 12]
    412        
    413         set command {}
    414         append command 0001${prefix}00000020000000401[string range $value 0 1]
    415         append command 0001${prefix}000000200000004[string range $value 2 5]
    416 
    417         $controller usbCmd $command
    418     }
    419 
    420 # -------------------------------------------------------------------------
    421 
    422     SpiDisplay instproc adc_150mV args {
    423         my instvar controller
    424 
    425         set value {070180}
    426 
    427         set prefix [format {%x} 12]
    428        
    429         set command {}
    430         append command 0001${prefix}00000020000000401[string range $value 0 1]
    431         append command 0001${prefix}000000200000004[string range $value 2 5]
    432 
    433         $controller usbCmd $command
    434     }
    435 
    436 # -------------------------------------------------------------------------
    437 
    438     SpiDisplay instproc adc_fltr0 args {
    439         my instvar controller
    440 
    441         set value {070000}
    442 
    443         set prefix [format {%x} 12]
    444        
    445         set command {}
    446         append command 0001${prefix}00000020000000401[string range $value 0 1]
    447         append command 0001${prefix}000000200000004[string range $value 2 5]
    448 
    449         $controller usbCmd $command
    450     }
    451 
    452 # -------------------------------------------------------------------------
    453 
    454     SpiDisplay instproc adc_fltr1 args {
    455         my instvar controller
    456 
    457         set value {070004}
    458 
    459         set prefix [format {%x} 12]
    460        
    461         set command {}
    462         append command 0001${prefix}00000020000000401[string range $value 0 1]
    463         append command 0001${prefix}000000200000004[string range $value 2 5]
    464 
    465         $controller usbCmd $command
    466     }
    467 
    468 # -------------------------------------------------------------------------
    469 
    470     SpiDisplay instproc adc_fltr2 args {
    471         my instvar controller
    472 
    473         set value {070008}
    474 
    475         set prefix [format {%x} 12]
    476        
    477         set command {}
    478         append command 0001${prefix}00000020000000401[string range $value 0 1]
    479         append command 0001${prefix}000000200000004[string range $value 2 5]
     411        for {set i 0} {$i <= 19} {incr i} {
     412            append command [format {000200%02x0004%04x} [expr {10 + ${i}}] $thrs($i)]
     413        }
    480414
    481415        $controller usbCmd $command
     
    549483        set key [frame ${master}.key]
    550484        set inv [frame ${master}.inv]
    551        
     485
    552486        foreach {osc title} $oscList {
    553487            set config($osc) [labelframe ${mux}.$osc -borderwidth 1 -relief sunken -text $title]
     
    580514        label $config(key).f -text "f - filtered signal"
    581515        grid $config(key).f -row 0 -column 1 -sticky news
    582  
     516
    583517        label $config(key).d -text "d - deconvoluted signal"
    584518        grid $config(key).d -row 0 -column 2 -sticky news
    585  
     519
    586520        label $config(key).c -text "c - clipped signal"
    587521        grid $config(key).c -row 0 -column 3 -sticky news
     
    589523        grid $config(key) -row 0 -column 0 -sticky news -padx 10
    590524
    591        
     525
    592526        set config(inv) [labelframe ${inv}.frame -borderwidth 1 -relief sunken -text {polarity inversion}]
    593527        label $config(inv).chan_label -text "channel "
     
    620554        grid columnconfigure $config(key) 3 -weight 1
    621555
    622        
     556
    623557        grid columnconfigure ${mux} 0 -weight 1
    624558        grid columnconfigure ${mux} 1 -weight 1
     
    627561        grid columnconfigure ${mux} 4 -weight 1
    628562        grid columnconfigure ${mux} 5 -weight 1
    629 
    630 
    631     }
    632 
     563    }
    633564
    634565# ------------------------------------------------------------------------
     
    648579    MuxDisplay instproc polar_update args {
    649580        my instvar controller polar
    650        
     581
    651582        set value {0b}
    652         for {set i 12} {$i >= 1} {incr i -1} {
    653             append value $polar($i) 
     583        for {set i 6} {$i >= 1} {incr i -1} {
     584            append value $polar($i)
    654585        }
    655586
     
    673604        my set data {}
    674605
    675         vector create [myvar xvec](4096)
    676         vector create [myvar yvec](4096)
    677 
    678         # fill one vector for the x axis with 4096 points
    679         [myvar xvec] seq -0.5 4095.5
     606        vector create [myvar xvec](64)
     607        vector create [myvar yvec](64)
     608
     609        # fill one vector for the x axis with 64 points
     610        [myvar xvec] seq -0.5 63.5
    680611
    681612        my setup
     
    696627
    697628        trace add variable [myvar data] write [myproc data_update]
    698         trace add variable [myvar cntr_val] write [myproc cntr_val_update]
    699         trace add variable [myvar rate_val] write [myproc rate_val_update]
    700629
    701630        trace add variable [myvar axis] write [myproc axis_update]
    702         trace add variable [myvar thrs] write [myproc thrs_update]
    703         trace add variable [myvar thrs_val] write [myproc thrs_update]
    704         trace add variable [myvar base] write [myproc base_update]
    705         trace add variable [myvar base_typ] write [myproc base_typ_update]
    706         trace add variable [myvar base_val] write [myproc base_val_update]
    707631
    708632        ${config}.axis_check select
    709633
    710         ${config}.thrs_check select
    711         ${config}.thrs_field set 25
    712 
    713         ${config}.base_auto select
    714         ${config}.base_field set 20
    715         ${config}.base_check select
    716 
    717         set cntr_tmp 1200000000
    718         my set cntr_val $cntr_tmp
    719         my set cntr_bak $cntr_tmp
    720         my set cntr_old $cntr_tmp
    721634        my set yvec_bak 0.0
    722635        my set yvec_old 0.0
    723 
    724         my set rate_val(inst) 0.0
    725         my set rate_val(mean) 0.0
    726 
    727 #        my cntr_reset
    728636    }
    729637
     
    741649        $graph grid configure -hide no
    742650        $graph legend configure -hide yes
    743         $graph axis configure x -min 0 -max 4096
     651        $graph axis configure x -min 0 -max 64
    744652
    745653        set config [frame ${master}.config -width 170]
     
    748656
    749657        frame ${config}.spc1 -width 170 -height 30
    750 
    751         frame ${config}.rate_frame -borderwidth 0 -width 170
    752         legendLabel ${config}.rate_frame 0 inst {Inst. rate, 1/s}
    753         legendLabel ${config}.rate_frame 1 mean {Avg. rate, 1/s}
    754 
    755         frame ${config}.spc2 -width 170 -height 30
    756658
    757659        frame ${config}.chan_frame -borderwidth 0 -width 170
     
    759661        legendLabel ${config}.chan_frame 1 axisx {Bin number}
    760662
    761         frame ${config}.spc3 -width 170 -height 30
    762 
    763         frame ${config}.cntr_frame -borderwidth 0 -width 170
    764 
    765         label ${config}.cntr_frame.h -width 3 -anchor w -text {h}
    766         entry ${config}.cntr_frame.h_field -width 3 -textvariable [myvar cntr_h] \
    767             -validate all -vcmd {::mca::validate 999 3 %P}
    768         label ${config}.cntr_frame.m -width 3 -anchor w -text {m}
    769         entry ${config}.cntr_frame.m_field -width 3 -textvariable [myvar cntr_m] \
    770             -validate all -vcmd {::mca::validate 59 2 %P}
    771         label ${config}.cntr_frame.s -width 3 -anchor w -text {s}
    772         entry ${config}.cntr_frame.s_field -width 6 -textvariable [myvar cntr_s] \
    773             -validate all -vcmd {::mca::doublevalidate 59.999 %P}
    774 
    775         grid ${config}.cntr_frame.h_field ${config}.cntr_frame.h \
    776             ${config}.cntr_frame.m_field ${config}.cntr_frame.m ${config}.cntr_frame.s_field ${config}.cntr_frame.s
    777 
    778         frame ${config}.spc4 -width 170 -height 10
     663        frame ${config}.spc2 -width 170 -height 30
    779664
    780665        button ${config}.start -text Start \
     
    783668            -bg red -activebackground red -command [myproc cntr_reset]
    784669
    785         frame ${config}.spc5 -width 170 -height 30
    786 
    787         checkbutton ${config}.thrs_check -text threshold -variable [myvar thrs]
    788         spinbox ${config}.thrs_field -from 1 -to 4095 \
    789             -increment 5 -width 10 -textvariable [myvar thrs_val] \
    790             -validate all -vcmd {::mca::validate 4095 4 %P}
    791 
    792         frame ${config}.spc6 -width 170 -height 30
    793 
    794         checkbutton ${config}.base_check -text baseline -variable [myvar base]
    795         radiobutton ${config}.base_auto -text automatic -variable [myvar base_typ] -value 1
    796         radiobutton ${config}.base_const -text constant -variable [myvar base_typ] -value 0
    797         spinbox ${config}.base_field -from 1 -to 4095 \
    798             -increment 5 -width 10 -textvariable [myvar base_val] \
    799             -validate all -vcmd {::mca::validate 4095 4 %P}
    800 
    801         frame ${config}.spc7 -width 170 -height 30
     670        frame ${config}.spc3 -width 170 -height 30
    802671
    803672        button ${config}.register -text Register \
     
    806675        grid ${config}.axis_check -sticky w
    807676        grid ${config}.spc1
    808         grid ${config}.rate_frame -sticky ew -padx 5
     677        grid ${config}.chan_frame -sticky ew -padx 5
    809678        grid ${config}.spc2
    810         grid ${config}.chan_frame -sticky ew -padx 5
    811         grid ${config}.spc3
    812         grid ${config}.cntr_frame -sticky ew -padx 5
    813         grid ${config}.spc4
    814679        grid ${config}.start -sticky ew -pady 3 -padx 5
    815680        grid ${config}.reset -sticky ew -pady 3 -padx 5
    816         grid ${config}.spc5
    817         grid ${config}.thrs_check -sticky w
    818         grid ${config}.thrs_field -sticky ew -pady 1 -padx 5
    819         grid ${config}.spc6
    820         grid ${config}.base_check -sticky w
    821         grid ${config}.base_auto -sticky w
    822         grid ${config}.base_const -sticky w
    823         grid ${config}.base_field -sticky ew -pady 1 -padx 5
    824         grid ${config}.spc7
     681        grid ${config}.spc3
    825682        grid ${config}.register -sticky ew -pady 3 -padx 5
    826683
     
    832689        grid columnconfigure ${master} 1 -weight 0 -minsize 80
    833690
    834         grid columnconfigure ${config}.rate_frame 1 -weight 1
    835691        grid columnconfigure ${config}.chan_frame 1 -weight 1
    836692
     
    886742# -------------------------------------------------------------------------
    887743
    888     HstDisplay instproc thrs_update args {
    889         my instvar controller config number thrs thrs_val
    890 
    891         if {[string equal $thrs_val {}]} {
    892             set thrs_val 0
    893         }
    894 
    895         set val_addr [format %02x [expr {6 + 2 * ${number}}]]
    896 
    897         if {$thrs} {
    898             ${config}.thrs_field configure -state normal
    899             set value [format %03x $thrs_val]
    900         } else {
    901             ${config}.thrs_field configure -state disabled
    902             set value 000
    903         }
    904 
    905         $controller usbCmd 000200${val_addr}00040${value}
    906     }
    907 
    908 # -------------------------------------------------------------------------
    909 
    910     HstDisplay instproc base_update args {
    911         my instvar controller config number base base_typ
    912 
    913         set val_addr [format %02x [expr {7 + 2 * ${number}}]]
    914 
    915         if {$base} {
    916             ${config}.base_auto configure -state normal
    917             ${config}.base_const configure -state normal
    918             my base_typ_update
    919         } else {
    920             ${config}.base_auto configure -state disabled
    921             ${config}.base_const configure -state disabled
    922             ${config}.base_field configure -state disabled
    923             $controller usbCmd 000200${val_addr}0004${base_typ}000
    924         }
    925     }
    926 
    927 # -------------------------------------------------------------------------
    928 
    929     HstDisplay instproc base_typ_update args {
    930         my instvar config base_typ
    931 
    932         switch -- $base_typ {
    933             1 {
    934                 ${config}.base_field configure -state disabled
    935             }
    936             0 {
    937                 ${config}.base_field configure -state normal
    938             }
    939         }
    940 
    941         my base_val_update
    942     }
    943 
    944 # -------------------------------------------------------------------------
    945 
    946     HstDisplay instproc base_val_update args {
    947         my instvar controller number base_typ base_val
    948 
    949         if {[string equal $base_val {}]} {
    950             set base_val 0
    951         }
    952 
    953         set val_addr [format %02x [expr {7 + 2 * ${number}}]]
    954         set value [format %03x $base_val]
    955 
    956         $controller usbCmd 000200${val_addr}0004${base_typ}${value}
    957     }
    958 
    959 # -------------------------------------------------------------------------
    960 
    961     HstDisplay instproc rate_val_update {name key op} {
    962         my instvar config rate_val
    963 
    964         ${config}.rate_frame.${key}_value configure -text [format {%.2e} $rate_val(${key})]
    965     }
    966 
    967 # -------------------------------------------------------------------------
    968 
    969     HstDisplay instproc cntr_val_update args {
    970         my instvar cntr_val cntr_h cntr_m cntr_s
    971 
    972         set cntr_tmp [expr {${cntr_val}/20000}]
    973         set cntr_h [expr {${cntr_tmp}/3600000}]
    974         set cntr_m [expr {${cntr_tmp}%3600000/60000}]
    975         set cntr_s [expr {${cntr_tmp}%3600000%60000/1000.0}]
    976     }
    977 
    978 # -------------------------------------------------------------------------
    979 
    980     HstDisplay instproc cntr_setup {} {
    981         my instvar controller number cntr_val
    982 
    983         set word0 [format %08x [expr {${cntr_val} & 0xFFFFFFFF}]]
    984         set word1 [format %08x [expr {${cntr_val} >> 32}]]
    985 
    986         set prefix [format %x [expr {5 + ${number}}]]
    987 
    988         set command {}
    989         append command 0001${prefix}000000200000004[string range $word0 4 7]
    990         append command 0001${prefix}000000200010004[string range $word0 0 3]
    991         append command 0001${prefix}000000200020004[string range $word1 4 7]
    992         append command 0001${prefix}000000200030004[string range $word1 0 3]
    993 
    994         # send counter value
    995         $controller usbCmd $command
    996 
    997         # load counter value
    998 #        set val_addr [format %02x [expr {12 + ${number}}]]
    999 #        $controller usbCmd 000200${val_addr}00040001000200${val_addr}00040000
    1000     }
    1001 
    1002 # -------------------------------------------------------------------------
    1003 
    1004744    HstDisplay instproc cntr_reset {} {
    1005         my instvar controller number after_handle
    1006         my instvar cntr_val cntr_bak cntr_old yvec_bak yvec_old
     745        my instvar controller number
    1007746
    1008747        my cntr_stop
     
    1011750        $controller usbCmd 000200000004${value}0002000000040000
    1012751
    1013         set cntr_val $cntr_bak
    1014         my cntr_setup
    1015 
    1016         set cntr_old $cntr_bak
    1017         set yvec_bak 0.0
    1018         set yvec_old 0.0
    1019        
    1020752        my acquire
    1021 
    1022         my cntr_ready
    1023     }
    1024 
    1025 # -------------------------------------------------------------------------
    1026 
    1027     HstDisplay instproc cntr_ready {} {
    1028         my instvar config cntr_val cntr_bak
    1029 
    1030         set cntr_val $cntr_bak
    1031 
    1032         ${config}.start configure -text Start -command [myproc cntr_start]
    1033         ${config}.reset configure -state active
    1034 
    1035         ${config}.cntr_frame.h_field configure -state normal
    1036         ${config}.cntr_frame.m_field configure -state normal
    1037         ${config}.cntr_frame.s_field configure -state normal
    1038753    }
    1039754
     
    1041756
    1042757    HstDisplay instproc cntr_start {} {
    1043         my instvar config
    1044         my instvar cntr_h cntr_m cntr_s
    1045         my instvar cntr_val cntr_bak cntr_old yvec_bak yvec_old
    1046 
    1047         set h $cntr_h
    1048         set m $cntr_m
    1049         set s $cntr_s
    1050 
    1051         if {[string equal $h {}]} {
    1052             set h 0
    1053         }
    1054         if {[string equal $m {}]} {
    1055             set m 0
    1056         }
    1057         if {[string equal $s {}]} {
    1058             set s 0
    1059         }
    1060 
    1061         set cntr_tmp [expr {${h}*3600000 + ${m}*60000 + ${s}*1000}]
    1062         set cntr_tmp [expr {entier(20000 * ${cntr_tmp})}]
    1063 
    1064         if {$cntr_tmp > 0} {
    1065             ${config}.cntr_frame.h_field configure -state disabled
    1066             ${config}.cntr_frame.m_field configure -state disabled
    1067             ${config}.cntr_frame.s_field configure -state disabled
    1068 
    1069             set cntr_val $cntr_tmp
    1070             set cntr_bak $cntr_tmp
    1071             set cntr_old $cntr_tmp
    1072             set yvec_bak [usb::integrateBlt [myvar yvec] 0]
    1073             set yvec_old $yvec_bak
    1074 
    1075             my cntr_setup
    1076 
    1077             my cntr_resume
    1078         }
    1079     }
    1080 
    1081 # -------------------------------------------------------------------------
    1082 
    1083     HstDisplay instproc cntr_pause {} {
    1084         my instvar config
    1085 
    1086         my cntr_stop
    1087 
    1088         ${config}.start configure -text Resume -command [myproc cntr_resume]
    1089 #        ${config}.reset configure -state active
    1090 
    1091     }
    1092 
    1093 # -------------------------------------------------------------------------
    1094 
    1095     HstDisplay instproc cntr_resume {} {
    1096758        my instvar controller config number auto
    1097759
    1098         set val_addr [format %02x [expr {13 + ${number}}]]
    1099 
    1100         ${config}.start configure -text Pause -command [myproc cntr_pause]
     760        set val_addr [format %02x [expr {6 + ${number}}]]
     761
     762        ${config}.start configure -text Stop -command [myproc cntr_stop]
    1101763#        ${config}.reset configure -state disabled
    1102764
    1103         $controller usbCmd 000200${val_addr}00040002
     765        $controller usbCmd 000200${val_addr}00040001
    1104766
    1105767        set auto 1
     
    1113775        my instvar controller config number auto
    1114776
    1115         set val_addr [format %02x [expr {13 + ${number}}]]
     777        set val_addr [format %02x [expr {6 + ${number}}]]
     778
     779        ${config}.start configure -text Start -command [myproc cntr_start]
    1116780
    1117781        $controller usbCmd 000200${val_addr}00040000
    1118782
    1119783        set auto 0
     784
     785        my acquire
    1120786    }
    1121787
     
    1134800        my acquire
    1135801
    1136         if {$cntr_val == 0} {
    1137             my cntr_stop
    1138             my cntr_ready
    1139         } elseif {$auto} {
     802        if {$auto} {
    1140803            after 1000 [myproc acquire_loop]
    1141804        }
     
    1146809    HstDisplay instproc acquire {} {
    1147810        my instvar controller config number
    1148         my instvar cntr_val cntr_bak cntr_old yvec_bak yvec_old rate_val
    1149 
    1150         set size 4096
     811
     812        set size 64
    1151813
    1152814        set prefix [format {%x} [expr {$number + 2}]]
     
    1157819
    1158820        $controller usbCmdReadRaw $command [expr {$size * 4}] [myvar data]
    1159         set yvec_new [usb::integrateBlt [myvar yvec]]
    1160 
    1161         set prefix [format {%x} [expr {$number + 5}]]
    1162         set command 0001${prefix}000000200000003000400050000
    1163 
    1164         $controller usbCmdReadHex $command 8 1 [myvar cntr_val]
    1165         set cntr_new $cntr_val
    1166 
    1167         if {$cntr_new < $cntr_old} {
    1168             set rate_val(inst) [expr {($yvec_new - $yvec_old)*20000000/($cntr_old - $cntr_new)}]
    1169             set rate_val(mean) [expr {($yvec_new - $yvec_bak)*20000000/($cntr_bak - $cntr_new)}]
    1170             set yvec_old $yvec_new
    1171             set cntr_old $cntr_new
    1172         }
    1173821   }
    1174822
     
    1209857
    1210858    HstDisplay instproc register {} {
    1211         my save_data [join [[myvar yvec] range 0 4095] \n]
    1212     }
    1213 
    1214 # -------------------------------------------------------------------------
    1215 
    1216     Class CntDisplay -parameter {
     859        my save_data [join [[myvar yvec] range 0 63] \n]
     860    }
     861
     862# -------------------------------------------------------------------------
     863
     864    Class OscDisplay -parameter {
    1217865        {master}
    1218866        {controller}
     
    1221869# -------------------------------------------------------------------------
    1222870
    1223     CntDisplay instproc init {} {
    1224 
    1225         my set data {}
    1226         my set cntr 0
    1227         my set recs 0
    1228 
    1229         vector create [myvar xvec](16384)
    1230         vector create [myvar yvec](16384)
    1231 
    1232         # fill one vector for the x axis with 16384 points
    1233         [myvar xvec] seq -0.5 16384.5
     871    OscDisplay instproc init {} {
     872        my instvar sequence data xvec yvec
     873
     874        set data {}
     875
     876        set sequence 0
     877
     878#        set xvec [vector create #auto(262144)]
     879#        set xvec [vector create #auto(10000)]
     880        set xvec [vector create #auto(60000)]
     881
     882        for {set i 1} {$i <= 9} {incr i} {
     883#          dict set yvec $i [vector create #auto(262144)]
     884#          dict set yvec $i [vector create #auto(10000)]
     885          dict set yvec $i [vector create #auto(60000)]
     886        }
     887
     888        # fill one vector for the x axis
     889#        $xvec seq 0 262143
     890#        $xvec seq 0 10000
     891        $xvec seq 0 60000
    1234892
    1235893        my setup
     
    1240898# -------------------------------------------------------------------------
    1241899
    1242     CntDisplay instproc destroy {} {
     900    OscDisplay instproc destroy {} {
    1243901        next
    1244902    }
     
    1246904# -------------------------------------------------------------------------
    1247905
    1248     CntDisplay instproc start {} {
     906    OscDisplay instproc start {} {
    1249907        my instvar config
     908        my instvar recs_val directory
     909
     910        set directory $::env(HOME)
     911        set recs_val 100
     912
     913        trace add variable [myvar chan] write [myproc chan_update]
    1250914
    1251915        trace add variable [myvar data] write [myproc data_update]
    1252916
    1253         trace add variable [myvar thrs_val] write [myproc thrs_val_update]
    1254 
    1255         trace add variable [myvar cntr] write [myproc cntr_update]
    1256         trace add variable [myvar recs] write [myproc recs_update]
    1257 
    1258         trace add variable [myvar axis] write [myproc axis_update]
    1259 
    1260         ${config}.axis_check select
    1261 
    1262         my set thrs_val 100
    1263 
    1264         my set cntr_val 100
    1265         my set cntr_bak 100
    1266         my set recs_val 100
    1267         my set recs_bak 100
    1268 
    1269 #        my cntr_reset
    1270     }
    1271 
    1272 # -------------------------------------------------------------------------
    1273 
    1274     CntDisplay instproc setup {} {
     917        trace add variable [myvar auto] write [myproc auto_update]
     918
     919        trace add variable [myvar thrs] write [myproc thrs_update 0]
     920        trace add variable [myvar thrs_val] write [myproc thrs_update 0]
     921
     922        trace add variable [myvar recs_val] write [myproc recs_val_update]
     923
     924        trace add variable [myvar last] write [myproc last_update]
     925
     926        for {set i 1} {$i <= 6} {incr i} {
     927            ${config}.chan_frame.chan${i}_check select
     928            ${config}.chan_frame.chan${i}_value configure -text 0.0
     929        }
     930        ${config}.chan_frame.axisx_value configure -text 0.0
     931
     932        ${config}.thrs_check select
     933        ${config}.thrs_field set 100
     934    }
     935
     936# -------------------------------------------------------------------------
     937
     938    OscDisplay instproc setup {} {
    1275939        my instvar master
    1276940        my instvar xvec yvec graph
    1277941        my instvar config
    1278         my instvar cntr_ms
    1279942
    1280943        # create a graph widget and show a grid
     
    1283946        $graph grid configure -hide no
    1284947        $graph legend configure -hide yes
    1285         $graph axis configure x -min 0 -max 16384
    1286 
    1287         set config [frame ${master}.config -width 170]
    1288 
    1289         checkbutton ${config}.axis_check -text {log scale} -variable [myvar axis]
    1290 
    1291         frame ${config}.spc1 -width 170 -height 30
    1292 
    1293         frame ${config}.chan_frame -borderwidth 0 -width 170
    1294         legendLabel ${config}.chan_frame 0 mean  {Mean value}
    1295         legendLabel ${config}.chan_frame 1 entr  {Total entries}
    1296         legendLabel ${config}.chan_frame 2 empty {}
    1297         legendLabel ${config}.chan_frame 3 axisy {Bin entries}
    1298         legendLabel ${config}.chan_frame 4 axisx {Bin number}
    1299 
    1300         frame ${config}.spc3 -width 170 -height 30
    1301 
    1302         label ${config}.thrs -text {amplitude threshold}
    1303         spinbox ${config}.thrs_field -from 1 -to 4095 \
    1304             -increment 5 -width 10 -textvariable [myvar thrs_val] \
    1305             -validate all -vcmd {::mca::validate 4095 4 %P}
    1306 
    1307         frame ${config}.spc4 -width 170 -height 30
    1308 
    1309         label ${config}.cntr -text {time of exposure (s)}
    1310         spinbox ${config}.cntr_field -from 0 -to 9999 \
    1311             -increment 10 -width 10 -textvariable [myvar cntr_val] \
    1312             -validate all -vcmd {::mca::validate 9999 4 %P}
    1313 
    1314         frame ${config}.spc5 -width 170 -height 10
    1315 
    1316         label ${config}.recs -text {number of exposures}
    1317         spinbox ${config}.recs_field -from 0 -to 99999 \
    1318             -increment 10 -width 10 -textvariable [myvar recs_val] \
    1319             -validate all -vcmd {::mca::validate 99999 5 %P}
    1320 
    1321         frame ${config}.spc6 -width 170 -height 10
    1322 
    1323         button ${config}.start -text {Start}  \
    1324             -bg yellow -activebackground yellow -command [myproc recs_start]
    1325 
    1326         button ${config}.reset -text Reset \
    1327             -bg red -activebackground red -command [myproc cntr_reset]
    1328 
    1329         frame ${config}.spc7 -width 170 -height 30
    1330 
    1331         button ${config}.register -text Register \
    1332             -bg lightblue -activebackground lightblue -command [myproc register]
    1333 
    1334         grid ${config}.axis_check -sticky w
    1335         grid ${config}.spc1
    1336         grid ${config}.chan_frame -sticky ew -padx 5
    1337         grid ${config}.spc3
    1338         grid ${config}.thrs -sticky w -pady 1 -padx 3
    1339         grid ${config}.thrs_field -sticky ew -pady 1 -padx 5
    1340         grid ${config}.spc4
    1341         grid ${config}.cntr -sticky w -pady 1 -padx 3
    1342         grid ${config}.cntr_field -sticky ew -pady 1 -padx 5
    1343         grid ${config}.spc5
    1344         grid ${config}.recs -sticky w -pady 1 -padx 3
    1345         grid ${config}.recs_field -sticky ew -pady 1 -padx 5
    1346         grid ${config}.spc6
    1347         grid ${config}.start -sticky ew -pady 3 -padx 5
    1348         grid ${config}.reset -sticky ew -pady 3 -padx 5
    1349         grid ${config}.spc7
    1350         grid ${config}.register -sticky ew -pady 3 -padx 5
    1351 
    1352         grid ${graph} -row 0 -column 0 -sticky news
    1353         grid ${config} -row 0 -column 1
    1354 
    1355         grid rowconfigure ${master} 0 -weight 1
    1356         grid columnconfigure ${master} 0 -weight 1
    1357         grid columnconfigure ${master} 1 -weight 0 -minsize 80
    1358 
    1359         grid columnconfigure ${config}.chan_frame 1 -weight 1
    1360 
    1361         # enable zooming
    1362         Blt_ZoomStack $graph
    1363 
    1364         my crosshairs $graph
    1365 
    1366         #bind .graph <Motion> {%W crosshairs configure -position @%x,%y}
    1367 
    1368         # create one element with data for the x and y axis, no dots
    1369         $graph element create Spectrum1 -color blue -linewidth 2 -symbol none -smooth step -xdata [myvar xvec] -ydata [myvar yvec]
    1370     }
    1371 
    1372 # -------------------------------------------------------------------------
    1373 
    1374     CntDisplay instproc coor_update {W x y} {
    1375         my instvar config graph
    1376 
    1377         $W crosshairs configure -position @${x},${y}
    1378 
    1379         set index [$W axis invtransform x $x]
    1380         set index [::tcl::mathfunc::round $index]
    1381         catch {
    1382             ${config}.chan_frame.axisy_value configure -text [[myvar yvec] index $index]
    1383             ${config}.chan_frame.axisx_value configure -text ${index}.0
    1384         }
    1385     }
    1386 # -------------------------------------------------------------------------
    1387 
    1388     CntDisplay instproc crosshairs {graph} {
    1389         set method [myproc coor_update]
    1390         bind $graph <Motion> [list [self] coor_update %W %x %y]
    1391         bind $graph <Leave> {
    1392             %W crosshairs off
    1393         }
    1394         bind $graph <Enter> {
    1395             %W crosshairs on
    1396         }
    1397     }
    1398 
    1399 # -------------------------------------------------------------------------
    1400 
    1401     CntDisplay instproc thrs_val_update args {
    1402         my instvar controller config thrs_val
    1403 
    1404         if {[string equal $thrs_val {}]} {
    1405             set thrs_val 0
    1406         }
    1407 
    1408         set val_addr [format %02x 12]
    1409 
    1410         ${config}.thrs_field configure -state normal
    1411         set value [format %03x $thrs_val]
    1412 
    1413         $controller usbCmd 000200${val_addr}00040${value}
    1414     }
    1415 
    1416 # -------------------------------------------------------------------------
    1417 
    1418     CntDisplay instproc cntr_update args {
    1419         my instvar cntr cntr_val
    1420         set cntr_val [expr {${cntr}/20000000}]
    1421 
    1422     }
    1423 
    1424 # -------------------------------------------------------------------------
    1425 
    1426     CntDisplay instproc recs_update args {
    1427         my instvar recs recs_val
    1428         set recs_val [expr {${recs}*1}]
    1429     }
    1430 
    1431 # -------------------------------------------------------------------------
    1432 
    1433     CntDisplay instproc cntr_setup {} {
    1434         my instvar controller cntr_val
    1435 
    1436         set cntr_tmp [expr {${cntr_val} * 20000000}]
    1437         set word0 [format {%08x} [expr {${cntr_tmp} & 0xFFFFFFFF}]]
    1438         set word1 [format {%08x} [expr {${cntr_tmp} >> 32}]]
    1439 
    1440         set prefix [format {%x} 9]
    1441 
    1442         set command {}
    1443         append command 0001${prefix}000000200000004[string range $word0 4 7]
    1444         append command 0001${prefix}000000200010004[string range $word0 0 3]
    1445         append command 0001${prefix}000000200020004[string range $word1 4 7]
    1446         append command 0001${prefix}000000200030004[string range $word1 0 3]
    1447 
    1448         # send counter value
    1449         $controller usbCmd $command
    1450     }
    1451 
    1452 # -------------------------------------------------------------------------
    1453 
    1454     CntDisplay instproc recs_setup {} {
    1455         my instvar controller recs_val
    1456 
    1457         set word0 [format {%08x} [expr {${recs_val} & 0xFFFFFFFF}]]
    1458         set word1 [format {%08x} [expr {${recs_val} >> 32}]]
    1459 
    1460         set prefix [format {%x} 10]
    1461 
    1462         set command {}
    1463         append command 0001${prefix}000000200000004[string range $word0 4 7]
    1464         append command 0001${prefix}000000200010004[string range $word0 0 3]
    1465         append command 0001${prefix}000000200020004[string range $word1 4 7]
    1466         append command 0001${prefix}000000200030004[string range $word1 0 3]
    1467 
    1468         # send counter value
    1469         $controller usbCmd $command
    1470     }
    1471 
    1472 # -------------------------------------------------------------------------
    1473 
    1474     CntDisplay instproc cntr_reset {} {
    1475         my instvar controller after_handle
    1476         my instvar cntr_val cntr_bak recs_val recs_bak
    1477 
    1478         my cntr_stop
    1479 
    1480         set value [format {%04x} [expr {1 << 11}]]
    1481         $controller usbCmd 000200000004${value}0002000000040000
    1482 
    1483         my recs_stop
    1484     }
    1485 
    1486 # -------------------------------------------------------------------------
    1487 
    1488     CntDisplay instproc cntr_ready {} {
    1489         my instvar config cntr_val cntr_bak recs_val recs_bak
    1490 
    1491         set cntr_val $cntr_bak
    1492         set recs_val $recs_bak
    1493 
    1494         ${config}.start configure -text Start -command [myproc recs_start]
    1495         ${config}.reset configure -state active
    1496 
    1497         ${config}.start configure -state active
    1498         ${config}.cntr_field configure -state normal
    1499         ${config}.recs_field configure -state normal
    1500     }
    1501 
    1502 # -------------------------------------------------------------------------
    1503 
    1504     CntDisplay instproc recs_start {} {
    1505         my instvar controller config auto
    1506         my instvar cntr_val cntr_bak recs_val recs_bak
    1507 
    1508         if {$cntr_val > 0 && $recs_val > 0} {
    1509             ${config}.start configure -text {Stop} -command [myproc recs_stop]
    1510             ${config}.cntr_field configure -state disabled
    1511             ${config}.recs_field configure -state disabled
    1512 
    1513             set cntr_bak $cntr_val
    1514             set recs_bak $recs_val
    1515 
    1516             my cntr_setup
    1517             my recs_setup
    1518 
    1519             set val_addr [format {%02x} 16]
    1520 
    1521             $controller usbCmd 000200${val_addr}00040002
    1522 
    1523             set auto 1
    1524 
    1525             after 100 [myproc acquire_loop]
    1526         }
    1527     }
    1528 
    1529 # -------------------------------------------------------------------------
    1530 
    1531     CntDisplay instproc recs_stop {} {
    1532         my instvar cntr_val cntr_bak recs_val recs_bak
    1533 
    1534         my cntr_stop
    1535 
    1536         set cntr_val $cntr_bak
    1537         my cntr_setup
    1538 
    1539         set recs_val $recs_bak
    1540         my recs_setup
    1541 
    1542         my acquire
    1543 
    1544         my cntr_ready
    1545     }
    1546 
    1547 # -------------------------------------------------------------------------
    1548 
    1549     CntDisplay instproc cntr_stop {} {
    1550         my instvar controller config auto
    1551 
    1552         set val_addr [format {%02x} 16]
    1553 
    1554         $controller usbCmd 000200${val_addr}00040000
    1555 
    1556         set auto 0
    1557     }
    1558 
    1559 # -------------------------------------------------------------------------
    1560 
    1561     CntDisplay instproc acquire_loop {} {
    1562         my instvar recs_val auto
    1563 
    1564         my acquire
    1565 
    1566         if {$recs_val == 0} {
    1567             my cntr_stop
    1568             my cntr_ready
    1569         } elseif {$auto} {
    1570             after 1000 [myproc acquire_loop]
    1571         }
    1572     }
    1573 
    1574 # -------------------------------------------------------------------------
    1575 
    1576     CntDisplay instproc data_update args {
    1577         my instvar config data
    1578         usb::convertBlt $data 2 [myvar yvec]
    1579 
    1580         ${config}.chan_frame.mean_value configure \
    1581             -text [format {%.2e} [usb::integrateBlt [myvar yvec] 1]]
    1582         ${config}.chan_frame.entr_value configure \
    1583             -text [usb::integrateBlt [myvar yvec] 0]
    1584 
    1585     }
    1586 
    1587 # -------------------------------------------------------------------------
    1588 
    1589     CntDisplay instproc axis_update args {
    1590         my instvar axis graph
    1591         if {$axis} {
    1592             $graph axis configure y -min 1 -max 1E5 -logscale yes
    1593         } else {
    1594             $graph axis configure y -min {} -max {} -logscale no
    1595         }
    1596     }
    1597 
    1598 # -------------------------------------------------------------------------
    1599 
    1600     CntDisplay instproc acquire {} {
    1601         my instvar controller config
    1602         my instvar cntr cntr_val recs recs_val
    1603 
    1604         set size 16384
    1605 
    1606         set prefix [format {%x} 8]
    1607 
    1608         set value [format {%08x} $size]
    1609 
    1610         set command 0001${prefix}000000200000001[string range $value 0 3]0003[string range $value 4 7]00050000
    1611 
    1612         $controller usbCmdReadRaw $command [expr {$size * 2}] [myvar data]
    1613 
    1614         set prefix [format {%x} 9]
    1615         set command 0001${prefix}000000200000003000400050000
    1616 
    1617         $controller usbCmdReadHex $command 8 1 [myvar cntr]
    1618 
    1619         set prefix [format {%x} 10]
    1620         set command 0001${prefix}000000200000003000400050000
    1621 
    1622         $controller usbCmdReadHex $command 8 1 [myvar recs]
    1623    }
    1624 
    1625 # -------------------------------------------------------------------------
    1626 
    1627     CntDisplay instproc save_data {data} {
    1628 
    1629         set types {
    1630             {{Data Files}       {.dat}        }
    1631             {{All Files}        *             }
    1632         }
    1633 
    1634         set stamp [clock format [clock seconds] -format %Y%m%d_%H%M%S]
    1635         set fname counts_${stamp}.dat
    1636 
    1637         set fname [tk_getSaveFile -filetypes $types -initialfile $fname]
    1638         if {[string equal $fname {}]} {
    1639             return
    1640         }
    1641 
    1642         set x [catch {
    1643             set fid [open $fname w+]
    1644             puts $fid $data
    1645             close $fid
    1646         }]
    1647 
    1648         if { $x || ![file exists $fname] || ![file isfile $fname] || ![file readable $fname] } {
    1649             tk_messageBox -icon error \
    1650                 -message "An error occurred while writing to \"$fname\""
    1651         } else {
    1652             tk_messageBox -icon info \
    1653                 -message "File \"$fname\" written successfully"
    1654         }
    1655     }
    1656 
    1657 # -------------------------------------------------------------------------
    1658 
    1659     CntDisplay instproc register {} {
    1660         my save_data [join [[myvar yvec] range 0 16383] \n]
    1661     }
    1662 
    1663 # -------------------------------------------------------------------------
    1664 
    1665     Class OscDisplay -parameter {
    1666         {master}
    1667         {controller}
    1668     }
    1669 
    1670 # -------------------------------------------------------------------------
    1671 
    1672     OscDisplay instproc init {} {
    1673         my instvar sequence data xvec yvec
    1674 
    1675         set data {}
    1676        
    1677         set sequence 0
    1678 
    1679 #        set xvec [vector create #auto(262144)]
    1680         set xvec [vector create #auto(10000)]
    1681 
    1682         for {set i 1} {$i <= 9} {incr i} {
    1683 #          dict set yvec $i [vector create #auto(262144)]
    1684           dict set yvec $i [vector create #auto(10000)]
    1685         }
    1686 
    1687         # fill one vector for the x axis
    1688 #        $xvec seq 0 262143
    1689         $xvec seq 0 10000
    1690 
    1691         my setup
    1692 
    1693         next
    1694     }
    1695 
    1696 # -------------------------------------------------------------------------
    1697 
    1698     OscDisplay instproc destroy {} {
    1699         next
    1700     }
    1701 
    1702 # -------------------------------------------------------------------------
    1703 
    1704     OscDisplay instproc start {} {
    1705         my instvar config
    1706         my instvar recs_val directory
    1707 
    1708         set directory $::env(HOMEPATH)
    1709         set recs_val 100
    1710 
    1711         trace add variable [myvar chan] write [myproc chan_update]
    1712 
    1713         trace add variable [myvar data] write [myproc data_update]
    1714 
    1715         trace add variable [myvar auto] write [myproc auto_update]
    1716 
    1717         trace add variable [myvar thrs] write [myproc thrs_update 0]
    1718         trace add variable [myvar thrs_val] write [myproc thrs_update 0]
    1719 
    1720         trace add variable [myvar recs_val] write [myproc recs_val_update]
    1721 
    1722         trace add variable [myvar last] write [myproc last_update]
    1723 
    1724         ${config}.chan_frame.chan1_check select
    1725         ${config}.chan_frame.chan2_check select
    1726         ${config}.chan_frame.chan3_check select
    1727         ${config}.chan_frame.chan4_check select
    1728         ${config}.chan_frame.chan5_check select
    1729         ${config}.chan_frame.chan6_check select
    1730 
    1731         ${config}.thrs_check select
    1732         ${config}.thrs_field set 100
    1733     }
    1734 
    1735 # -------------------------------------------------------------------------
    1736 
    1737     OscDisplay instproc setup {} {
    1738         my instvar master
    1739         my instvar xvec yvec graph
    1740         my instvar config
    1741 
    1742         # create a graph widget and show a grid
    1743         set graph [graph ${master}.graph -height 250 -leftmargin 80]
    1744         $graph crosshairs configure -hide no -linewidth 1 -color darkblue -dashes {2 2}
    1745         $graph grid configure -hide no
    1746         $graph legend configure -hide yes
    1747         $graph axis configure x -min 0 -max 10000
     948        $graph axis configure x -min 0 -max 60000
    1748949        $graph axis configure y -min 0 -max 4100
    1749950
     
    1791992            -bg yellow -activebackground yellow
    1792993
    1793         frame ${config}.spc6 -width 170 -height 10
     994        frame ${config}.spc6 -width 170 -height 30
    1794995
    1795996        button ${config}.recover -text {Read file} \
     
    19201121        if {$thrs} {
    19211122            ${config}.thrs_field configure -state normal
    1922             set value [format %03x $thrs_val]
     1123            set value [format {%03x} $thrs_val]
    19231124        } else {
    19241125            ${config}.thrs_field configure -state disabled
     
    19791180
    19801181#        set size 262144
    1981         set size 10000
     1182#        set size 10000
     1183        set size 60000
    19821184
    19831185        set value [format {%08x} [expr {$size * 4}]]
    19841186
    19851187        set command 00011000000200000001[string range $value 0 3]0003[string range $value 4 7]00050000
    1986        
     1188
    19871189        $controller usbCmdReadRaw $command [expr {$size * 8}] [myvar data]
    19881190
     
    20711273        }
    20721274
    2073         set stamp [clock format [clock seconds] -format %Y%m%d_%H%M%S]
     1275        set stamp [clock format [clock seconds] -format {%Y%m%d_%H%M%S}]
    20741276        set fname oscillogram_${stamp}.dat
    20751277
     
    20781280            return
    20791281        }
    2080    
     1282
    20811283        if {[catch {my save_data $fname} result]} {
    20821284            tk_messageBox -icon error \
     
    21151317        ${config}.register configure -state disabled
    21161318        ${config}.recover configure -state disabled
    2117        
     1319
    21181320        set recs_bak $recs_val
    21191321
     
    21401342            return
    21411343        }
    2142        
     1344
    21431345        my sequence_stop
    21441346    }
     
    21501352
    21511353        set sequence 0
    2152        
     1354
    21531355        set recs_val $recs_bak
    21541356
     
    21641366    namespace export MuxDisplay
    21651367    namespace export HstDisplay
    2166     namespace export CntDisplay
     1368    namespace export CfgDisplay
    21671369    namespace export OscDisplay
    21681370}
     
    21761378
    21771379::mca::UsbController usb
    2178 usb usbCmd 00000000
    2179 
    2180 set window [frame ${notebook}.spi]
    2181 $notebook insert end -text "DAC & ADC control" -window $window -fill both
    2182 ::mca::SpiDisplay spi -master $window -controller usb
    21831380
    21841381set window [frame ${notebook}.mux]
     
    21861383::mca::MuxDisplay mux -master $window -controller usb
    21871384
     1385set window [frame ${notebook}.cfg]
     1386$notebook insert end -text "Configuration" -window $window -fill both
     1387::mca::CfgDisplay cfg -master $window -controller usb
     1388
     1389set window [frame ${notebook}.hst]
     1390$notebook insert end -text "Histogram" -window $window -fill both
     1391::mca::HstDisplay hst -number 0 -master $window -controller usb
     1392
    21881393set window [frame ${notebook}.ept]
    21891394$notebook insert end -text "Oscilloscope" -window $window -fill both
     
    21921397update
    21931398
    2194 spi start
     1399cfg start
    21951400
    21961401mux start
    21971402
     1403hst start
     1404
    21981405osc start
    2199 
    2200 spi adc_reset
Note: See TracChangeset for help on using the changeset viewer.