I have 7 switches connected to digital inputs on the PLS and 7 Digital outputs.
Digital input 1 controls Digital Out 1
Digital input 2 controls Digital Out 2
Digital input 3 controls Digital Out 3
Digital input 4 controls Digital Out 4
Digital input 5 controls Digital Out 5
Digital input 6 controls Digital Out 6
Digital input 7 controls Digital Out 7
When 3 digital outputs are TRUE, no more outputs are allowed to be set to TRUE.
Then you must turn off an output before the next can be turned on.
If I set
Digital input 1 = TRUE
Digital input 2 = TRUE
Digital input 3 = TRUE
Digital input 4 = FALSE
Digital input 5 = FALSE
Digital input 6 = FALSE
Digital input 7 = FALSE
Then
Digital out 1 = TRUE
Digital out 2 = TRUE
Digital out 3 = TRUE
Digital out 4 = FALSE
Digital out 5 = FALSE
Digital out 6 = FALSE
Digital out 7 = FALSE
Then I set Digital 4 TRUE
Digital input 1 = TRUE
Digital input 2 = TRUE
Digital input 3 = TRUE
Digital input 4 = TRUE
Digital input 5 = FALSE
Digital input 6 = FALSE
Digital input 7 = FALSE
Then
Digital out 1 = TRUE
Digital out 2 = TRUE
Digital out 3 = TRUE
Digital out 4 = FALSE
Digital out 5 = FALSE
Digital out 6 = FALSE
Digital out 7 = FALSE
And nothing should happen to the output
If I then turn of digital input 1 to FALSE I get
Digital input 1 = FALSE
Digital input 2 = TRUE
Digital input 3 = TRUE
Digital input 4 = TRUE
Digital input 5 = FALSE
Digital input 6 = FALSE
Digital input 7 = FALSE
Then
Digital out 1 = FALSE
Digital out 2 = TRUE
Digital out 3 = TRUE
Digital out 4 = TRUE
Digital out 5 = FALSE
Digital out 6 = FALSE
Digital out 7 = FALSE
I Then turn Digital input 5 to TRUE and digital input 2 to FALSE.
Digital output 2 don't go to FALSE
Digital input 1 = FALSE
Digital input 2 = FALSE
Digital input 3 = TRUE
Digital input 4 = TRUE
Digital input 5 = TRUE
Digital input 6 = FALSE
Digital input 7 = FALSE
Then
Digital out 1 = FALSE
Digital out 2 = TRUE
Digital out 3 = TRUE
Digital out 4 = TRUE
Digital out 5 = FALSE
Digital out 6 = FALSE
Digital out 7 = FALSE
How can I get thise to work?
VAR_GLOBALCONSTANT
  IOMAXSIZE: INT :=7;END_VARPROGRAMtest2VAR
  aInput      : ARRAY[1..IOMAXSIZE] OFBOOL;
  aOutput      : ARRAY[1..IOMAXSIZE] OFBOOL;
   aINT_Input    : ARRAY[1..IOMAXSIZE] OFINT;
  aINT_Output    : ARRAY[1..IOMAXSIZE] OFINT;
  iCount      : INT;
  iTotalInput    : INT;
  iTotalOutput  : INT;END_VAR(*Max3tilTRUEsamtidig. Alledeandreskaldaværestengt.
Ikkemulig å åpneden4når3alleredeerTRUE.
Børkunnegå fra4inngangeriTRUEtil3UTGANGERiTRUEdirekte. Ikkemåtteinnomkun2iTRUE*)PROG
  (*LeggersammenalleutgangenesomerTRUEentotalvariabel*)
  iTotalInput :=aINT_Input[1] +aINT_Input[2] +aINT_Input[3] +aINT_Input[4] +aINT_Input[5] +aINT_Input[6] +aINT_Input[7];
  iTotalOutput :=aINT_Output[1] +aINT_Output[2] +aINT_Output[3] +aINT_Output[4] +aINT_Output[5] +aINT_Output[6] +aINT_Output[7];(*GjøromfraBOOLverdiertilINT*)FORiCount :=1TOIOMAXSIZEBY1DO
  aINT_Input[iCount] :=BOOL_TO_INT(aInput[iCount]);
  aINT_Output[iCount] :=BOOL_TO_INT(aOutput[iCount]);END_FOR(*Hvisdetermindreen3innganersomerpå kjøresdenne*)IF(iTotalInput<3)THEN
  (*Overførerutgangertilingangsarrayene*)
  FORiCount :=1TOIOMAXSIZEBY1DO
    aOutput[iCount] :=aInput[iCount];
  END_FOREND_IF(*HerertanketatHvisdeter3InngangersomerTRUE, mendisseikkesammsvarermedutgangenesomerTRUE.
Så kjørdennefor å oppdatereinnganger å utganger*)IF(iTotalInput=3)ANDNOTaOutput[iCount] =aInput[iCount] THEN
  FORiCount :=1TOIOMAXSIZEBY1DO
    aOutput[iCount] :=aInput[iCount];
  END_FOREND_IF
There are two problems I see that once fixed will get your function to work properly.
Try using this code instead and you can compare to what you have to see what has changed.
(*Gjør om fra BOOL verdier til INT*)FORiCount:=1TOIOMAXSIZEBY1DO  aINT_Input[iCount]:=BOOL_TO_INT(aInput[iCount]);  aINT_Output[iCount]:=BOOL_TO_INT(aOutput[iCount]);END_FOR(*Legger sammen alle utgangene som er TRUE en total variabel*)  iTotalInput:=aINT_Input[1]+aINT_Input[2]+aINT_Input[3]+aINT_Input[4]+aINT_Input[5]+aINT_Input[6]+aINT_Input[7];  iTotalOutput:=aINT_Output[1]+aINT_Output[2]+aINT_Output[3]+aINT_Output[4]+aINT_Output[5]+aINT_Output[6]+aINT_Output[7];(*Hvis det er mindre en 3 innganer som er på kjøres denne*)IF(iTotalInput<3)THEN  (*Overfører utganger til ingangs arrayene*)  FORiCount:=1TOIOMAXSIZEBY1DO   aOutput[iCount]:=aInput[iCount];  END_FOREND_IF(*Her er tanket at Hvis det er 3 Innganger som er TRUE, men disse ikke sammsvarer med utgangene som er TRUE.Så kjør denne for å oppdatere innganger å utganger*)FORiCount:=1TOIOMAXSIZEBY1DO  IF(iTotalInput=3)ANDaOutput[iCount]<>aInput[iCount]THEN   aOutput[iCount]:=aInput[iCount];  END_IFEND_FOR
The first problem was was you were counting inputs of aINT_Input then later assigning the values you were changing so the iTotalInput value was wrong.
The second problem was the last if/for statements that were made needed to be done in a different order. The IF statement was only checking to see if aInput[iCount] of array position 8 did not equal aOutput[iCount] of array position 8. The IF statement needed to be moved into the FOR loop in order to iterate through the array using the iCount variable.
I been working with it and found another solution.
PROGRAMtest2VAR
  aInput      : ARRAY[1..IOMAXSIZE] OFBOOL;
  aOutput      : ARRAY[1..IOMAXSIZE] OFBOOL;
   aINT_Input    : ARRAY[1..IOMAXSIZE] OFINT;
  aINT_Output    : ARRAY[1..IOMAXSIZE] OFINT;
  iCount      : INT;
  iTotalInput    : INT;
  iTotalOutput  : INT;
  iTotalActiveInputs: INT;
  iInputCount: INT;
  bad: BOOL;END_VAR(*TelleroppantallinputersomerTRUE*)iTotalActiveInputs :=0;FORiInputCount :=1TOIOMAXSIZEBY1DO
  IF(aInput[iInputCount] =TRUE)THEN
    iTotalActiveInputs :=iTotalActiveInputs+1;
  END_IFEND_FOR(*Hvisdetermindreen4inputersomerTRUE, overførinputermotoutputene*)FORiCount :=1TOIOMAXSIZEBY1DO
  IF(iTotalActiveInputs<4)THEN
    aOutput[iCount] :=aInput[iCount];(*Hvisdeter0inputssomerTRUEsetoutputenetilFALSE*)
  ELSIF(iTotalActiveInputs=0)THEN
    aOutput[iCount] :=FALSE;
  END_IF
  aINT_Input[iCount] :=BOOL_TO_INT(aInput[iCount]);
  aINT_Output[iCount] :=BOOL_TO_INT(aOutput[iCount]);END_FOR(*DENULTIMATETEST*)IF(iTotalActiveInputs<4)THEN
  FORiCount :=1TOIOMAXSIZEBY1DO
    IF(aOutput[iCount] <>aInput[iCount])THEN
      bad :=TRUE;
    END_IF
  END_FOREND_IF
Hello. I need some help with a control function.
I have 7 switches connected to digital inputs on the PLS and 7 Digital outputs.
Digital input 1 controls Digital Out 1
Digital input 2 controls Digital Out 2
Digital input 3 controls Digital Out 3
Digital input 4 controls Digital Out 4
Digital input 5 controls Digital Out 5
Digital input 6 controls Digital Out 6
Digital input 7 controls Digital Out 7
When 3 digital outputs are TRUE, no more outputs are allowed to be set to TRUE.
Then you must turn off an output before the next can be turned on.
If I set
Digital input 1 = TRUE
Digital input 2 = TRUE
Digital input 3 = TRUE
Digital input 4 = FALSE
Digital input 5 = FALSE
Digital input 6 = FALSE
Digital input 7 = FALSE
Then
Digital out 1 = TRUE
Digital out 2 = TRUE
Digital out 3 = TRUE
Digital out 4 = FALSE
Digital out 5 = FALSE
Digital out 6 = FALSE
Digital out 7 = FALSE
Then I set Digital 4 TRUE
Digital input 1 = TRUE
Digital input 2 = TRUE
Digital input 3 = TRUE
Digital input 4 = TRUE
Digital input 5 = FALSE
Digital input 6 = FALSE
Digital input 7 = FALSE
Then
Digital out 1 = TRUE
Digital out 2 = TRUE
Digital out 3 = TRUE
Digital out 4 = FALSE
Digital out 5 = FALSE
Digital out 6 = FALSE
Digital out 7 = FALSE
And nothing should happen to the output
If I then turn of digital input 1 to FALSE I get
Digital input 1 = FALSE
Digital input 2 = TRUE
Digital input 3 = TRUE
Digital input 4 = TRUE
Digital input 5 = FALSE
Digital input 6 = FALSE
Digital input 7 = FALSE
Then
Digital out 1 = FALSE
Digital out 2 = TRUE
Digital out 3 = TRUE
Digital out 4 = TRUE
Digital out 5 = FALSE
Digital out 6 = FALSE
Digital out 7 = FALSE
I Then turn Digital input 5 to TRUE and digital input 2 to FALSE.
Digital output 2 don't go to FALSE
Digital input 1 = FALSE
Digital input 2 = FALSE
Digital input 3 = TRUE
Digital input 4 = TRUE
Digital input 5 = TRUE
Digital input 6 = FALSE
Digital input 7 = FALSE
Then
Digital out 1 = FALSE
Digital out 2 = TRUE
Digital out 3 = TRUE
Digital out 4 = TRUE
Digital out 5 = FALSE
Digital out 6 = FALSE
Digital out 7 = FALSE
How can I get thise to work?
Link to video
https://www.dropbox.com/s/opu2b96l5lvhl ... 5.MOV?dl=0
Link to program
https://www.dropbox.com/s/qz1jtw7bse6cfaq/test.zip?dl=0 m
Related
Talk.ru: 1
Talk.ru: 2
Talk.ru: 3
Talk.ru: 5
Talk.ru: 7
There are two problems I see that once fixed will get your function to work properly.
Try using this code instead and you can compare to what you have to see what has changed.
The first problem was was you were counting inputs of aINT_Input then later assigning the values you were changing so the iTotalInput value was wrong.
The second problem was the last if/for statements that were made needed to be done in a different order. The IF statement was only checking to see if aInput[iCount] of array position 8 did not equal aOutput[iCount] of array position 8. The IF statement needed to be moved into the FOR loop in order to iterate through the array using the iCount variable.
Related
Talk.ru: 1
Talk.ru: 2
Talk.ru: 3
Talk.ru: 5
Talk.ru: 7
Thank you for youre feedback Comingback4u
I been working with it and found another solution.
Link to project
https://www.dropbox.com/s/h6kgatk13g2x0 ... n.zip?dl=0
I will test the code to try to learn more about how this can be solved.