Activation of random inputs/outputs?

asteroide

Member
Join Date
Jul 2010
Location
der
Posts
155
Hello Friends

I need to activate random outputs (0-9) and ask for random inputs (0-9).

I have created in s71200 a program to generate a random number in Dint, but how can i move this number to an output or input?

Thanks in advance.
 
Last edited:
Hello asteroide:
Not sure if I understand your inquiry. You can move data from a program variable to an output by means of MOVE command. However, the only way that you can see reflected the generated random number in an input is if you hard-wire the physical output module (to which you move the randomly generated data) to the physical input modules. I do not know if my explanation makes sense.

2021-05-01_Move_data_S7.png
 
Alfredo, I looked at this one but did not reply & it did not really make sense, moving values to inputs? as you say only driving output to turn on inputs but that does not make sense, random number to outputs, could look at this two ways transfer the binary bit pattern to outputs, not what I think the OP means, is to generate a random number then turn on the output i.e. if number was 2 then turn on output 2 if 0 turn on output 0 etc. the OP needs to be a little more specific if they want a valid answer.
A couple of ways if it is number to output number, indirectly point to the output (not always possible with octal addressing), or just do 9 compares and enable the output.
 
Hello Friends

I should explain better.

I need to program a game of 10 button-light.

The game turns on the lights in a random sequence and you should push the button of this light in x seconds.

For example:

(output 5) turn on ligth 5 - push button 5 (input 5)
(output 3) turn on light 3 - push button 3 (input 3)
(output 8) turn on light 8 - push button 8 (input 8)
and so on.

I have created a Dint Random Number but I do not know how to move to an inputs and outputs.

Thanks again
 
Last edited:
If OP is asking how to extract bits from a random DInt, to get random bits, in Portal, then here is one approach:

If there are only 10 outputs, then the program only needs a 16-bit, or even 11-bit*, random number. So an Int would suffice. But any ten bits above bit 0 a DInt will work:

xxx.png

* if the RNG is an LCG, then the low bit alternates and is not random
 
Last edited:
Hello Friends

I should explain better.

I need to program a game of 10 button-light.

The game turns on the lights in a random sequence and you should push the button of this light in x seconds.

For example:

(output 5) turn on ligth 5 - push button 5 (input 5)
(output 3) turn on light 3 - push button 3 (input 3)
(output 8) turn on light 8 - push button 8 (input 8)
and so on.

I have created a Dint Random Number but I do not know how to move to an inputs and outputs.

Thanks again

Asteroide, just for clarification, please. Can you confirm if my understanding of your game is correct? Your program generates a number out of which it selects on output lamp and turns it on (one out of 16 lamps for the game console). Then what happens? It seems to me that the lamp is physically housed inside a push button, and this push button must be pushed by the person playing the game, correct? Meaning the push button is wired to the PLC's digital input module and the lamp is wired to the PLC's digital output module. But they externally look like the same device (push-button, lamp device).

If the above is correct, all you need is to use the MOVE statement for the %IW offset where the input module is configured, and move it to a DINT variable for your random number generator. The generated random number is then moved to the %QW offset where the output module is configured.
 
It is correct, the game works like you said.

As I have to use more than 8 bits, I am doing 9 compares to move data, I do not know if it is possible with a simple instruction like Move.

My knowledge in Siemens is not enough.

Thanks again.



Asteroide, just for clarification, please. Can you confirm if my understanding of your game is correct? Your program generates a number out of which it selects on output lamp and turns it on (one out of 16 lamps for the game console). Then what happens? It seems to me that the lamp is physically housed inside a push button, and this push button must be pushed by the person playing the game, correct? Meaning the push button is wired to the PLC's digital input module and the lamp is wired to the PLC's digital output module. But they externally look like the same device (push-button, lamp device).

If the above is correct, all you need is to use the MOVE statement for the %IW offset where the input module is configured, and move it to a DINT variable for your random number generator. The generated random number is then moved to the %QW offset where the output module is configured.
 
Asteroide, yes it is possible. Just make sure the variable in the program is DINT and that the address in the IO area is either %IW or %QW. ¡Buena suerte!
 
I'm still confused, perhaps my age, is the random number going to be sent as a binary bit pattern to the outputs ? or is it a number only turns on the respective bit, if respective bit i.e. only one output on at a time then move is not what is required, you would have to do 10 compares one for each output/number.
for example the random generator stops at 6 then only output 6 needs to be on.
example:

If random = 0 then output 0
if random = 1 then output 1
and so on.
If more than one light can be on then you could do a move instruction however, this would need to be moved into a 16 bit address or via a mask which makes it difficult to use those spare outputs.
the other way is to use a function integer to bit then use those bits to enable the outputs.
 
Whack-a-mole may be possible with indirect/indexed/* addressing (but I am not sure if it is any better than brute force):

  1. Step 0
    1. Put 0s in all elements of Boolean array output
    2. Generate a random number, RNG in the range 0 to N-1
    3. Put a 1 in element output[RNG]
    4. The RLO of NO(output[RNG]) goes to output/coil/* %DQ[RNG], which turns on light RNG when output[RNG] is 1
      1. I suspect %DQ[RNG] is not valid syntax, so this might require 10 expressions/rungs
      2. In ST (SCL?), could the output array be in a union with %DQs?
    5. Start a TON timer; the player has until it completes to press button RNG
    6. Save the number RNG
    7. Change step number to 10
  2. Step 10
    1. Copy all 10 button inputs, plus the timer .Q bit, into the eleven bits, 0-10, of an integer IBITS, ensuring all other bits of IBITS are 0
      1. Again, I suspect this may require 11 expressions
    2. If IBITS is not 0
      1. Test if IBITS.[RNG] (again, not sure about syntax)
        1. If 1, then player pushed the correct button within the time limit; record success event e.g. green light
        2. If 0, then player did not push the correct button within the time limit; record failure event e.g. red light
    3. Reset timer
    4. Change the step number to 0
* or whatever siemens calls it


There are other approaches e.g.


  1. Integer OUTPUT_BITS has exactly one bit, bit RNG, assigned a 1
  2. Integer INPUT_BITS has the state of the 10 button inputs, plus the timer .Q, as bits 0-10
  3. When both OUTPUT_BITS and INPUT_BITS are non-zero, compare them:
    1. they will be equal when the correct button is pressed AND the timer has not expired;
    2. they will be unequal when an incorrect button is pressed OR the timer expired
 
Newby wants something similar

I saw this post while searching for an answer to a problem. I need something very similar, except the lightvans switch are in different places. Also no timer or at best a long timer 30 seconds or more before reset.
What chip type or PCL would I need to start with. I know very little but want to learn as I'm retired.
 

Similar Topics

Rockwell Tech Support seemed to have hit a wall with this question. Already updated the version to 5.00.13 per their suggestio but am still...
Replies
1
Views
68
Hello guys, I would need some help. I have installed the aveva plant scada and want to run a project. From the configurator, all are fine, as I...
Replies
0
Views
70
Hello all, I have the misfortune of needing to support some old firmware version 1756 controllogix machines in rslogix 5000, as well as some...
Replies
13
Views
661
I have a Win10 host that crashed this weekend. I reinstalled windows and Factorytalk Activation. Now my VM won't pull the licenses. Host and VM...
Replies
4
Views
829
Hi, During Activation Rehosting(with Internet) of Studio 5000 there was an connectivity error which caused my License to be removed from laptop...
Replies
3
Views
555
Back
Top Bottom