Main page
PLC functions
Small tools
Technical links
Other links
Some information
Back to home
 Reactions: E-mail

Working people make mistakes, some people do never make mistakes! Working people
I work to live, my boss thinks I live to work!

Here are the functions i´ve made for translating a flowchart to a program in a plc.
The best way to make it clear is an example:

download awl source (incl. functions.)

Symbol table:
example step program FB 1 FB 1 Example of step program functions
reset step FC 1021FC 1021reset all steps in range (all bits)
step calculation FC 1022FC 1022Calculate active step
step FC 1023FC 1023if enable activate next step
next step with choiceFC 1024FC 1024if enable activate a selected step
step reset & calc FC 1025FC 1025Calculate active step and Reset all step and actions if needed

The flowchart to be converted:

Can be converted to the next program:

Example part 1 Example part 2 Example part 3


Explanation: FB 1

Network 1: FC 1025: Calculate active step and Reset all step and actions if needed.
Input: first_bit Pointer to the first bit of an array or list of bits. The pointer has to start on the lsb of a byte and has to be in a DB.
max_bits Amount of bits in the array or list.
reset If this item is high then all bits (steps) will be resettet and ENO will be high.
Output: bit_number The last bit that was found high in the list. Wenn none found then number is 0.
ENO Same value as reset. Can be used to reset data to initiate value.
If you don´t need them both or you want to split the calculate and the reset function you can use the functions explained below instead. (Network 8 and 9)
top

Network2: Step Enable
Condition for program to make a next step. Here you can freeze the program or make a step-4-step function (time or key).
top

Network 3: Step 1
Condition for program to start. Here the first step is set and the assigned actions are performed. The step_active is set so that the program can´t start again. Other programs can see that the program has started. (For handshake purpose or synchronize for example.) The Step_EN is reset so that step[1] is for a minimum of 1 PLC-cycles high.
top

Network 4: FC 1023: next step
Input: EN Condition to make the step. May be an AND/OR logic or another combination of functions.
Step_EN Condition to make the step. If the step has been performed the bit is reset once.
(Can be replaced with the same value as Step_act, then the program will not hold here. a Minimum of 1 PLC-cycles is then not garanteerd.)
Step_act The step that has to be active to go to the next step. If the step has been performed the step is reset once.
Output: ENO high wenn step is performed (One Shot).
Whats in the function?
top

Network 5: FC 1023: next step
Same as network 4. Here the step from Step[2] to Step[3] is performed wenn Condition 3 and Step_EN is true. #Action1 will be reset if the step is performed.
Whats in the function?
top

Network 6: FC 1024: next step with choice
Input: EN Condition to make the step. May be an AND/OR logic or another combination of functions.
Choice Condition for what the next step is. Is the value high then Step_new_1 is the next step, else Step_new_0 is the next step.
Step_EN Condition to make the step. If the step has been performed the bit is reset once.
(Can be replaced with the same value as Step_act, then the program will not hold here. a Minimum of 1 PLC-cycles is then not garanteerd.)
Step_act The step that has to be active to go to the next step. If the step has been performed the step is reset once.
Output: ENO high wenn step is performed (One Shot).
Whats in the function?
top

Network 7: FC 1023: next step
Same as network 4. Here the step from Step[4] to Step[32] is performed wenn Condition 3 and Step_EN is true. #Action1 will be reset if the step is performed. The next cycle the program will be reset in network 1.
Whats in the function?
top

Example caculate step

Network 8: FC 1022: Calculate step
Input: first_bit Pointer to the first bit of an array or list of bits. The pointer has to start on the lsb of a byte and has to be in a DB.
max_bits Amount of bits in the array or list.
Output: bit_number The FIRST bit that was found high in the list. Wenn none found then the number is 0.
ENO Always high
top

Network 9: FC 1021: Reset step
Input: EN If high then all bits (steps) will be reset and ENO will be high.
first_bit Pointer to the first bit of an array or list of bits. The pointer has to start on the lsb of a byte and has to be in a DB.
max_bits Amount of bits in the array or list.
Output: ENO Same value as EN. Can be used to reset data to initiate value.
top

Extra: An simple method to create a runtime error on a single step.

Step runtime
The Timer is set to the new value if #step_en is low. (done by the "step" function)
You can hold or continue the cycle or take actions if a runtime error occurs. To hold the program you have to AND the RT_error to the condition of the next step (not in #step_en condition, this will reset the timer).
You can use a other timer described in the 'Timer' section.
(No code included for download.)
top

content of some functions: For those who don´t program a S7 here are the content of the step functions.

Content of the Step function:
step

Content of the Step Choice function:
step choice

top