Go Down

Topic: Simulating a PLC ladder diagram on arduino (Read 7 times) previous topic - next topic

ash901226

Hello and good day/night (depending on what region your in).. I have a question concerning the matter above,
i would like to create a simple program that the arduino can understand that is base on PLC ladder diagram.
i am more familiar with a ladder diagram that coding but i am trying to make the transition as easy as possible, though i have bought arduino uno for the long time, i truly think that i only able to scratch on the the surface of its capability. However in ladder diagram, i have an intermediate certificate in PLC programming and i really hope that i can use the same logic and principle to make sense of arduino coding.

i know that ( sorry for using ascii art to demonstrate due to not having any plc software at home)
:
on a ladder diagram
------|I1|------   or  ------|/I1|-----   is an input of I1 and

on arduino coding
Code: [Select]

int I1=2;
void setup()
{
  pinMode(I1,INPUT);
}
void loop(){}



on PLC
-----(Q1)------ meaning that Q1 is an output


on arduino
Code: [Select]

int Q1=3;
void setup()
{
  pinMode (Q1, OUTPUT)
}
void loop(){}


on plc

      I1       Q1
----||------( )      meaning that when the input I1 high Q1 is high


on arduino
Code: [Select]

int I1=2;
int Q1=3;
void setup()
{
  pinMode (I1,INPUT);
  pinMode (Q1,OUTPUT);
}
void loop()
{
  boolean StateIn1=digitalRead(I1);
  digitalWrite(Q1, StateIn1);
// or simple yet just digitalWrite (Q1,digitalRead(I1));
}



but my real question is this how can i make the coding for arduino to an equivalent of PLC keep function


like :

    I1    I2      Keep1
---| |--|\|-----ls      l
    I3             l       l
---|\|---------lr     l


according to this program
a high (I1) and a low (I2) with make the output high (keep1)
however the low (I3) will make it the output low

the keep function on a PLC is identical to rs flip flop.

how can i write this ladder diagram into arduino?
please help me, any idea would be great. And i thank anyone in advance to have spend your time read my question and to help me.


wildbill

I'm not familiar with ladder diagrams so this is likely has a very obvious answer:

Quote
a high (I1) and a low (I2) with make the output high (keep1)
however the low (I3) will make it the output low


What happens if I1 is high, I2 is low and I3 is low. How do you resolve the apparent conflict? Latest condition wins?

zatalian

A set or reset is easiest done with an if without else.

Code: [Select]

I1 = digitalRead(Input1);
I2 = digitalRead(Input2);
I3 = digitalRead(Input3);

if (I1 && !I2) Q1 = 1;
if (!I3) Q1 = 0;

digitalWrite(Q1, Output1);



If you want to simulate a plc, remember to first read all your inputs, then do your networks and in the end write your outputs...

ash901226

sorry for not clearing that up Karma...
the keep function that i am talking about is an digital equivalent RS flip flop.

meaning that every open and close contact operation in the upper rung ( rung in simple term line) if high with result in the S portion to be high.
if the lower rung is true, the R  will set HIgh and the keep will be low. R will always be a priority


ash901226


Go Up