Jump to content
  • 0

Script Editor: Change duty ratio of a clock pattern every cycle


gupta

Question

Hello, I am a new user of Analog Discovery 2 device. I would like to output a pattern at DIO1 (for example) wherein the duty ratio is selected from a look-up table. I am trying to use the Script Editor. However, I am unsure what function/variable I should use to increment the index for the look-up table such that at the beginning of every cycle, the clock has the updated duty ratio. Here is a snapshot of my dummy code:

clear()

if(!('Patterns' in this)) throw "Please open a Patterns instrument";

var values = [10, 20, 30, 40, 50, 60, 70, 80, 90, 95];

Patterns.run();

for(var idx = 0; idx < 10; idx++){

	var d = values[idx];

	wait(FOR AN EDGE-TRIGGER OR SOME SIMILAR CLOCK EVENT) // I am unsure if wait is the correct choice. 

	Patterns.Channels.DIO1.Duty.value = d;

	idx = idx+1;

}

// Assuming that DIO1 has a set frequency of 1kHz, the duty should change from 10% to 95% every 1kHz in steps as listed in variable 'values'.

Any insights would be helpful.

 

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

Hi @gupta

You can create a custom pattern with such duty factors.

With the default configuration of AD2 you have 1ki samples for such custom pattern but with the 4th device configuration up to 16ki.

The pattern can be created in WaveForms Pattern Custom Editor, external spreadsheet editor exported/imported csv, or with the Script tool like this:

var duty = [10, 20, 30, 40, 50, 60, 70, 80, 90, 95];
var data = []
const res = 20
duty.forEach(function(d){ for(var i = 0; i < res; i++) data.push(i>=res*d/100?0:1)})
Patterns.Channels.DIO1.custom = data

if(Patterns.Channels.DIO1.custom.length!=data.length) print("too many samples",data.length)
else print("done", data.length)

image.thumb.png.0bf447a2104d25b81af0b84bb1e6b69b.png

image.png.bcc9a6f4bc12cacae0f8a5c17c4f8c9f.png

Link to comment
Share on other sites

Hi @attila

Thank you for your reply. 

I have solved it. It was the problem of channel. As I am using digital discovery Digital Channel 1 can not be used for generation.

have another problem if you can help, even I have already posted in forum.

I want to generate the two patterns but some deadtime between them.

pattern_deadtime.png

Link to comment
Share on other sites

Hi @ravikyo

Yes, you can type in any desired value.

The device can generate natural (2+) divisions of base frequency (default 100MHz)

With Digital Discovery the base freq is adjustable in the Supply tool. This can be useful if you want to fine adjust high frequency signals.

image.png.5aacdfaa69df4081ac1789727e1cf580.png

image.png.c1dcfef6282c4541eeb8f5fabd3d5fec.png

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...