You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

Reply
 
Thread Tools Display Modes
Old May 1st, 2021, 12:41 AM   #1
asteroide
Member
Spain

asteroide is offline
 
Join Date: Jul 2010
Location: der
Posts: 94
Arrow Activation of random inputs/outputs?

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 by asteroide; May 1st, 2021 at 12:44 AM.
  Reply With Quote
Old May 1st, 2021, 07:43 AM   #2
AlfredoQuintero
Lifetime Supporting Member
Japan

AlfredoQuintero is offline
 
Join Date: Feb 2015
Location: Yokohama
Posts: 605
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.
Attached Images
File Type: png 2021-05-01_Move_data_S7.png (12.0 KB, 121 views)
  Reply With Quote
Old May 1st, 2021, 08:43 AM   #3
parky
Member
United Kingdom

parky is offline
 
parky's Avatar
 
Join Date: Oct 2004
Location: Midlands
Posts: 3,149
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.
  Reply With Quote
Old May 1st, 2021, 10:01 AM   #4
asteroide
Member
Spain

asteroide is offline
 
Join Date: Jul 2010
Location: der
Posts: 94
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 by asteroide; May 1st, 2021 at 10:03 AM.
  Reply With Quote
Old May 1st, 2021, 11:35 AM   #5
gclshortt
Member
Canada

gclshortt is offline
 
gclshortt's Avatar
 
Join Date: Dec 2014
Location: Ontario
Posts: 3,187
Here is the game of Simon using PLC logic.
https://accautomation.ca/building-a-...oud-of-part-5/
The random value is used with a rotate instruction.
This may help you out.
Regards,
__________________
Garry
https://www.accautomation.ca
Connect with us on Facebook: facebook.com/accautomation/
  Reply With Quote
Old May 1st, 2021, 11:44 AM   #6
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 2,670
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
__________________
Take care of the bits, and the bytes will take care of themselves.

Last edited by drbitboy; May 1st, 2021 at 11:46 AM.
  Reply With Quote
Old May 2nd, 2021, 12:41 AM   #7
AlfredoQuintero
Lifetime Supporting Member
Japan

AlfredoQuintero is offline
 
Join Date: Feb 2015
Location: Yokohama
Posts: 605
Quote:
Originally Posted by asteroide View Post
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.
  Reply With Quote
Old May 3rd, 2021, 10:39 PM   #8
asteroide
Member
Spain

asteroide is offline
 
Join Date: Jul 2010
Location: der
Posts: 94
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.



Quote:
Originally Posted by AlfredoQuintero View Post
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.
  Reply With Quote
Old May 3rd, 2021, 10:52 PM   #9
AlfredoQuintero
Lifetime Supporting Member
Japan

AlfredoQuintero is offline
 
Join Date: Feb 2015
Location: Yokohama
Posts: 605
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!
  Reply With Quote
Old May 4th, 2021, 02:48 AM   #10
parky
Member
United Kingdom

parky is offline
 
parky's Avatar
 
Join Date: Oct 2004
Location: Midlands
Posts: 3,149
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.
  Reply With Quote
Old May 4th, 2021, 03:06 AM   #11
AlfredoQuintero
Lifetime Supporting Member
Japan

AlfredoQuintero is offline
 
Join Date: Feb 2015
Location: Yokohama
Posts: 605
I think the game is kind of a "whackamole".
  Reply With Quote
Old May 4th, 2021, 03:09 AM   #12
parky
Member
United Kingdom

parky is offline
 
parky's Avatar
 
Join Date: Oct 2004
Location: Midlands
Posts: 3,149
Ah... Then it could be a move, however, difficult to move 10 bits would have to be 16 to make it simple.
  Reply With Quote
Old May 4th, 2021, 08:25 AM   #13
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 2,670
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
__________________
Take care of the bits, and the bytes will take care of themselves.
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
RSLinx Classic Activation Problem SPAZ LIVE PLC Questions And Answers 3 January 13th, 2019 12:04 AM
Activation file missing in current activation(FT Activation Tool) Joshua37 LIVE PLC Questions And Answers 5 May 27th, 2016 02:29 PM
RSLogix 500 Installation nagaraj_h LIVE PLC Questions And Answers 13 December 18th, 2014 08:11 PM
FT View SE Editing Without License Mark Cole LIVE PLC Questions And Answers 9 November 22nd, 2014 09:03 AM
Procedure request on FactoryTalk Activation calendarw LIVE PLC Questions And Answers 0 February 5th, 2007 02:03 AM


All times are GMT -4. The time now is 09:39 PM.


.