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:
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):
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.
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.