Clock Stats

Hi everyone

I was wondering if anyone has used the “clock stats” extension on Logic2 software? If so, do you know if it is possible to use it to look at two channels/signals and find the time difference between the two signals?

Also, is it possible to develop extensions that look at multiple channels at the same time and produce statistics?

Thank you

Clock Stats can’t do that trick. You can set timing markers (Ctrl T on Windows or use the Measure menu) on events of interest on different channels and get the time between events that way. You can also set “time 0” to a timing marker (right click on the marker’s number flag) and read off times of events relative to that marker.
This sort of question comes up a lot in various guises. Ideas topics that are related are: Measurement Extensions to Support Multiple Channels - Logic 2 - Ideas and Feature Requests - Saleae, HLA - Support multiple LLA inputs - Logic 2 - Ideas and Feature Requests - Saleae and Virtual math channels and analog transformation functions - Logic 2 - Ideas and Feature Requests - Saleae.

1 Like

@P.Jaquiery

I have also noticed that Logic2 allows you to write extensions to calculate features that you require. Do you think it would be possible write an extension to calculate the time differences between two events/two channels and generate a table that way, over a period of time? To clarify, I am interested in finding the time difference between the two channels as time passes, for example initially there could be no time difference and as time passes there could be multiple time difference and I am interested in a generating a table of these time differences.
Please let me know if you think, there is already a feature on Logic2 that does this for you.

Thank you

At present you can’t use data from multiple channels in a single High Level Analyzer (the simplest option for this analysis). If you need the results “live” it could, I presume, be done with a Low Level Analyzer written in C++, but I have no experience in writing LLAs for Logic.

If you just need to do the analysis after recording the data you could export the data as a CSV file and analyze it using Python or some other language. Both this option and the LLA option require programming skills. The LLA option is likely to require more coding experience and would be harder to debug than the offline analysis option.

@P.Jaquiery, Do you think it would possible to write two “HLAs”, one for each channel, and write a third one to make the two other channels to communicate with each other and perform the calculations?

If you think that would be too complicated/not possible, I could try to use LLAs (if it is possible). I am sort of comfortable with C++.

Also, Thank you for your input @P.Jaquiery

Communication between HLAs is a much wished for facility for Logic 2, but it isn’t available yet so no, it’s not possible at present to combine the output of two HLAs using a third HLA.

If you are interested in following up the LLA option you should start at Protocol Analyzer SDK - Saleae Support.

Thank you @P.Jaquiery

I think I am going to get around the problem by writing a “HLA” that calculates the time for one channel and save the data on a CSV file, and then use the same “HLA” for the second channel to find the time for the second channel and then save the data on a “CSV” file. After write a python file to separately analyses the two “CSV” files.

This is becasue I am not sure how complicated it would be to write a “LLA”.

Let me know what you think about it.
Thank you

You don’t need to work that hard. Just use the File|Export menu to export a CSV file containing the raw data for the channels of interest. You will end up with something like:

Time [s],GRNLed,I2C-0
2022-06-08T02:26:50.443047700+00:00,1,0
2022-06-08T02:26:50.591667628+00:00,0,0
2022-06-08T02:26:50.591946212+00:00,0,1

where the first row contains the column headers then the following rows contain a time stamp and the state of each channel when any channel changes state.

@P.Jaquiery Just to confirm the column “start” in the row data, does that contain, specific time where the period repeat itself. Because I did think of that but I was not sure if the “time” the specific time that I am after.

Have a look at the attached picture for better visual understanding.

The time at the start of each row is the nominal host computer time when an event (at least one signal changed state) happened.

The following (Perl) code:

use strict;
use warnings;

my $path = 'D:\Scratch~~\digital.csv';

open my $fIn, '<', $path or die "Can't open '$path': $!";

<$fIn>; # Skip column header row

my $lastLED;
my $lastI2C;
my $lastFallingLED;

while (my $line = <$fIn>) {
    chomp $line;

    my ($time, $led, $i2c) = split ',', $line;

    $lastLED //= $led;
    $lastI2C //= $i2c;

    my $fallingLED = $lastLED && !$led;
    my $risingI2C = !$lastI2C && $i2c;

    $lastLED = $led;
    $lastI2C = $i2c;

    # Record time if this is a falling LED edge
    $lastFallingLED = $time if $fallingLED;

    next if !$risingI2C || !$lastFallingLED;

    # have a I2C rising edge following or synchronous with a LED rising edge
    my $ledSeconds = ExtractSeconds($lastFallingLED);
    my $i2cSeconds = ExtractSeconds($time);
    my $delta = $i2cSeconds - $ledSeconds;

    $delta += 60.0 if $delta < 0;
    print "$lastFallingLED: delta $delta\n";
    $lastFallingLED = undef;
}


sub ExtractSeconds {
    my ($timeStamp) = @_;
    my ($seconds) = $timeStamp =~ /(\d+\.\d+)/;

    return $seconds;
}

run against the data:

Time [s],GRNLed,I2C-0
2022-06-08T02:26:50.443047700+00:00,1,0
2022-06-08T02:26:50.591667628+00:00,0,0
2022-06-08T02:26:50.591946212+00:00,0,1
2022-06-08T02:26:50.616669900+00:00,1,1
2022-06-08T02:26:50.616948764+00:00,1,0
2022-06-08T02:26:51.091749972+00:00,0,0
2022-06-08T02:26:51.092027940+00:00,0,1
2022-06-08T02:26:51.116758444+00:00,1,1
2022-06-08T02:26:51.117036492+00:00,1,0
2022-06-08T02:26:51.591834684+00:00,0,0
2022-06-08T02:26:51.592113260+00:00,0,1

generates:

2022-06-08T02:26:50.591667628+00:00: delta 0.000278584000000137
2022-06-08T02:26:51.091749972+00:00: delta 0.000277967999998907
2022-06-08T02:26:51.591834684+00:00: delta 0.000278575999999475

which is a list of the times between falling edges on the GRNLed line and the next rising edge on the I2C-0 line. The time stamp is the time of the GRNLed falling edge. I should note that Perl is my “go to” scripting language so I could knock up the example code more quickly than I would with Python.

@P.Jaquiery

how is your scrip connected/communicating to logic2 that it can collect the time?
I had a quick look at your code but could not understand that part!

Also to give you a bit of backgrounds I am trying to do this:

but in real time using Saleae and Log2. I am not sure if it is possible or if it is the best of doing it!

Do you know Saleae and Log2 well enough to clarify these points for me please:
1- can you continuously feed in data into Saleae and logic2 and analyse the data in real time? I know I am may need to write a LLA to do this but I am not sure if the data gets saved on Saleae and logic 2 or you can just feed the data in and use them as analysing poplin?
2- can you extract the time in real time from the two channels in logic2 and feed them into a another source, eg python for further analysis?

I am trying to understand Saleae and Logic2 better, please let me know if you have any recommendation on that.
Thank you

Bottom line: it can’t currently be done easily (it may be possible with an LLA). The code I posted runs against data exported after sampling stops. There is no simple way I am aware of to show clock sync between channels in real time.

The equivalent Python code is:

import re

def ExtractSeconds (timeStamp):
    matched = re.search(r"(\d+\.\d+)", timeStamp)
    return float(matched.expand(r"\1"))

path = 'D:\Scratch~~\digital.csv'

fIn = open(path, mode = 'rt')

fIn.readline() # Skip column header row

lastLED = None
lastI2C = None
lastFallingLED = None
line = None

for line in fIn:
    line = line.rstrip('\n')

    (time, led, i2c) = line.split(',')

    if lastLED == None: lastLED = led
    if lastI2C == None: lastI2C = i2c

    fallingLED = lastLED == '1' and led == '0'
    risingI2C =  lastI2C == '0' and i2c == '1'

    lastLED = led
    lastI2C = i2c

    # Record time if this is a falling LED edge
    if fallingLED: lastFallingLED = time

    if not risingI2C or not lastFallingLED: continue

    # have a I2C rising edge following or synchronous with a LED rising edge
    ledSeconds = ExtractSeconds(lastFallingLED)
    i2cSeconds = ExtractSeconds(time)
    delta = i2cSeconds - ledSeconds

    if delta < 0: delta += 60.0
    print(str(lastFallingLED) + ": delta " + str(delta))

@P.Jaquiery
Assuming that it can’t be done, can I clarify a few things about Saleae and Logic2.

If I have two channels connected to Saleae and then Logic2, are the time for the two channels in sync when you press record? I mean when the measurement starts, does it start at the same time for both channel one and channel two?

I still do not understand, how you are receiving/saving the time from each channel into a “CSV file”? After you are passing on that “CSV file” into you python file for further analysis to find the time difference right?

Thank you @P.Jaquiery

The article What Is the Worst Case Channel to Channel Skew? - Saleae Support says the worst case slew between channels is one sample time so you can consider that all channels start within one sample time.

I used the File|Export Data… menu to save the captured data as a .csv file. I run the analysis code from the equivalent of a command line.

@P.Jaquiery Have a look at the picture that I have attached, and the time that I have highlighted. Is the time on a the picture the time that were interested? Each channel will have its separate time.