250
Manual – IPOSplus®
18
Querying an edge
Compiler – Examples
If the input terminal was used instead of the lInputLevel auxiliary variable, the edge at
the input terminal could change at the point when the IPOS
plus®
program is between the
two program lines required for edge creation. This would mean that the edge change
would not be detected at the input terminal.
Also note that the edge of an input terminal can only be queried in the task in which the
edge was created. If this is not the case, if the individual tasks are not synchronous, the
edge may not be detected or it may be interpreted incorrectly.
If the edge of an input terminal is required in several tasks, the edge must be created
separately in each task.
Negative edge query
#include <const.h>
#include <io.h>
// Variables for edge generation
long lDI02FallingEdge,
lDI02LastState,
lDO02State,
lInputLevel;
main()
{
while(1)
{
// Read DI02
lInputLevel = (InputLevel & 0x00000004);
// Generate edge DI02
lDI02FallingEdge = !lInputLevel && (lDI02LastState);
lDI02LastState = lInputLevel;
if(lDI02FallingEdge)
lDO02State = (!lDO02State)
// Set output DO02
if (lDO02State)
_BitSet( StdOutpIPOS, 2 );
else
_BitClear( StdOutpIPOS, 2 );
}
}
INFORMATION
For When querying an edge, make sure to always use an auxiliary variable
lInput-
Level
that stores the state of the input terminal instead of using the input terminal it-
self to create the edge.
Edge change at DI02
// Read DI02
lInputLevel = (InputLevel & 0x00000004);
// Generate edge DI02
lDI02FallingEdge = !lInputLevel && (!DI02LastState);
lDI02LastState = lInputLevel;
P
i
f
kVA
Hz
n
P
i
f
kVA
Hz
n