Jump to content

attila

Technical Forum Moderator
  • Posts

    6,651
  • Joined

  • Last visited

Posts posted by attila

  1. Hi @Empower

    Move start_index = sample_index + 1;

    image.png

     

    like in the included example:

    image.png

     

    // This scripted is intended for use with Digilent Analog Discovery 3.
    // Refer to https://digilent.com/reference/test-and-measurement/guides/waveforms-script-editor
    
    // rgData: input, raw digital sample array
    // rgValue: output, decoded data array
    // rgFlag: output, decoded flag array
    
    var sample_count    = rgData.length // sample_count = number of raw samples
    var previous_clock  = false;        // previous cock signal level
    var start_index     = 0;            // used to keep track on word start index
    var sbus_bit_count  = 0;            // byte count per transmission
    var bit_count       = 0;            // bit counter
    var bit_value       = 0;            // bit value 
    var byte_value      = 0;            // byte value
    var sbus_bit        = 0;            // sbus bit
    var num_sbus_bits   = 0;
    var sbus_byte_count = 0;
    
    for (var sample_index = 0; sample_index < sample_count; sample_index++) { // for each sample
        var current_sample = rgData[sample_index]; // current sample
        // var chip_select_pin = 1 & (current_sample >> 0); // pin0 is the select signal
        var clock_pin = 1 & (current_sample >> 1); // pin1 is the clock signal
        var data_pin = 1 & (current_sample >> 2); // pin2 is the data signal
    
        // if (chip_select_pin != 0) { // select active low
            // // while select inactive reset our counters/variables
            // start_index = sample_index+1; // select might become active with next sample
            // sbus_bit_count = 0;
            // bit_count = 0;
            // bit_value = 0;
            // previous_clock = false;
            // continue;
        // }
        if (previous_clock == 0 && clock_pin != 0) { // sample on clock rising edge
            bit_value <<= 1; // serial data bit, MSBit first
            
            if (data_pin) bit_value |= 1;
            bit_count++;
            
            if (bit_count == 2) { // when got the 2nd bit of the word store it
                sbus_bit_count++;
                
                if (bit_value == 0) {
                    num_sbus_bits = 1;
                    sbus_bit = 0; // "S" Start
                }
                else if (bit_value == 1) {
                    num_sbus_bits = 8;
                    sbus_bit = 1;
                }
                else if (bit_value == 2) {
                    num_sbus_bits = 8;
                    sbus_bit = 0;
                }
                else {
                    num_sbus_bits = 1;
                    sbus_bit = 1; // "P" Stop, End of Message  
                }
                byte_value = (sbus_bit << (7 - (sbus_bit_count - 1))) | byte_value;
                if (sbus_bit_count == num_sbus_bits) { // when got the 2nd bit of the word store it
                    sbus_byte_count++;
                    
                    // store rgValue/Flag from word start index to current sample position
                    for (var j = start_index; j < sample_index; j++) {
                        // rgFlag and rgValue used in Value2Text()
                        // Flag change will be visible on plot even when data remains constant.
                        // This is useful in case we get more consecutive equal bit_values.
                        rgFlag[j] = sbus_bit_count; // If rgFlag[] is > 0, waveform is displayed
                        rgValue[j] = byte_value;
                    }
                    start_index = sample_index + 1; // next word might start after this sample
                    byte_value = 0;
                    sbus_bit_count = 0;
                }
                bit_value = 0; // reset bit_value variable
                bit_count = 0;  // reset bit count for the next byte
            }
        }
        previous_clock = clock_pin; // previous clock level
    }

     

  2. Hi @fizzbang

    The Analog Discovery 1,2,3 oscilloscope inputs are suitable for such measurements since these are differential.

    To measure the entire filter: channel 2 measured relative to 1.

    image.png

    To measure just the second part influence: channel 2 measured relative to 1.
    In this case channel 1 absolute measurement will represent the first part only if the load does not cause W1 to drop.

    image.png

  3. Hi @miketranch

    You should not leave any together used device floating since the communication between these would not work, unless you use dedicated isolator.
    Voltage is potential difference ! You need to have a common or known relative level.

    You could use different reference voltage for the DUT, like the GND of this to be connected to +0.9V relative to the AD2 GND. A 0.9V floating supply negative to be at AD-GND and positive at DUT-GND or use the AD V+ supply. This way the AD's 0V will be -0.9V for the DUT and for AD's +0.9V be 0V for the DUT.
    Note, the AD-GND is connected to the computer GND via USB cable and this, depending on the computer supply, this may be connected to mains earth.
    A wrong connection, like earth referenced supply output connected to AD GND will be a short circuit that could damaged the devices !

    Usually, the safest option is to use the same GND for all devices and generate negative pulses.

    image.png

     

×
×
  • Create New...