Initialise to random values

profibusdp

Member
Join Date
Jan 2007
Location
california
Posts
1
Hi all,

Breaking my head on this one:
PLC: Siemens s7300
Programming language: STL/LAD
Q: Initialise an array of 100 data words with random values

Notes: 1) Hopefully can be done in 1 step (initialise)
2) DataBlock or Array or Table? Any will do...
 
Hello profibusdp;

If the question is : how to automate the initialization of an array of 100 words (you know of course that you can assign manually an initial value to any variable...):



-start by declaring your array, in a DB for example;

-create a loop (search this forum for indexed addressing, indirect addressing, you will find many good snippets of code in STL)

-in this loop, generate a random number (see below), store it in the first available un-initialized member of the array, then increment the pointer to the next member, and repeat until you have reached the ebnd of the array.

For the generation of a random number, here is a suggestion from Siemens' support website:

calculation of a random number with STEP 7



QUESTION:
How can you calculate random numbers between 0 and a specified upper limit?

ANSWER:
You can use the system function SFC64 "TIME_TCK" to generate a random number. From the system time you create the absolute value and then run an integer division with the upper limit as divisor. Determine the remainder left by this division operation. You can use this number as random number.







Hope this helps,

Daniel Chartier
 

Similar Topics

Hi All, I'm keep getting double quotes in between selections rather than the beginning and the end. Here's the script and please help to find...
Replies
7
Views
800
I've got an application where a robot is running 10 objects one after another past a camera so I need to buffer the result of the camera test...
Replies
20
Views
9,320
I got this error in Citect SCADA "Failed to Initialise Server Object Invalid Class String" I don't know what mistake I have made in Citect...
Replies
5
Views
6,158
Hi, when using the IEC timers in S7, I cannot put an intial value to the .PT (preset time), when generating the DBs for the IEC timers, the...
Replies
5
Views
10,478
Looking for some advice for backing up the programs on a bunch of old random PLCs. All I'm really concerned about is getting the program out of...
Replies
43
Views
4,709
Back
Top Bottom