Changeset 4610


Ignore:
Timestamp:
08/26/08 04:54:54 (5 years ago)
Author:
werner
Message:

Support for full waveform retrieval with DS1000CD. This allows decoding of
SPI (and SD) sequences of up to about 50kbits.

  • lib/scope.py (scale_125): improved tolerance against rounding errors
  • lib/scope.py: added full-depth retrieval for analog and digital waves
  • lib/scope.py: give credit to rew's Rigol interface program
  • lib/scope.py: send parameters of horizontal system only in non-exponential format (exponents confuse the Rigol)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • developers/werner/ahrt/host/tmc/lib/scope.py

    r4608 r4610  
    44#  
    55 
    6 # Found screen dump algorithm here: 
     6# Found Rigol screen dump algorithm here: 
    77# http://www.circuitsonline.net/forum/view/message/652573#652573 
     8# 
     9# Rigol data retrieval is heavily based on 
     10# http://prive.bitwizard.nl/rigol/rigol-0.1rew3.tgz 
     11# 
    812 
    913# 
     
    2428 
    2529def scale_125(n = None, fuzz = None, min = None, max = None): 
     30    epsilon = 1e-15 
    2631    res = None 
    2732    for e in range(-9, 1+1): 
     
    3439            if n is not None and r >= n*(1-fuzz) and r <= n*(1+fuzz): 
    3540                return s 
    36             if min is not None and r >= min: 
     41            if min is not None and r >= min-epsilon: 
    3742                return s 
    38             if max is not None and r <= max: 
     43            if max is not None and r <= max+epsilon: 
    3944                res = s 
    4045    if res is not None: 
     
    108113 
    109114    def wave(self, start = None, end = None, step = None): 
    110         width = self.scope.div_hor*self.scope.hor.scale 
    111         if start is None and end is None: 
    112             start = self.scope.hor.pos 
    113         if start is not None and end is None: 
    114             end = start+width 
    115         elif start is None and end is not None: 
    116             start = end-width 
    117         if step is None: 
    118             return self.scope.download_wave(self, start, end, None) 
    119         else: 
    120             # @@@ put setting the horizontal system into download_wave 
    121             if step*self.scope.sampling_rate() < 1: 
    122                 raise hell 
    123             span = step*self.scope.samples_per_div*self.scope.div_hor 
    124             if False and span >= start-end: 
    125                 return self.scope.download_wave(self, start, end, None) 
    126             else: 
    127                 scale = float(scale_125(max = step*self.scope.samples_per_div)) 
    128                 orig_pos = self.scope.hor.pos 
    129                 orig_scale = self.scope.hor.scale 
    130                 self.scope.hor.scale = scale 
    131                 span = self.scope.div_hor*self.scope.hor.scale 
    132                 wave = analog_wave() 
    133                 pos = start 
    134                 while pos < end: 
    135                     self.scope.hor.pos = pos 
    136                     wave.extend(self.scope.download_wave(self, pos, pos+span, 
    137                       None)) 
    138                     pos += span 
    139                 self.scope.hor.pos = orig_pos 
    140                 self.scope.hor.scale = orig_scale 
    141                 return wave 
     115        # @@@ move start and end adjustment here ! 
     116        return self.scope.download_wave(self, start, end, step) 
    142117 
    143118 
     
    150125        self.scope = scope 
    151126        self.pos = setting(scope, ":TIM:OFFS", 
    152           lambda x: float(x)) 
     127          lambda x: float(x), 
     128          lambda x: "%.9f" % x) 
    153129        self.scale = setting(scope, ":TIM:SCAL", 
    154           lambda x: float(x)) 
     130          lambda x: float(x), 
     131          lambda x: "%.9f" % x) 
    155132        self.forget() 
    156133 
     
    265242 
    266243 
     244def rigol_wave(scope, start, end, step, query, merge, fn, *args): 
     245    wave = None 
     246    orig_pos = scope.hor.pos 
     247    orig_scale = scope.hor.scale 
     248 
     249    width = scope.div_hor*orig_scale 
     250    if start is None: 
     251        start = orig_pos-width/2 
     252    if end is None: 
     253        end = orig_pos+width/2 
     254    if step is None: 
     255        step = 1/scope.sampling_rate() 
     256 
     257    scope.hor.scale = float(scale_125(max = step*scope.samples_per_div)) 
     258    while start < end: 
     259        scope.hor.pos = start+6*scope.hor.scale 
     260        data = scope.query(query) 
     261        data = fn(data, scope.hor.pos, scope.hor.scale, *args) 
     262        if wave is None: 
     263            wave = data 
     264        else: 
     265            merge(wave, data) 
     266        start += 12*scope.hor.scale 
     267 
     268    scope.hor.pos = orig_pos 
     269    scope.hor.scale = orig_scale 
     270    return wave 
     271 
     272 
     273def rigol_extend_la(a, b): 
     274    i = 0 
     275    while i != 16: 
     276        a[i].extend(b[i]) 
     277        i += 1 
     278 
     279 
    267280def rigol_to_ppm(s): 
    268281    lut = [] 
     
    283296    div_hor = 12 
    284297    div_vert = 10 
    285     samples_per_div = 600       #@@@ not exactly true. needs more investigation 
     298    samples_per_div = 50 
    286299 
    287300    def __init__(self): 
     
    322335            if self.ch[n] == channel: 
    323336                c_num = n+1 
    324         data = self.query(":WAV:DATA? CHAN"+str(c_num)) 
    325         return rigol_channel_data(data, self.hor.pos, self.hor.scale, 
    326            channel.pos, channel.scale) 
     337        return rigol_wave(self, start, end, step, 
     338          ":WAV:DATA? CHAN"+str(c_num), 
     339          lambda a, b: a.extend(b), 
     340          rigol_channel_data, channel.pos, channel.scale) 
    327341 
    328342    # experimental 
    329343 
    330     def download_la(self): 
    331         data = self.query(":WAV:DATA? DIG") 
    332         return rigol_la_data(data, self.hor.pos, self.hor.scale) 
     344    def download_la(self, start = None, end = None, step = None): 
     345        return rigol_wave(self, start, end, step, 
     346          ":WAV:DATA? DIG", 
     347          rigol_extend_la, rigol_la_data) 
    333348 
    334349    def sampling_rate(self): 
Note: See TracChangeset for help on using the changeset viewer.