Jump to content
  • 0

Setting recording length in Waveforms script


EZaro

Question

// Function to generate and capture a tone

function generateAndCaptureTone(frequency) {

 

print("generating tone with freq=", frequency);

 

Wavegen.Channel1.Mode.text = "Simple";

Wavegen.Channel1.Simple.Type.text = "Sine";

Wavegen.Channel1.Simple.Frequency.value = frequency;

Wavegen.Channel1.Simple.Amplitude.value = 1.0;

 

// Enable Scope capture

Scope.config();

Scope.Time.Mode.text = "Record";

Scope.Time.Trigger = "None";

Scope.Time.Rate.value = sampleRate;

Scope.Time.Samples.value = sampleRate * pulseTime_sec;

Scope.Channel1.fft = true;

Scope.Time.enable = true;

Scope.config();

 

print("Base="+Scope.Time.Base.real+" Samples="+Scope.Time.Samples.real+ " Rate="+Scope.Time.Rate.real);

 

Wavegen.run();

Scope.run();

 

 

 

// Run Wavegen for specified time

Scope.wait();

 

I have a script that steps up frequencies over a range. The script works almost as expected, except I'm running into a strange issue with applying the configuration of Scope.Rate, and Scope.Samples.

On the first run of this loop, the Scope configuration is always set to whatever the default or previous configuration of the system was. For example:

If the Scope's base was set in the manual configuration
- 150 kHz sample
- 3 s
- 450 k samples

When I run the script below, the print will read:
"Base=3 Samples=450000 Rate=150000"

Upon the next loop and step up, the configuration will take effect and it will read:

"Base=1.5 Samples=150000 Rate=10000"


I am having trouble understanding why this is taking a loop cycle for my setting changes to take effect. I don't see any reason for it in the script, unless I am using the Scope.config() method incorrectly? Any tips here would be greatly appreciated. Thanks!

 

// Scope config
var sampleRate = 100e3 // Sample rate in Hz

// Test variables
var startFrequency = 10; // Start frequency in Hz
var endFrequency = 120;  // Stop frequency in Hz
var stepFrequency = 10;   // Step frequency in Hz
var pulseTime_sec = 1.5; // Pulse time in sec

function runAndCaptureeFrequencySweep(startFreq, endFreq, length_sec){

    print("running with startFreq=" + frequency + " endFreq=" + endFreq + " length="+ length_sec + " sec");

    // Frequency sweep
    Wavegen.Channel1.Mode.text = "Sweep"
    Wavegen.Channel1.Sweep.Frequency.Start.value = startFreq;
    Wavegen.Channel1.Sweep.Frequency.Stop.value = endFreq;
    Wavegen.Channel1.Sweep.Frequency.Time.value = length_sec;
    Wavegen.Channel1.Sweep.enable = true;
    
    // Capture the sweep with Scope
    // Enable Scope capture
    Scope.Time.Mode.text = "Record";
    Scope.Time.Trigger = "None";
    Scope.Channel1.fft = true;
    Scope.Time.Rate.value = sampleRate;
    Scope.Time.Samples.value = sampleRate * length_sec;
    Scope.config();

    print("Base="+Scope.Time.Base.real+" Samples="+Scope.Time.Samples.real+ " Rate="+Scope.Time.Rate.real);

    Scope.run();
    Wavegen.run();
    
    
    Scope.wait();
    
    // Stop Wavegen and Scope
    Wavegen.stop();    
}

// Generate each stepped frequency
for(var freq = startFrequency; freq <= stopFrequency; freq += stepFrequency) {
    generateAndCaptureTone(freq);
    wait(0.5);
}

 

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Hi @EZaro

The .config() is only needed if you want your earlier changes to be applied immediately on the device, like adjusting Wavegen frequency. Otherwise the changes are applied  with run/stop call or sometime during next wait.
The .real represent the actual value, like the channel range of the current Scope capture.

See the Help tab and "Scope and Wavegen" under Example.

image.png

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...