Jump to content
  • 1

Trying to control digital pins on digilent waveforms


Mohamad Idris

Question

I had posted this query earlier as well but to no use. I am trying to generate 4 signals at digital pins of ADP3450 using waveforms. Each signal has a frequency of 1khz/100hz with each signal having 1000 samples each. The fourth signal is much more straightforward and is on for the initial half-cycle and then off. 

In the first attempt, the "patterns" is used in BUS Mode with D0-D3 configured for generating these waveforms with a "Parameter1" frequency set using the formula frequency*numberof samples. However, this does not work as the frequency of one or two signals is incorrect on generation.     

To correct this I used a script but facing issues there as well. And I have pasted the code here 

// Check if the script is running in the WaveForms environment

if (typeof Patterns === 'undefined') {

throw "Please run this script in the WaveForms environment!";

}

 

// Define digital patterns

var amplitudes1 = [0, 5, 0, 5, 0, 5, 0, 5, 5, 0, 5, 0, 5, 0, 5, 0, 0, 5, 0, 5, 0, 5, 0, 5, 5, 0, 5, 0, 5, 0, 5, 0];

var amplitudes2 = [0, 0, 5, 5, 0, 0, 5, 5, 5, 5, 0, 0, 5, 5, 0, 0, 0, 0, 5, 5, 0, 0, 5, 5, 5, 5, 0, 0, 5, 5, 0, 0];

var amplitudes3 = [0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0];

var durations_us = [300, 200, 200, 250, 250, 300, 450, 550, 550, 450, 300, 250, 250, 200, 200, 300, 300, 200, 200, 250, 250, 300, 450, 550, 550, 450, 300, 250, 250, 200, 200, 300];

 

// Initialize Pattern Generator

var Patterns = new Wavegen.WaveformManager();

Patterns.setup();

 

// Set up digital channels

Patterns.channels = [

{ enabled: true, mode: 'digital', values: amplitudes1 },

{ enabled: true, mode: 'digital', values: amplitudes2 },

{ enabled: true, mode: 'digital', values: amplitudes3 }

];

 

// Configure digital channels

Patterns.channels.forEach((channel, index) => {

if (channel.enabled) {

Patterns.setupChannel(index, channel.mode);

channel.values.forEach((value, i) => {

Patterns.add(index, value, durations_us[i] / 1e6); // Convert microseconds to seconds

});

Patterns.setSampleRate(1e6); // Set sample rate to 1 MHz

Patterns.configure(index);

}

});

 

// Start the Pattern Generator

Patterns.start();

 

// Wait for a certain amount of time (adjust as needed)

wait(10); // Run for 10 seconds

 

// Stop the Pattern Generator

Patterns.stop();

I am getting a parse error 

Any help would be highly appreciated

 

Switching_logic.png

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Thanks for the reply @attila can you please guide how can we generate these waves using the "patterns" while keeping in view the issues I am facing? I have attached a snapshot of the generated waveforms of different frequencies for your reference.   

1Mhz.png

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