diff options
author | Karl Palsson <karlp@etactica.com> | 2017-01-20 16:24:29 +0000 |
---|---|---|
committer | Uwe Hermann <uwe@hermann-uwe.de> | 2017-05-13 16:11:27 +0200 |
commit | b8c44f69b0f12c2cee2b9765abca8e0b3e751b43 (patch) | |
tree | 302841ddb980fbfd842b70aff7bfc32e0a4386ea /decoders/timing/pd.py | |
parent | 82738302754039cffb4ee84b2fa9b1450612a5e3 (diff) | |
download | libsigrokdecode-b8c44f69b0f12c2cee2b9765abca8e0b3e751b43.tar.gz libsigrokdecode-b8c44f69b0f12c2cee2b9765abca8e0b3e751b43.zip |
timing: add edge-edge mode and delta calculation
Instead of only measuring the timing from any edge to any edge, provide
a mode to measure the times from falling->falling and rising->rising
edges. This works better to monitor timing of an IRQ pin for instance,
that drives one direction under hardware, and is only cleared by
software reading a value.
Include time delta measurements as an optional annotation to help track
jitter in measurements.
Signed-off-by: Karl Palsson <karlp@etactica.com>
Diffstat (limited to 'decoders/timing/pd.py')
-rw-r--r-- | decoders/timing/pd.py | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/decoders/timing/pd.py b/decoders/timing/pd.py index 01e3b01..b694c1d 100644 --- a/decoders/timing/pd.py +++ b/decoders/timing/pd.py @@ -60,13 +60,17 @@ class Decoder(srd.Decoder): annotations = ( ('time', 'Time'), ('average', 'Average'), + ('delta', 'Delta'), ) annotation_rows = ( ('time', 'Time', (0,)), ('average', 'Average', (1,)), + ('delta', 'Delta', (2,)), ) options = ( { 'id': 'avg_period', 'desc': 'Averaging period', 'default': 100 }, + { 'id': 'edge', 'desc': 'Edges to check', 'default': 'any', 'values': ('any', 'rising', 'falling') }, + { 'id': 'delta', 'desc': 'Show delta from last', 'default': 'no', 'values': ('yes', 'no') }, ) def __init__(self): @@ -75,6 +79,8 @@ class Decoder(srd.Decoder): self.last_samplenum = None self.last_n = deque() self.chunks = 0 + self.level_changed = False + self.last_t = None def metadata(self, key, value): if key == srd.SRD_CONF_SAMPLERATE: @@ -82,44 +88,39 @@ class Decoder(srd.Decoder): def start(self): self.out_ann = self.register(srd.OUTPUT_ANN) + self.edge = self.options['edge'] self.initial_pins = [0] def decode(self): if not self.samplerate: raise SamplerateError('Cannot decode without samplerate.') while True: - pin = self.wait({0: 'e'}) + if self.edge == 'rising': + pin = self.wait({0: 'r'}) + elif self.edge == 'falling': + pin = self.wait({0: 'f'}) + else: + pin = self.wait({0: 'e'}) - if self.oldpin is None: - self.oldpin = pin + if not self.last_samplenum: self.last_samplenum = self.samplenum continue + samples = self.samplenum - self.last_samplenum + t = samples / self.samplerate - if self.oldpin != pin: - samples = self.samplenum - self.last_samplenum - t = samples / self.samplerate - self.chunks += 1 + if t > 0: + self.last_n.append(t) + if len(self.last_n) > self.options['avg_period']: + self.last_n.popleft() - # Don't insert the first chunk into the averaging as it is - # not complete probably. - if self.last_samplenum is None or self.chunks < 2: - # Report the timing normalized. - self.put(self.last_samplenum, self.samplenum, self.out_ann, - [0, [normalize_time(t)]]) - else: - if t > 0: - self.last_n.append(t) + self.put(self.last_samplenum, self.samplenum, self.out_ann, + [0, [normalize_time(t)]]) + if self.options['avg_period'] > 0: + self.put(self.last_samplenum, self.samplenum, self.out_ann, + [1, [normalize_time(sum(self.last_n) / len(self.last_n))]]) + if self.last_t and self.options['delta'] == 'yes': + self.put(self.last_samplenum, self.samplenum, self.out_ann, + [2, [normalize_time(t - self.last_t)]]) - if len(self.last_n) > self.options['avg_period']: - self.last_n.popleft() - - # Report the timing normalized. - self.put(self.last_samplenum, self.samplenum, self.out_ann, - [0, [normalize_time(t)]]) - if self.options['avg_period'] > 0: - self.put(self.last_samplenum, self.samplenum, self.out_ann, - [1, [normalize_time(sum(self.last_n) / len(self.last_n))]]) - - # Store data for next round. - self.last_samplenum = self.samplenum - self.oldpin = pin + self.last_t = t + self.last_samplenum = self.samplenum |