Easy PLc programming task - but not for me

szfamman

Member
Join Date
Jul 2011
Location
Szfvár
Posts
2
Hi everyone!

I've started to learn PLC programming (Simatic manager with plcsim (siemens s7 300). I read an interesting lesson on the internet: write a plc program which can toggle on and off an output (LED, motor, etc.) with and ON and OFF momentary push button. I could solve it with an SR flip-flop, but the next lesson is harder for me. It's the same with only 1 button.
So, at beginning i push the button (then release it) and the output turns on, till i push the button again, when the output turns off (and then if i push again, it will turn on, then push again, it will turn off, and so on).

I know how to program it in C language, here it is:
Code:
//this code is shorther, it's like a T flip-flop because of the "outtemp = !outtemp" part
//check if input (in1) true (someone pushing the button right now), and the button has been not pressed before (temp1); if the button has been pressed in the last cpu cycle then temp=1, and outtemp will hold, and this is the edge detection part
if ((in1==1) && (temp1 == 0)
{
  //button is under pressure
  temp1 = 1;
  //change (invert) the output temp value
  outTemp = !outTemp;
}
//if input is 0 (nobody pusning the button right now) 
if (in1 == 0)
{
  //button is not under pressure
  temp1 = 0;
}
//write output
out1 = outTemp;

the code in and easier (it's easier i think, because the output=1/output=0 is like set and reset an SR flip-flop) way (in C):
Code:
//now i have more temp variables: "temp1" is for edge detection (like the first C code), and "ispressed" means, that someone pushed the button before this pushing. at start the "ispressed" variable is false, because no one pressed the button before. at first press "ispressed " is true, till the next press, when it'll become false again

if( (in1 == 1) && (temp1 == 0))
{
  //button is under pressure
  temp1 = 1;

  //if the button has not been pressen before, so the output is 0
  if (ispressed == 0)
  {
     //change output temp to 1
     outTemp = 1;
     //button has been pressed (so turned ON)
     ispressed = 1;
  }
  else if (ispressed == 1)
  {
     //change output temp to 0
     outTemp = 0;
     //button has been pressed again (so turned OFF)
     ispressed = 0;
  }
}
if( in1 == 0 )
{
  //button is not under pressure
  temp1 = 0;
}

The problem, that it's complex for me to program this in STL/FBD/LAD. Can someone help me with that? I know, I should make a latch circuit (with one or more flip-flops maybe), but I don't really know how :S

And my other question: is there and easier/better way to solve the first circuuit (i solved it with 1 SR-FF, and i think it's the best/fastest solution)

Thanks,
szfAmman

UI: sorry for my bad english, i haven't use it for a long time.
 
Translating your C into STL gives...

Code:
[COLOR=Red][I]//check if input (in1) true (someone pushing the button right now), and the button has been not pressed before (temp1); if the button has been pressed in the last cpu cycle then temp=1, and outtemp will hold, and this is the edge detection part
if ((in1==1) && (temp1 == 0)
{
//button is under pressure
  temp1 = 1;
//change (invert) the output temp value
  outTemp = !outTemp;
}
//if input is 0 (nobody pusning the button right now) 
if (in1 == 0)
{
//button is not under pressure
  temp1 = 0;
}
//write output
out1 = outTemp;[/I][/COLOR]

      A     #in1                        // if....
      AN    #temp1
      JCN   elsa
      S     #temp1                      //  then ...
      AN    #outtemp
      =     #outtemp
      JU    enfa
elsa: NOP   0                           //  else  ...

enfa: NOP   0                           // endif

      AN    #in1
      JCN   elsb
      R     #temp1
      JU    enfb

elsb: NOP   0
enfb: NOP   0
      A     #outtemp
      =     #out1
 
Hi everyone!

I was working on the exercise too, but i could't figure it out. i tried like this:
mine2_www.kepfeltoltes.hu_.jpg

and this:
mine_www.kepfeltoltes.hu_.jpg


Can you show me where i made a mistake? (I tried to translate my C codes to FBD, and it is, how there drawnings born :D). Both has the same error: the reset didn't work on out or temp properly.

I will check your solutions later, but i can't imagine, it's really that easy. I just made it more complicate, but hell ye, i'm the little noob, and you're the expert :))
 

Similar Topics

I am an Electric Engineer working as a maintenance engineer and manage some technician on the production hall now but in the past, I mostly focus...
Replies
12
Views
3,555
hi i have plc moeller easy821dc-tc and i forget password and i tried many way to get in to it to resets plc to factory defult thnaks plz if any...
Replies
2
Views
1,689
Hi everyone. I think i have problems with noise disturbing the Can BUS on my Xlogic 18-DA-RU low cost PLC. I have random dropouts on the...
Replies
0
Views
2,024
Looking for tips on making replacement of failed PLC's, HMI's and Drives easy for E&I techs. This would be all Rockwell Automation Equipment. I...
Replies
0
Views
2,840
hello Gentelmans, Is there a first scan bit in Klockner Moeller EASY PLC?
Replies
4
Views
2,801
Back
Top Bottom