I tried to program the following with one single input and one output.
One push button (puls)
Press one time = output high
Press another time = outoput low
Press another time = output high
etc.
I thought it would be easy. But when I turn on the simulation mode in CoDeSys
my ladder program won't work. Strange becaus i'm not the only one with this problem
on the internet. I tried some of the sugestions on the net. no succes.
Maybe it has something to do with the simulationmode?
I hope someone has the sollution for this.
kind regards Yorick
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Newbie at work here,
I tried to program the following with one single input and one output.
One push button (puls)
Press one time = output high
Press another time = outoput low
Press another time = output high
etc.
I thought it would be easy. But when I turn on the simulation mode in CoDeSys
my ladder program won't work. Strange becaus i'm not the only one with this problem
on the internet. I tried some of the sugestions on the net. no succes.
Maybe it has something to do with the simulationmode?
I hope someone has the sollution for this.
kind regards Yorick
Why don't you post what you tried so we know what language you are using and what you have tried.
This should definitely work in simulation mode.
make a pulse of your in signal, now it does switch many times.
and yes i will keep the secret as you will have to learn not me.
hihi.
if you come back with your prog we will give solution
This is what I found and tried.
another hint:
the contacts setting are asked not in the beginning, but on every start of a line.
i like this type of very simple assignments.
and yes good thing you are asking, it will give you a point extra on your portfolio.
make this in one line, not more.
and this is solution:
( @NESTEDCOMMENTS := 'Yes' )
( @PATH := '\/Logic\/FF edge triggered' )
( @SYMFILEFLAGS := '2048' )
FUNCTION_BLOCK TOGGLE
VAR_INPUT
CLK : BOOL;
rst : BOOL;
END_VAR
VAR_OUTPUT
Q : BOOL;
END_VAR
VAR
edge : BOOL;
END_VAR
(*
version 1.1 30. oct. 2008
programmer hugo
tested by oscat
toggle flip flop the output changes state with every rising edge of clk.
*)
( @END_DECLARATION := '0' )
below the code needed.
put it in a function block.
IF rst THEN q := 0;ELSIF clk AND NOT edge THEN Q := NOT Q;END_IF;edge := clk;
(* revision history
hm 13.9.2007 rev 1.0
original version
hm 30. oct. 2008 rev 1.1
deleted unnecessary init
*)
END_FUNCTION_BLOCK
here you go with a good solution.
taken from oscat.
look for toggle in w www.oscat.de w
that is best place to learn.
take the file as you can read and also take the txt file.
it is all in structured text so you can read it clearly and take parts out of it.
toggle.pro [16.32 KiB]
Thanks! you helped me a lot!
And thanks for the oscat site.
geef het ook maar aan de rest van de klas.