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