Jump to content
  • 0

Logic analyzer custom protocol script problem


s4msepi0l

Question

Hi, as the title says, I'm tryng to analyze a custom protocol in the logic analyzer in WaveForms.

I can't disclose every detail but I can write some example code.

My problem is the following: my protocol has more than 32 bits per word, how can I pass a full word to the Value2Text function?

I tried to assign a byte array to the rgValue variable, I can confirm it works as intended through the debug window.

The Value2Text script however receives a 0 value parameter, not the array I assigned.

I took the SPI example and modified it, the relevant part is:

...
            // store rgValue/Flag from word start index to current sample position
            for(var j = iStart; j < i; j++){
                // Flag change will be visible on plot even when data remains constant.
                // This is useful in case we get more consecutive equal values.
                rgFlag[j] = cByte;
                rgValue[j] = bValue; // NOTE: here bValue is an array, not a byte
            }
...

And as I said, the value to text script:

function Value2Text(flag, value){
  // NOTE: value is 0
...

 

Thanks a lot for your help.

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

Hi @s4msepi0l

The Value and Flag are limited to 32bit.
If you need less than 64bits in total, you could store a part of in Flag. Note that Flag 0 is represented as idle/inactive, line in middle of the row.
Another solution is to split the words up, store and represent as consequent Values, like MSbits, LSbits

Link to comment
Share on other sites

  • 0

Hi @s4msepi0l

image.png

// rgData: input, raw digital sample array
// rgValue: output, decoded data array
// rgFlag: output, decoded flag array

var c = rgData.length // c = number of raw samples
var pClock = false; // previous cock signal level
var iStart = 0;     // used to keep track on word start index
var cByte = 0;      // byte count per transmission
var cBits = 0;      // bit counter
var bValue1 = 0;     // value variable
var bValue2 = 0;     // value variable

for(var i = 0; i < c; i++){ // for each sample
    var s = rgData[i]; // current sample
    var fSelect = 1&(s>>0); // pin0 is the select signal
    var fClock = 1&(s>>1); // pin1 is the clock signal
    var fData = 1&(s>>2); // pin2 is the data signal
    
    if(fSelect != 0){ // select active low
        // while select inactive reset our counters/variables
        iStart = i+1; // select might become active with next sample
        cByte = 0;
        cBits = 0;
        bValue1 = 0;
        bValue2 = 0;
        pClock = false;
        continue;
    }
    if(pClock == 0 && fClock != 0){ // sample on clock rising edge
        if(cBits<16){ // MSbs
            bValue1 <<= 1; // serial data bit, MSBit first
            if(fData)  bValue1 |= 1;
        }else{ // LSbs
            bValue2 <<= 1; // serial data bit, MSBit first
            if(fData)  bValue2 |= 1;
        }
        
        cBits++;
        if(cBits==48){ // when got the 8th bit of the word store it
            cByte++;
            // store rgValue/Flag from word start index to current sample position
            for(var j = iStart; j < i; j++){
                // Flag change will be visible on plot even when data remains constant.
                // This is useful in case we get more consecutive equal values.
                rgFlag[j] = (1+(cByte&1))|(bValue1<<16);
                rgValue[j] = bValue2;
            }
            iStart = i+1; // next word might start after this sample
            cBits = 0;  // reset bit count for the next byte
            bValue1 = 0; // reset value variable
            bValue2 = 0; // reset value variable
        }
    }
    pClock = fClock; // previous clock level
}

 

// value: value sample
// flag: flag sample

function Value2Text(flag, value){ // 16bit + 32bit
  switch(flag){
    case 0: return "X";
    default: {
        var sz = "00000000"+(value.toString(16).toUpperCase());
        sz = sz.substring(sz.length-8);
        sz = "0000"+((flag>>16).toString(16).toUpperCase())+sz;
        sz = sz.substring(sz.length-12);
        return "0x"+sz;
    }
  }
}
Value2Text(0x10000,2)

 

Link to comment
Share on other sites

  • 0

Many thanks for your suggestion.

Unfortunately it won't be enough because I need more than 64 bits.

At this point I think I should split the individual fields and give a flag to each of them, then print separately. That means having to do the heavy part in the decode script.

I would like the next version of Waveforms to support assigning arbitrary objects to rgValue, how can I make a suggestion?

Best regards

Link to comment
Share on other sites

  • 0

Hi, I think I have a similar problem with the custom script.
Given that in my case the acquisition format of the logic analyzer is 40-bits, I don't know how the signals beyond 32-bits can be accessed in the script. The array rgData seems to be limited to 32-bits, so the signals from bit 32 to 39 can't be referenced in the script.
Am I missing something?
Thanks for your support

Link to comment
Share on other sites

  • 0

Hi @leodom

The next version (v3.22.11) will pass the rgData in native JavaScript 64bit float data type with 54 bit fraction.

The bit operations seem to be performed as 32 bit signed value, so these need to be handled with care above 31 bit, like: add, divide, divrem... instead of: or, shift, mask...
image.png

image.png

image.png

image.png

Thank you for your post.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...