Vbuilder Manual PDF
Vbuilder Manual PDF
Vbuilder Manual PDF
Some of the major features incorporated into vBuilder are listed below.
While the list, above, may appear intimidating, vBuilder is designed to be very easy to use. Start with the basics and you’ll ad-
vance to objects and embedded objects in short order.
This manual will guide you through vBuilder’s features, navigation and function details. The material is presented in a se-
quence starting with quick tutorials in vBuilder Flow Charts and vBuilder Ladder. This is followed by more detailed discus-
sions of Navigation of the software, Ladder function block and Flow Chart function block details. Subsequent chapters get into
more advanced features, including debug, program deployment, Embedded Objects and other topics.
An inexpensive and powerful tool, which will accelerate your learning experience, as well as provide a platform to ac-
celerate your real world application development is one of the available Velocio Simulators. The assortment of available
Simulators can be found at Velocio.net. Also available at Velocio.net is a sequence of training lessons, which you can
work through to quickly learn to master the advanced control programming skills of the future. Thirdly, training videos
can be found at Velocio.net. [understand that the number of available lessons and videos will grow over time]
Recommendation : All program functionality is available, using either Flow Chart or Ladder Logic programming. When
you have subroutines in a program, you can even mix (some routines in Flow Chart and some in Ladder). While Ladder
Logic is the traditional language in the PLC industry, we strongly recommend that you learn Flow Chart programming. It
is a much more natural and powerful programming language. It is much easier to implement state machine programming
(please take a look a the state machine programming chapter). It is a much easier language to debug a program. Almost
every customer that has tried Flow Chart programming has not gone back to ladder.
We first implement the tutorial examples with Flow Chart programming, then with Ladder Logic. We actually could mix the
two programming modes (one type for the main program and the other for the subroutine) if we wanted. We won’t, but you
could try that yourself.
For those people without a control systems background, the next few pages will demystify the basics of control, bits, tagnames
and terminology. If you are already a PLC or control system expert, you can skip these pages and go on to the first tutorial
program.
The next illustration shows two light bulbs. One is an AC light bulb, like you have
in your home. It operates when connected to 120 VAC (Volts of Alternating Current)
power. The other is a DC light bulb, which is used in most indicator lights in machin-
ery, or inside your car. Different DC light bulbs operate from different DC voltages.
There are light bulbs that operate on 5VDC (Volts Direct Current). There are light bulbs
that operate on 10VDC, 12VDC, 24VDC, etcetera. They all work the same way. If you
connect the bulb to the electrical power source they are designed for, they will light. +
-
In both cases, you have two power connections. The terms AC (altenating current) and DC (Direct Current) are general terms
that define the current flow, and more simply, the voltage relationship between the two connections.
Direct Current : Direct Current is a power source that has a constant voltage between the two terminals. A battery is a direct
current power supply. Your battery charger for your cell phone converts the AC power from an AC outlet to DC power to
charge the cell phone battery. The DC voltage from you car battery is usually about 12VDC. Cell phone batteries and associated
chargers are whatever voltage your cell phone manufacturer designed them to be. In common practice, most electrical equip-
ment will operate from a 5VDC, 12VDC or 24VDC power supply.
The illustration on the right shows the symbol commonly used to signify a DC power source. It consists of a +12V
stack of long and short parallel lines and labelling of the voltage level of each of the two connections (or temi-
nals). Usually, you’ll see this symbol as shown, with two long lines and two shorter lines, stacked long/short/
long/short from top to bottom. Occasionally, you may see a symbol with just one long line above one short line.
The key is it indicates a DC power source at whatever voltage level it is labelled. GND
Other DC symbols that you might see in an electrical diagram are on the right. The one with a horizontal line on top 5V
of a vertical line and a voltage label above it (5V in this case), is a symbol indicating that whatever is connected to it is
connected to the positive voltage side of whatever voltage supply (5V in this case) is indicated.
The next symbol is a ground symbol. It is commonly used to indicate connection to the negative side of the DC power
source, whether the DC side of the power source is actually connected to physical ground or not.
So a DC power source can be symbolized in either of the two ways shown on the right.
In common practice, DC power either comes from a battery, or from an electrical device called a power supply. A power supply
simply converts AC power to DC power.
The illustration, below, shows the difference in voltage between the two terminals over time. As you can see, the voltage dif-
ference goes from 0 to a positive peak value (at time B), to a negative peak value (at time D) and back to 0 every 0.016666667
seconds. The reason it is every 0.016666667 seconds is that it does this 60 times per second (divide 1 by 60). The voltage differ-
ence alternates between the first terminal being at a higher voltage than the second terminal to the being at a lower voltage and
back again 60 times per second.
+
Voltage
C D
A B
.0083 .0167
seconds seconds
AC Power
AC is used to transmit power from the power station to your home or business because it is easier
and cheaper to convert to very high voltages for transmission and back down to lower voltages for use. Higher voltage trans-
mission results in less loss of power in the transmission lines.
Very little equipment runs directly from AC power. Many motors will (including refrigerator, washing machines and air con-
ditioners) and most light bulbs used for room lighting. If equipment has electronics in it, there will be a power supply that con-
verts the AC to DC for use. Electronics operate on DC power, commonly 5VDC or less, although higher voltages are commonly
used for “power” portions of the design (running DC motors, heaters, etc.)
The symbol for AC power source is shown on the right. It shows the sinusoidal alternating of the difference in volt-
age between the two terminals.
In the AC example, when the terminal on the top is at a higher voltage than the one on the
bottom, current flows from the top terminal, through the bulb to the bottom one. When
the voltage reverses, the current flow the other way. It doesn’t matter. Either way it flows,
the filament heats up and provides light.
In both the AC and DC illustrations, we have a “circuit”. All that is meant by circuit is that
the current has a path to flow around from one terminal of the supply, through something,
+
back to the other terminal of the supply - in other words, in a circular path or circuit. If
there is not a complete path, the circuit is defined as “open”. The light bulb will not turn -
on.
+
-
The next set of illustrations show the switch connected on the other side of the light bulb.
It doesn’t matter where the switch is. If it is closed, the bulb will turn on. If it is open, the
bulb will be off.
This same principle works with motors, heaters, and any device that can be turned on or
off. If you create a complete circuit for current flow it will be on. If you open the circuit, it
will be off.
+
-
VDC
Output Pin Load
◊ Turning Devices On and Off with a Transistor Common Gnd
A transistor is an electronic switch for DC circuits. The direct digital outputs in Velocio
PLCs are called “sinking” transistor outputs. All sinking means is that they provide the Inside PLC VDC
switch on the ground side of the circuit (like the last set of illustrations). They switch, or
sink to ground. The figure on the right shows a sinking transistor output connected to a
light bulb.
VDC
The equivalent circuit, using a switch is shown below it. The whole idea is that if the transistor is
turned on, it physically closes a switch in the ground side of the circuit.
Load
Outside of the PLC, one side of each device (symbolized by light bulbs) must be
connected to the positive terminal of the power supply. The other side is con-
nected to the PLC terminal (which in turn connects to a transistor).
The sinking transistor outputs in most Velocio PLCs are rated at up to 30 VDC
and 200mA current. In a lot of cases, that is enough.
See the specifications for the particular PLC that you are using to learn the exact output voltage and current limits.
That begs the question, what do you do if you need to switch higher DC voltages, higher current or AC? That’s covered too.
M Motor VDC
In a PLC program, you can define a large number of what we call tagnames. Tagnames are just meaningful names you give to
information. Some of those are bits. A lot of bit tagnames are just information that you keep track of. They are just information
and are not directly associated with anything physical. We call those Register bits.
Some bits are directly associated with digital inputs and outputs. We’ll give you a peek into a little bit of the programming.
The screen shot shows what we call a “dialog box”. This particular dialog box is the one that you can use to see the names of all
of the tagnamed data in your program, and to create new ones or change the names of existing ones. On the left side, you can
see that there are is a list of different types of tagnames. If you click the selection button for one of these types, the button you
have selected will turn blue and the list of all tagnames of that type will be displayed.
What is unique to “Input/Output” tagnames is that the tagnames are directly tied to a particular input or output device. The
Output Bits are each directly tied to one of the output transistors on the output ports. For example, the Output Bit named Out-
BitD1 will directly control the transistor connected to port D, output 1. Any time that your program writes a 1 to an output bit,
the associated output transistor turns, which turns on whatever is connected. Anytime a 0 is written to a tagname, the transistor
turns off, opening the connected circuit and turning the connected device off.
What all of these conditions have in common is that they are binary - either they are true or they are not. Electrically, they can
easily be determined by the state of a binary type sensor. Quite often these sensors are switches. They could be a limit switch, a
human operated toggle switch, a proximity switch, an optical sensor, a float switch and so on.
Velocio PLCs sense these types of status with digital inputs. We’ll illustrate how digital inputs work by use of a switch. Any
other digital inputs works fundamentally the same way - its just a minor variation on a theme.
Digital Inputs
PLC bit value
Digital inputs in Velocio PLCs are pretty simple. Connections directly into a PLC port digital
input simply sense whether voltage level at that port pin is above or below a threshold level. 5V
The figure on the right illustrates. The first input is connected to 5V. 5V is above the threshold
voltage level, so that input’s bit value is 1. The second input is connected to ground. Ground is
below the threshold voltage level, so the second digital input’s bit value is 0 .
1
See the PLC’s specifications for digital input threshold values. Typically, a maximum value is
specified for input value of 0 and a minimum value given for an input value of 1. There will be 0
a small gap between these to values to ensure that inputs clearly reflect the desired states. For
example, the maximum value for a 0, might be 0.8V and the minimum value for a 1 might be
2.5V. If you design your system so that the signals fall in line, operation will be reliable.
5V
The next figure shows a digital input connected to a switch. If the switch is thrown in the direc-
tion shown, the input value will be a 1. If it is thrown in the opposite direction, it will be a 0.
24V
Another example of a digital input circuit is shown next. In this example, the input is tied
through a resistor to 24V. Generally, a circuit like this uses a resistor in the 10,000 - 22,000 ohm
range. What this does, is pull the input voltage to 24V, if the switch is open.
If the switch is closed, the direct connection to ground pulls the input voltage to ground. The
fact that there is a connection to 24V through a resistor simply means that a very small (milliamp
level) current will flow through the resistor. The input voltage will be ground.
Direct digital input signals to a Velocio PLC can be any DC voltage level up to 30V. That covers
almost all DC signals used in most machinery. But the natural next question is, “what about
sensing AC or high voltage DC”. That’s covered. Optocoupler Terminal Block modules are avail-
able for just that purpose.
By using optocoupler terminal modules, connected to digital input ports, AC signals or high voltage DC signals can be sensed.
Just use a Optocoupled Terminal Block module rated at the voltage level that you want to sense. 120VAC, 240VAC and 24VAC
are common levels.
PLC 5V
optocoupler
terminal board
• Temperature
• Pressure
• Weight
• Liquid level
• Flow rate
• Voltage
• pH
• chemical levels (carbon monoxide in atmosphere, oxygen level, nitrogen level, etc)
There are devices, called transducers that measure particular parameters and output an analog electrical signal proportionate to
the measured parameter. For example, a particular pressure transducer might convert 0 - 1000 psi of pressure to 0 to 5V. In this
example, a pressure of 200 psi would be output as 1V, 250 psi would be 1.25V, 750 psi would be 3.75V, etc.
Analog measurements are typically continuously variable electrical signals of some standard range. The most common ranges
used in industry are 0-5V, 0-10V and 4-20mA. Velocio’s PLC measure signals in these ranges. The particular PLC module that
you use must be configured for the particular output range of the transducers that are attached.
Typical transducers have two connections, the output connection and the PLC
ground. Typical connection to an anolog input port is shown on the right.
A/D Pressure
Inside the PLC, the analog value is converted to a digital equivalent. The Converter
PLCs analog inputs have 12 bit resolution. That means the signal, whether Transducer
it be 0-5V, 0-10V or 0-20mA is converted to a value between 0 and 4095.
The convertion is linear. Pressure
Transducer
Lets use a 0-3000psi tranducer that outputs a 0-5V signal to the PLC. If the
pressure on the transducer is is measuring a pressure that is currently 540 Scale
psi, it will output :
If you get a Windows message that asks whether you want to allow vBuilder to make changes to your com-
puter, click Yes. The changes that vBuilder makes to your computer is saving your program files.
You should get an opening screen that looks like the one shown below. At this point you are ready to begin entering a program.
Begin your program entry by selecting the File Menu, then “New”.
Likewise, tagnames are automatically created for the 12 digital outputs, located in the Output bit list and the 12 analog inputs,
located in the Input i16 list. The raw analog input values are signed 16 bit numbers.
In the Output bit list, rename the D1 output “lockRelease”, and the D2 output
“heater”.
Next, change the tagname of the first analog input (Input i16) to “rawTem-
perature”, as shown.
Along the right hand side of vBuilder is the Toolbox. The Toolbox contains all of the program tools
necessary to build a program. There are two basic types of tools :
• Decision blocks : decision blocks make a decision whether something is true or not. If it is true, the
program flow will follow one branch. If it is false, it will follow another. There are decision blocks for
whether a bit is on or off, numeric comparison decision blocks and timer based decisions. The decision
blocks are all near the top of the toolbox, below the WireRouter and above the Turn On/Off tool.
• Process blocks : Process blocks do something. That something can be to turn something on or off,
perform a calculation, count, filter, control a stepper motor, PID, etc. The Process blocks begin with Turn
On/Off and end with Timer.
Select the Turn On/Off tool again, and place another block
below the decision block. Select the “lockRelease” again.
This time, select the Off option. Click OK.
We now need to wire up the program flow. If you move your cursor over the bottom of the
Start block, a bubble will appear and turn blue. This bubble is a connection point. When it
turns blue, you are in a position to place a flow line beginning at this point. Click on the blue
bubble, keep your left mouse button depressed and move to the top of the decision block.
When a blue bubble appears on the top of the decision block, release the left mouse button.
You will have placed a flow line from the Start block to the decision block.
STRONG RECOMMENDATION! The best tool for learning Velocio PLC programming, and doing program develop-
ment is a Velocio Simulator. They are inexpensive and very convenient. A Velocio Simulator allows you to simulate an
application, right at your desk, with switches, potentiometers and LED indicators to simulate actual IO. You can fully
develop, debug and have your application programs ready, without waiting to connect to the final hardware. You can
simulate operation without any repricussions for a mistake in your program - thereby enabling you to eliminate such
mistakes before “going live”.
The download and debug portions of all of the examples in this manual assume that you either have a Velocio Simulator, or that
you have wired up the equivalent inputs and outputs in order to simulated program operation.
This icon is the Program icon. When you click this icon, the program will be compiled and downloaded into the PLC.
Before we can program a PLC, we need to make sure that we are connected to the
PLC and the PLC is powered on. The required connection is via a USB cable from
the PC to the mini USB port on the main PLC (Ace or Branch unit). If this connec-
tion is made and the PLC is powered on, you should see a USB present indicator, as
shown on the right, in the lower right corner of vBuilder.
Also notice the lower left hand corner of vBuilder. When you press the Program
icon to compile and download, a message saying “Programming” and a progress bar
will appear. With such a small program, this may appear only instantaneously, so
be watching as you click on the Program icon. When programming is completed, the
status message in the lower left hand corner will say “Stopped”
Finally, notice that the first logic block in your program is highlighted with a green background and a yellow arrow pointing at
it. This tells you that your program is currently set to execute this program block next.
When you single step the first time, the program window
should look like this.
Single step again. You will see that the program steps
back to the decision block. When it executed the turn off
block, it turned the output off. Since it was already off, you
wouldn’t see anything change.
Switch the doorbell input back and forth. You should see
the program window switch between the two screen shots
on the right, to reflect the states. You’ll see the values of
doorbell and lockRelease displayed to reflect the current
state.
Toggle the Name/Value back and forth and watch what hap-
pens.
Hover your cursor over the turn off block. You should see
a small circle appear in the upper left hand corner of the block, as shown. This is an indication that if
you click on the block, a breakpoint will be placed there.
When you do, a red circle and blue rectangle will appear in the up-
per left corner of the turn off block. The red circle indicates that this
block has a breakpoint. The blue rectangle indicates that it applies
to the program in the blue module. Notice that the Setup window in
the upper left contains a single blue rectangle. This means that there
is only one PLC module in this application, indicated by a blue rect-
angle. If there were multiple modules in the application, there would
be a tree of rectangles, each indicated by a colored rectangle and, for
all modules other that the main Branch PLC, a number.
If you select the Run icon, the program will start, then
stop at the block with the breakpoint. If you switch the
doorbell switch to on, then, select Run, the program flow
will take the other branch and continue to run, until you
switch the doorbell back to off.
To turn the breakpoint off, click on the program block with the breakpoint. The breakpoint will disappear from the block.
• releaseTime : Timer for timing the 5 second release time. this will be a signed
32 bit integer, since all timers are signed 32 bit integers. To creste this tagname,
select i32, under Register, click the box under Name, and type in the name, release-
Time
• doorStep : A variable to keep track of the current state with respect to the
doorbell and lockRelease. This will illustrate a very simple “state machine” pro-
gram. We’ll define this as a ui8 (unsigned 8 bit integer number, which can hold a
value between 0 and 255). Use the same process to create this name, by first select-
ing ui8, under Register.
The tagname definitions of these two new variables are shown in the screen shots
on the right.
Turn Debug mode off by clicking the ladybug icon and stop the program execu-
tion by selecting the red program stop icon.
This phase of the program is going to have a lot more logic blocks, connected
much differently than the Phase I example. Since it will have major changes, the
easiest way to start is to select each of the program blocks and press the delete key
on your keyboard. Delete the whole program (except the Start block). We’ll start
over.
The program should now look like this (after you drag the Start block to the right to line
things up. To drag a block, click and hold the block, move your cursor to where you
want it, then release).
So far, it probably looks a little fuzzy as to where we’re headed. That will clear up as we enter more blocks & wire up the flow.
Right below the doorStep = 1 decision block, place another decision block that checks whether doorStep = 2. Just to the right of
that block, place a Timer Compare block.. The Timer Compare decision block icon is the one with the clock. Select
releaseTime, select the greater than or equal to comparison and type in 5. Leave the units selected to seconds (units
are selectable as a variety of ranges. Click the down arrow to see the options).
Lets go through how this program should operate. This program is written in “state machine” style. It is highly recommended
that you write your programs as state machines also. State machines divide programs into states or steps. In each step, we
know our program condition and we know what to look for to trigger an operation and to transition to another step. There is a
chapter on state machine programming, later in this manual.
The program :
• Initializes to doorStep 1
• In doorStep 1 : Waits for the doorbell to activate. When the doorbell is activate, the lockRelease is turned on, the timer is
started, and the doorStep transitions to step 2.
• In doorStep 2 : Waits for the 5 second delay, then turns the lockRelease off and transitions to doorStep 3.
• In doorStep 3 : Waits until the doorbell is off, then transitions to doorStep 1.
• In any other doorStep : This should never happen. If it does, sets the doorStep back to 1. (This is just a programming practice
to ensure the impossible gets handled).
Try programming and running the program. Try putting it in Debug mode, setting breakpoints, single stepping and watching
what happens. One thing that you will notice is that once the releaseTime is started, it will continue to time up until it is reset
with the next doorbell activation. That is because we didn’t put a Timer Pause in the program. Its not a problem, just something
to notice.
Another thing that you might notice is that the timer value in the Timer Compare block has two less digits than in the Timer
Reset and Timer Start/Continue blocks. The Timer Reset and Timer Start/Continue are displaying the time as its raw value.
Timers increment once every millisecond. The Timer Compare is showing the value in the units (seconds) that was selected for
the comparison.
When you are finished seeing all that you want to see, turn Debug off and Stop the program execution.
The temperature transducer measures temperatures between 0 and 100 degrees. It outputs an analog signal between 0 and 5V
to the PLC. There is a linear relationship between the temperature
reading and the voltage output.
Click the Tag icon, then select Float, under the Register group. Enter
‘temperature’ as a new tagname.
While you have the Tags dialog box open, look at your Output bits.
You should see that you already created the tagname ‘heater’ for
output D2.
Click OK.
Since we are going to modify the existing program, the first thing to do is to remove some of the existing flow wiring. We’ll re-
wire the flow after adding some program function blocks to do temperature control.
If you move your cursor over the connection point for any flow line, you will see
that the connection turns blue. Move over the connection out of the Copy block at
the bottom of your program. Click on the blue circle. The flow line out of the Copy
block will be deleted.
Delete all of the flow lines into and out of the Wire Router. After you do, your pro-
gram should look like the screen shot shown below.
We want to turn the heater on when the temperature is 68 degrees or below, and turn it off whenever it is 72 degrees or above.
The doorbell/lockRelease portion of your program should work just like it did before. If it does not, check your progam
. - especially the flow wiring, since that is the area that changed. Make corrections and reprogram if you see the problem. If its
not readily apparent, you may need to employ the debugging skills that you have just learned. Single stepping and/or break-
points should reveal any errors.
Once you have the chart type (Flow Chart) selected, Directory for Velocio programs (choose your own folder name)
Name entered and the path for program storage identi-
fied, select “OK”. The screen will change to look like
the one shown on the right.
Next, take a look at the tags. All data in a vBuilder program is referenced by meaningful tag names. Tagnames are names that
you choose that are meaningful to your application. You might name a digital output that controls a recirculation pump, “recir-
cPump1”, or an input connected to a limit switch that indicates the “home” position, “home”. That way, in your program, your
logic is very clearly defined.
Take a look at the Subroutine Inputs dialog box. Passing of parameters is explained at the top. There are two pass options for
passing to a subroutine object. Pass by val-
ue, indicated by a single arrow to the right
or in, passes a numeric value into the sub-
routine variable that you define. Passing by
reference, illustrated by the opposing arrows
indicating in and out, passes a reference or
handle to a variable in the calling routine.
In actuality, data and references are passed
into an object subroutine, no data is actually
passed back out. By using a reference that
is passed in, data in the calling routine can
be accessed and changed. Changing data
passed by reference is the equivalent of pass-
ing data out.
Click OK in the Subroutine Inputs dialog box when all three input
parameters have been defined.
Now we need to define a local tagname variable for a timer that times the interval between changes in the output states. All tim-
ers are 32 bit integers.
Start by selecting the Tag icon. When the Tags for the subroutine come up,
select i32 and enter the tag name “interval”. Click OK at the bottom.
Next,
select
the
Timer
icon
and drop a Timer block as
shown. Select “interval”
from the drop down list and
select Reset. This will reset
the interval timer to 0. Click
OK.
Let’s connect up the blocks that we have now. Start by placing your cur-
sor at the bottom edge of the Start block. Notice that a blue connection
circle shows up. If you left click your mouse, hold it down and drag it to
the top of the decision block, then release the mouse button, a connection
line will be drawn from the Start to the decision block, as shown.
Place a Timer Compare to the right, as shown. The Timer Compare icon is shown on the right. When you
place the Timer Compare a dialog box will pop up. Select the timer we defined (interval) by using the drop
down selection and type a 2 in the second field, leaving the selection as greater than or equal to and the time
units as seconds. When the timer value reaches 2 seconds, the program flow will execute the logic connected
to the “yes” output of this block. Until then, it will execute the “No” logic. Select OK.
You could add a Sub Return block and wire up everything as shown below. However it’s not necessary. When the program
gets to the end of a line of execution in a subroutine it will return. Putting an explicit return block in is a matter of preference. It
may make documentation more clear. Its your choice. Note : the small block on the right side that shows no operation is a Wire
Router, available at the
top of the tool bar. It
can be used to make
sure wires are routed
the way you want. It
does nothing.
Select the main program. Select and place a subroutine block. Notice when you select Cycle3 in the dialog box, the three passed
parameters will automatically come up on the right side of the pass list. You need to select the main program parameters that
you want to pass in. Select cycleStep, outStates and cycleSelect as shown, then click OK.
Take a look at the top tool bar. Next to the Program icon, you will see the Run, then
the Stop button. Next is Reset, which will cause the program to start over from the
beginning. The next set of button icons are debug functions, which we will use as we
debug this program in the following pages.
Try running the program. Click on the Run icon. The status indication in the lower left corner should change to “Running”.
If you have correctly entered the program as described and switch the input that we chose for “cycleSelect” (input B1) on, you
should see output LEDs cycle every two seconds. We intentionally put a bug in the program though. You should see two out-
puts cycling, instead of the three that we intended. That gives us a chance to debug the program.
Select Stop. The status indication in the lower left corner will say “Stopped”. Select the icon that looks like a ladybug. It is the
debug mode selection. You should see it change from indicating that it is OFF to indicating that debug is ON. You will also see
that your main and subroutine windows will have a red bar across the top. This red bar is an indication that the routine is not
currently running.
Select Run. The colored status bar on each program window will change to green, indicating that the program is running. You
will also see some decision blocks turn red and others green. This is a high level indication of the predominent execution of
each decision. To see the details, we have to look closer, but just this quick view tells us that we are executing the subroutine’s
step 2. Toggle the cycle-
Select input and you will
see the ‘run” decision in
step 2 change between red
& green. The PLCs are
only polled by vBuilder
twice per second, so there
will be a time lag on the
screen.
We need to figure out why the program is only cycling between the second and third outputs. Go to the Cycle3 flow chart and
click on the Shift block.
Notice the icons on the top tool bar that look like this -
These are single step functions. If you hover your cursor over them, you will see that the first one is “Step In”, the second “Step
Over” and the third “Step Out”. The first one can be used to step through the execution of your program, one block at a time.
The second one operates the same, except when the block is a subroutine call. Instead of stepping into the subroutine, it ex-
ecutes the entire subroutine. The third one will step through execution, but if you are in a subroutine, it will execute all blocks
until you return to the calling program; in other words, “Step Out” of the subroutine. Try these functions.
Click the Run and wait until the program breaks at the Shift block, then step through the execution for the next few blocks.
Watch the cycleData when you do this. Notice that when cycleData is shifted from the value 4 to 8, then checked to see if it is
greater than 4, the next block that executes, resets the cycleData to one (first bit on). That is what we want. If you keep stepping,
you see that it does turn the first output on. But when we run it full speed, with no break points, we don’t see the first output
coming on. What’s going on?
Select the Stop icon on the top tool bar. Click the De-
bug icon to exit Debug mode. Route the output of the
Copy block to the Timer Reset, as shown. Download
this program and run it. It will step through all three
outputs, as we intended.
Select your main program, select the Tag icon, and add the following tagname variables :
• Select Input bits and rename InBitB2 ‘cycle2Select’
• Select ui16 and add ‘cycle2Step’ and ‘outStates2’
Take a look at the list of Project Files along the left hand side of vBuilder. Next to Cycle3 is an
up and down dial and the number 1. Select up to get the number to change to 2. You’ve just cre-
ated a second Cycle3 object.
Now lets see what we can
do with it.
Program it and run it. You will see that when you flip the B1
switch (which you gave the tagname ‘cycleSelect’) on, the first three
outputs will cycle at a 2 second step rate. When you switch the B2
switch (which you gave the tagname ‘cycle2Select’) on, outputs 4, 5,
and 6 cycle. Try turning the inputs on and off. Notice that the step
time for the 2 groups is not synchronized. That is because we cre-
ated our timer in the Cycle3 object. The two objects each have their
own independent timers. If we had wanted to synchronize the step
times, there are simple ways we could have done so. The purpose
was to demonstrate that we can create two totally distinct entities,
or Objects, that operate independently, but use the same logic.
There are other powerful aspects of vBuilder that you have just
unleashed - but we’ll discuss those in later detail pages. Let’s move
on to Ladder Logic programming.
If you have installed Velocio Builder (referred to here as vBuilder) on your computer and followed all of the de-
fault settings, you should have a logo, like the one on the right, on your desktop. If you declined to put an icon
on your desktop, locate it though the Start menu of your computer.
If you get a Windows message that asks whether you want to allow vBuilder to make changes to your computer, click Yes. The
changes that vBuilder makes to your computer is saving your program files.
You should get an opening screen that looks like the one shown below. At this point you are ready to begin entering a program.
A dialog box, like that shown on the right will pop up.
At the top of the dialog box, you see that we can select
to write this program in either Flow Chart or Ladder
Logic programming. We’re going to do this one in
Ladder Logic - so click the radio button next to Lad-
der Logic.
The first step is to select the PLC main CPU. This will
be either an Ace, or a Branch unit. The selections are
the labeled, gray squares below the Ace & Branch icons.
These selections identify both the type (Ace or Branch)
and the associated IO configuration. Select the one that
applies to the application. In this tutorial example, any
of these units will work. The configuration that you
select will turn blue, as shown.
The tagname dialog box will open. Select the various options on the left under Input/Output and Register. You will see that
when you select any of the options under Register, you get a blank table. That is because we haven’t created any tagnames yet.
Register tagnames are just general data identifiers that will mean something and hold information for your program. They are
not directly tied to inputs or outputs.
Notice that there are lists of tagnames for Input bit, Input i16 and Output bit. These were automatically created when you set
up the PLC hardware to run on. vBuilder knows that an A100-222 has 12 digital inputs. It automatically creates tagnames for
each of the digital inputs. These are default names. You can change to more meaningful names, if you want. The default names
are pretty simple. For example, InBitB1 is assigned to the digital input connected to the signal B1.
Likewise, tagnames are automatically created for the 12 digital outputs, located in the Output bit list and the 12 analog inputs,
located in the Input i16 list. The raw analog input values are signed 16 bit integer numbers.
In the Output bit list, rename the D1 output “lockRelease”, and the D2 out-
put “heater”.
Next, change the tagname of the first analog input (Input i16) to “rawTem-
perature”, as shown.
Along the right hand side of vBuilder is the Toolbox. The Toolbox contains all of the program tools
necessary to build a program. There are two basic types of tools :
• Contact blocks : contact blocks make a decision whether something is true or not. If it is true, the
program will flow through the contact to the next progam block. If it is false, program flow will stop,
for the particular rung, at that contact. There are contact blocks for whether a bit is on or off, numeric
comparison decision blocks and timer based decisions. The contact blocks are all near the top of the
toolbox, below the Wire and above the Coil.
• Process blocks : Process blocks do something. That something can be to turn something on or off,
perform a calculation, count, filter, control a stepper motor, PID, etc. The Process blocks begin with Coil
and end with Timer.
Congratulations! You have just written the simplest Ladder Logic program that you will ever write. It should look like the il-
lustration below. If so, we’re ready to try it.
STRONG RECOMMENDATION! The best tool for learning Velocio PLC programming, and doing program develop-
ment is a Velocio Simulator. They are inexpensive and very convenient. A Velocio Simulator allows you to simulate an
application, right at your desk, with switches, potentiometers and LED indicators to simulate actual IO. You can fully
develop, debug and have your application programs ready to deploy without waiting to connect to the final hardware.
You can simulate operation without any repricussions for a mistake in your program - thereby enabling you to eliminate
such mistakes before “going live”.
The download and debug portions of all of the examples in this manual assume that you either have a Velocio Simulator, or that
you have wired up the equivalent inputs and outputs in order to simulated program operation.
This icon is the Program icon. When you click this icon, the program will be compiled and downloaded into the PLC.
Before we can program into a PLC, we need to make sure that we are connected to the
PLC and the PLC is powered on. The required connection is via a USB cable from the PC
to the mini USB port on the main PLC (Ace or Branch unit). If this connection is made
and the PLC is powered on, you should see a USB present indicator, as shown on the
right, in the lower right corner of vBuilder.
Also notice the lower left hand corner of vBuilder. When you press the Program icon to
compile and download, a message saying “Programming” and a progress bar will ap-
pear. With such a small program, this may appear only instantaneously, so be watching
as you click on the Program icon. When programming is completed, the status message
in the lower left hand corner will say “Stopped”
To illustrate program operation, click on the green arrow in the top toolbar. That’s the Run icon. Also click the ladybug icon.
The ladybug turns Debug on and off. When its in Debug mode, the ladybug, and the 5 icons to its right will all be lit up, like
shown below. Turn Debug on.
When a Ladder Logic program runs, it starts at the top rung of the ladder and works down. Each rung is solved, one at a time,
then the next rung is solved, until the program reaches the last rung. When the ladder logic is completed, the PLC writes the
outputs, reads the inputs, handles communications and other administrative tasks. Then it starts all over at the top of the lad-
der, solving again.
In this case, we only have one rung. The PLC will solve the rung, handle IO, communications, etc., and repeat in a continuous
loop, as long as the program is in Run mode.
Notice that if you flip the switch for the B1 input, which you tagnamed, “doorbell”, the D1 output (lockRelease) will turn on and
off - reflecting the state of the doorbell. Also, you should see the doorbell contact in vBuilder turn between green (on) and red
(off). Another thing to note is that the top of the program window turned green. This is an indication that the program is run-
ning.
A one rung program is not long enough to illustrate other Debug functions, so let’s go on the Phase 2 of our tutorial program.
• releaseTime : Timer for timing the 5 second release time. This will be a signed 32
bit integer, since all timers are signed 32 bit integers. To create, select i32 on the left pane,
then select the block under “Name”, type in releaseTime and Enter.
• doorStep : A variable to keep track of the current state with respect to the doorbell
and lockRelease. This will illustrate a very simple “state machine” program. We’ll define
this as a ui8 (unsigned 8 bit integer number, which can hold a value between 0 and 255).
• initialize : A bit variable that we will use to cause the doorStep to be initialized to 1,
the first time through the logic rungs.
The tagname definitions of these three new variables is shown in the screen shots on the
right.
Turn Debug mode off by clicking the ladybug icon and stop the program by selecting
the red program stop icon.
This phase of the program is going to have several rungs that are different than the
Phase I example. Since what we have now is a
trivial program, the easiest way to start is to delete
the whole program. We’ll start over.
Next, select a Copy block from the Toolbox and place it at the end of the first rung. In the dialog box, select the basic copy (just
labeled “Copy”) Type ‘1’ in the first From and select ‘doorStep’ as the first To. Click OK.
All data is initialized to zero at program start up. The reason we’ve placed a Normally Closed contact is that a Normally Closed
contact is closed when it’s value is 0. So at start up, the rung will solve true and the copy will happen.
Initialization is something that we want to happen only once. So we need to make sure the initialize contact is never closed
again. We’ll do that with the next rung. Place another normally closed initialize contact on the next rung, then select and place a
coil. In the Coil dialog box, select a Set Coil, then select initialize as the Output Bit.
The difference between an Out Coil and either a Set or a Reset Coil is that an Out Coil will always turn the value of the
tagnamed bit to the solve value (true (1) or false (0)) of the rung, while the Set Coil and Reset Coil set the tagnamed bit to
a 1 or a 0, respectively, only if the rung solves to true.
Click OK.
Step 3 just needs to wait until the doorbell switch is turned off, then set the doorStep back to 1 to begin the process all over
again. This can be done with one rung. Enter the rung shown below. Notice that this rung will use a Normally Closed contact
for doorbell. You want the Copy to execute when the doorbell switch is off.
You can Zoom the program window display in and out using the Zoom icons on the top toolbar.
You can also use the View/Hide arrows on the three panes on the right, left and bottom (the blue V).
Look at the program window. It should have a red strip across the top. The red indicates that the program is stopped. In the
red strip is a small blue rectangle. The blue rectangle is the same indicator as in your Setup window. It indicates that the pro-
gram is located in the main (or in this case, only) PLC unit.
The first rung of your program should appear with a yellow background and a yellow arrow, pointing to it, on the left side.
This is a status indication, showing that the program is stopped at this rung. Whichever line is highlighted like this is the next
rung to be executed.
Click the Name/Value icon a few times to toggle between displaying tagnames and the value of the data in the
tags. Notice that before any rung is executed, the value of the initialize flag is 0 and the value of doorStep is 0.
The initialize contact is displayed as green. This means that the path through this contact will solve “true”. If there is a path
from the power rail, on the left, all the way to the function block on the right (in this case, a Copy), the function block will
execute. A Normally Closed contact, whose tagnamed bit value is 0, solves to true. Conversely, a Normally Open contact, with
the same 0 value would solve to false.
Since there is only this one contact in the rung, the Copy will execute.
Single Step again. Now, doorStep is 1 and initialize is also 1. The execution of the second rung Set initialize to 1.
Another thing to notice is that the initialize Normally Closed contacts are now displayed in red. That mean that the rungs will
solve false through those contacts and not execute the blocks at the end of the rungs. Since you only want to execute initializa-
tion once, this is what you want.
Your program is now in doorStep 1. Looking at the third, fourth and fifth rungs, you can see that the doorStep Equals 1 contact
in each rung is green, indicating that that rung will solve true. However, unless you have switched the doorbell switch (B1) on,
the doorbell contact is red, indicating that it will solve false. That means that there is not a complete ‘true” path from the power
rail to the function blocks in these rungs. As long as that is the case, the function blocks will not execute.
will be displayed in green. There should be a complete green path from the power rail to the function blocks of step 1 (rungs 3,
4 and 5). This means that the the function blocks will execute.
Keep stepping through. Notice that when you step through rung 5, that the lockRelease output (D1) will turn on and doorStep
will change to 2. The program window display will now show that doorStep 1 rungs are blocked by the doorStep = 1 contacts
and the doorStep 2 rungs will solve past the doorStep check contact.
In rungs 3 and 4, the releaseTime timer was started and Reset to a value of 0.
At this point, the debug features are not as effective for Ladder Logic as for Flow Chart programs. Timers don’t time while
single stepping, so we can’t single step until the 5 second timeout times out. In Flow Chart debug, what you would do is put
a breakpoint on a block that would be reached at the end of the timeout and run to the breakpoint. Since Ladder programs
execute all rungs, a breakpoint to wait out the delay won’t work (you would hit the breakpoint on every program pass).
If we had used subroutines in this program, it might be possible to effectively use breakpoints. However, we didin’t & we’re not
ready for those yet. What we can do is run the program at full speed and watch what happens.
You may notice a hollow circle that follows your cursor, moving to whichever rung your cursor is over. This is an indication of
where a breakpoint will be placed if you left click. Try it on one of the rungs. Just left click. You will see that the circle fills in,
red. This indicates that if you Run the program, it will stop at this rung. Also, a little blue square shows up below it. The blue
indicator shows that the breakpoint is in the main PLC’s program (which is the only one we have in this example).
Let’s see how this works. Click the Run icon on the top toolbar (the green arrow icon). Your program will begin run-
ning and will continue to run until it reaches the breakpoint you just set. This will be instantaneous. If you click the
Run icon again, it will appear like nothing happen. Actually the program will run again, back to the breakpoint. It
just happens so fast that it looks like nothing happened.
Now, lets just run the program and watch it work. Click run.
Flip the doorbell switch (B1). Notice that when you do, the lockRelease output (D1) will turn on and stay on for 5 seconds, then
turn off. Turn the doorbell switch off, then on again. If you watch, in the Value mode, a program block that has the releaseTime
timer, you will see
that the time counts
up. The screen shot
on the right shows a
releaseTime value of
168. That means that
168 milliseconds has elapsed since the doorbell switch was turned on. If you watch it, you will see that when the releaseTime
reaches 5000 (5 seconds), the lockRelease will turn off.
You will also notice that releaseTime will continue to count up. Once a timer is Started, it will continue to time until the pro-
gram executes a Pause for that timer. Your program doesn’t have a Pause block. It doesn’t matter. The timer continuing to
count up has no effect on anything. If you really want it to stop, you could create another doorStep 3 rung and put a Pause in it.
Flip the doorbell switch back off. This should cause doorStep to be set to 1, where it again waits for the doorbell to be switched
on. Each time you flip the doorbell switch on, the lockRelease will turn on for 5 seconds.
You may notice that occasionally, if you leave the doorswitch on for the 5 second releaseTime duration, then flip it off, the lock-
Release may start again. This is not a error. It can occur if you transistion the switch slowly. As you do, the mechanical contact
in the switch may reach a point where it there is “contact bounce”. Contact bounce is when the switch condition transitions
from closed to open to closed very quickly. This can happen with a manually actuated switch if there is momentary hesita-
tion in the movement. With a Velocio simulator, you can see this if you have the switch in the on position and lightly press it
towards off, but don’t actually move it.
Contact bounce can happen in with electromechanical switches, but is less likely with electrically actuated devices than human
actuated ones. If there is a chance for contact bounce, it is very easily handled in a vBuilder program. You just place debounce
logic or a debounce subroutine in the program. We won’t go into that here, but it is covered in an application note.
Continue to play with the operation and view it until you have a good understanding of everything that happens. You can put
in breakpoints, single step & run at will. Another thing you can do is Run (clicking the green Run icon) and Stop (click the red
Stop rectangle icon). You can go back and forth between Run and Stop.
When you are done, click the ladybug icon to turn Debug off.
The temperature transducer measures temperatures between 0 and 100 degrees. It outputs an analog signal between 0 and 5V to
the PLC. There is a linear relationship between the temperature reading and the voltage output.
Click the Tag icon, then select Float, under the Register
group. Enter “temperature” as a new tagname.
While you have the Tags dialog box open, look at your
Output bits. You should see that you already created the
tagname “heater” for output D2.
Click OK.
Select the Scale function icon from the Toolbox and place
it at the end of the next available rung. In the dialog box,
select rawTemperature as the Input and temperature as the
Output. For the conversion, place 0 and 4095 as the first two
Input values and 0 and 100 as the corresponding Output
values. The graph in the dialog box will illustrate how what
the Scale function will do.
If you move your cursor into the graph area, as you move along the Input (X) axis, you can
see the Output values that each Input will translate to.
For this rung, we did not put any contacts before the Scale function block. That is because we
want to the Scale to always execute, unconditionally.
Follow this rung with another one that checks whether temperature is Greater Than or Equal to 72 and, if so, Reset the heater, as
shown.
What you now have is a program that will still operate the same with the doorbell and lockRelease. It will also control the
heater to maintain temperature between 68 and 72 degrees.
Click the program icon to program the PLC. Put it in Debug mode. Start it by clicking the Run icon. Try the doorbell again.
The operation should be the same as previous.
Put the PLC into Debug mode and select to display Values. Look at the rung that you placed the Scale block in. As you turn the
A1 potentiomenter, which was assigned the tagname rawTemperature, you should see both the rawTemperature and tempera-
ture values change. The rawTemperature will be between 0 and 4095, which is the raw input range for all analog inputs. The
temperature values should be between 0 and 100. The Scale block converts the rawTemperature to temperature. When you en-
tered the Scale block, you set it up for a linear conversion between minimum and maximum values. Twist the A1 potentiometer
back and forth and watch the rawTemperature value and the temperature that the Scale block converts it to.
As you move the temperature up, you should notice that the heater output (D2) will stay on until the temperature is Greater
Than or Equal to 72. At that point the heater output bits will be Reset to 0, turning the output off. It will not turn on again until
the temperature again drops to or below 68.
This type of temperature control is called hysterisis control. It is what a thermostat does.
Play with this example until you have mastered it. You can set breakpoints, single step, toggle between Name and Value, start
and stop it. It should give you a good understanding of basic Ladder Logic programming.
When you are done, you are ready for the next tutorial. In the next tutorial, you’ll learn about subroutines and objects. These
are some of the advanced features of vBuilder, which enable powerful functionality, improve programming efficiency and make
implementing more complex programs an easier task.
Once you have the chart type (Ladder Logic) selected, Name
entered and the path for program storage identified, select “OK”.
The screen will change to look like the one shown on the right.
Next, take a look at the tags. All data in a vBuilder program is referenced by meaningful tag names. Tagnames are names that
you choose that are meaningful to your application. You might name a digital output that controls a recirculation pump, “recir-
cPump1”, or an input connected to a limit
switch that indicates the “home” position,
“home”. That way, in your program, your
logic is very clearly defined.
There are also a few special special case selections for IO for
some of these types, listed for convenience, such as input bits.
Move your cursor over to the Toolbox, located along the right
side of vBuilder. Select a Normally Closed Contact (top con-
tact, right side - if you hoover over the icons, a help label will
appear for each one). Left click and hold the Normally Closed
Contact while you move your cursor to the left portion of the
first rung, then release. [Alternatively, you can click & release
the icon to select,then move the cursor to where you want to
drop it, and click and release again]
The Normally Closed Contact will drop onto the rung and
a dialog box will open. The dialog box allows you to select
which bit to associate with the contact. Go to the drop down
box and select “initialized”,as shown, and click OK.
Next, select
the “Copy”
icon and place
a Copy block
on the (no-op)
symbol, just
like you placed
the Normally
Closed Contact.
A Copy dialog box will also pop up. A dialog box provides
the means for you to define exactly what the block will do.
Take a look at the top of the dialog box. You see three selec-
tions. The Copy selection is highlighted. The Pack and
Unpack options are grayed out. The simple Copy selection
allows you to copy data into up to 16 tagnamed variables
from other variables or constant values. The Pack copy per-
forms a copy of up to 16 individual bits, into an integer. The
Unpack copy moves selected individual bits from an integer
into bit tagnames. If you click on pack or unpack, you will
see that the selected option becomes highlighted, the other
options are grayed out and the dialog box selections change.
Enter ‘1’ in the first “From” box and select “cycleStep” from
the drop down list for the first “To” box., as shown on the
right. In the second
“From” box, type in
another 1. In its associ-
ated “To” box, select
“initialized” from the
drop down list. Select
“OK” at the bottom of
the dialog box.
Next, se-
lect the
Timer
icon and
drop a
Timer
block as shown. Select “interval”
from the drop down list and
select Reset. This will reset the
interval timer to 0. Click OK.
Enter the next two rungs as shown below. The first contact on each rung will check whether the current step (cStep) is step 2. If
it is and the “run” bit is active (the run bit is passed from the main program), the Timer will be Started or Continued. If “run” is
inactive, the Timer will be Paused.
Now, for the rung action, select a “Shift/Rotate” block and place it at the end of the rung. In the dialog box, select Shift and
left. Enter 0 as the input bit, select cycleData for output and enter a 1 as the number of bits to shift, as shown. This will create a
program block that will shift the 1 in cycleData one position left, each time it is executed.
We are actually
entering an error
here. It will give
us a chance to
demonstrate some
debug features.
Click ‘OK’.
Finish the rung by placing a Copy block. Using the Copy block dialog box, create a copy of the value 1 to cycleData.
The last logical operation we need to do is restart the timer. On the next rung, start by performing the check for step 2, followed
by a Timer Compare to check that the time is Greater Than or Equal to 2 seconds. Finish the rung by placing a Timer reset to
clear the time to 0.
idea to put in these kinds of checks, then monitor if they ever happen. If it does happen, you can start debugging your pro-
gram logic to determine why. It won’t happen on such a simple program as this, and the object oriented program architecture
vBuilder protect against one area of code clobbering another area. Particularly in development stage, its a good idea to put in
checks anyway.
Cycle3 is a simple state machine (see the chapter on state machines for a more thorough discussion). In the first step, the timer
and output data are initialized. In the second step, if the run switch is on, the data is shifted around a loop every 2 seconds. If
the run is not on, it maintains the outputs in the condition when the run was switched off. You should never get to any other
step, but if you do (it would have to be some error somewhere else), this subroutine will restart step 1.
Select the main program. Select and place a Subroutine block (near the bottom of the Toolbox) as the action
for rung 2. Notice that when you select Cycle3 (the only subroutine available to select, since its the only one
we have defined), the three passed parameters will automatically come up in the list on the right. You need
to select the main program tagnamed parameters that you want to pass in. Select cycleStep, outStates and cycleSelect as shown,
then click
OK.
Take a look at the top tool bar. Next to the Program icon, you will see the Run then
the Stop button. Next is the Reset, which will cause the program to start over from
the beginning. The next set of button icons are debug functions, which we will use as we debug this program in the following
pages.
Try running the program. Click on the Run icon. The status indication in the lower left corner should change to “Running”.
If you have correctly entered the program as described and switch the input that we chose for “cycleSelect” (input B1) on, you
should see output LEDs cycle every two seconds. We intentionally put a bug in the program though. You should see two out-
puts cycling, instead of the three that we intended. That gives us a chance to debug the program.
Select Stop. The status indication in the lower left corner will say “Stopped”. Select the icon that looks like a ladybug. It is the
debug mode selection. You should see it change from indicating that it is OFF to indicating that debug is ON. You will also see
that your main and subroutine windows will have a red bar across the top. This red bar is an indication that the routine is not
currently running.
Select Run. The colored status bar on each program window will change to green, indicating that the program is running. You
will also see some contacts turn red and others green. This is a high level indication of the predominent execution of each deci-
sion. To see the details, we have to look closer, but just this quick view tells us that we are executing the subroutine’s step 2.
Toggle the cycleSelect input and you will see the ‘run” decision in step 2 change between red & green. The PLCs are only polled
by vBuilder around
twice per second,
so there will be a
slight time lag on the
screen.
Notice the icons on the top tool bar that look like this -
These are single step functions. If you hover your cursor over them, you will see that the first one is “Step In”, the second “Step
Over” and the third “Step Out”. The first one can be used to step through the execution of your program, one rung at a time.
The second one operates the same, except when the block is a Subroutine call. Instead of stepping into the subroutine, it ex-
ecutes the entire subroutine. The third one will step through
execution, but if you are in a subroutine, it will execute
all blocks until you return to the calling program, in other
words, “Step Out” of the subroutine. Try these functions.
Click the “Run” green arrow again, while you still have De-
bug On. The program should be running full speed. Move
your cursor around. Notice that whichever rung your cursor
is over will have a hollow round indicator, like that shown on
the right, just to the left of the rung. This is an indication that
you can place a breakpoint here.
With Ladder Logic, we can break on rungs, not individual program blocks. For a program where the error that we are try-
ing to track is something that happens very intermittently, its a little more difficult to catch in ladder than with flow charts. In
this case, the shift operation happens only every two seconds. The PLC will execute the program hundreds, possibly over a
thousand passes through the program between each shift. Since we can’t put a break on the exact program pass where the shift
occurs, like we can in vBuilder Flow Chart programming, its nearly impossible to catch the exact program pass that we are inter-
ested in. This problem does not exist with logic that is not so intermittent.
Even with the inability to break on the exact Shift operation that we are interested in, the Debug features of vBuilder provide
enough information to track down and solve this problem. Just put the program in Run, in the Debug mode and watch it.
Select “Value” for the Name/Value selection. As you watch the 5th and 6th rung of the Cycle3 subroutine, you will notice that
the Output of the Shift Left, which is cycleData, changes between 1 and 2, but never appears as 4. Our intent is for it to cycle
between 1, 2 and 4.
Look at the next line and we see the problem. As soon as we shift cycleData to 4, the next line checks to see if cycleData is
Greater Than or Equal to 4. If it is 4, the contact is closed and the program will copy the value 1 to cycleData. The subroutine
will never return to the main program with cycleData being a 4. That’s exaclty what we see in the operation.
The error that must be corrected is the check for Greater Than or Equal to 4. We could do that either by changing to check for
Greater Than or Equal to 8, or change the check to just Greater Than 4. Let’s do the second choice.
Select your main program, select the Tag icon, and add the following tagname variables :
• Select Input bits and rename InBitB2 ‘cycle2Select
• Select ui16 and add ‘cycle2Step’ and ‘outStates2”
Take a look at the list of Project Files along the left hand side of vBuilder. Next to Cycle3 is an up and
down dial and the number 1. Select up to get the number to change to 2. You’ve just created a second
Cycle3 object. Now lets see what we can do with it.
Now add a second Subroutine call to Cycle3 and a second Copy Unpack as shown. Make sure you select Data Set 2. Pass cy-
cle2Step, outStates2 and cycle2Select in. For the Copy Unpack, unpack from outStates2 to OutBitD4, OutDitD5, and OutBitD6.
Your program should look like the illustration on the right. Be sure to add the initialization of cycle2Step to 1 in the first rung
copy statement.
Program it and run it. You will see that when you flip the B1 switch (which you gave the tagname ‘cycleSelect’) on, the first
three outputs will cycle on a 2 second step rate. When you switch the B2 switch (which you gave the tagname ‘cycle2Select’) on,
There are other powerful aspects of vBuilder that you have just unleashed - but we’ll discuss those in later detail pages.
This is your starting point. The large area in the center is where you enter, edit and debug your application program. Every-
thing else, surrounding that area, contains the tools that allow you to do so. The general screen areas are labeled with num-
bered bubbles, which are explained below.
1) General menu bar (similar to most Windows applications).
2) Quick access tools which are available when not grayed out.
3) The program hardware set up
4) List of programs and subroutines associated with the application program.
5) Program information window.
6) Program Toolbox tools, which may be either ladder or flow chart components, depending on your
selection
7) Status indication, including connection status to a PLC and cursor location within a ladder or flow
chart.
When you select New, a dialog box, like that shown below, will pop up. With this dialog box, you
can create a name for your project, tell vBuilder where to put it on your computer and define whether
you want the main program to be a Flow Chart or Ladder Logic program.
• Select Flow
Chart or Ladder Logic
by using the selection
buttons at the top of
the dialog box.
• Type in the
name of your project
in the text box below
“Name”
• Under “Path”
select the directory
where you want to
store your program.
Its a good idea to cre-
ate a directory to store
all of your programs
and select that direc-
tory. Once you create
the directory, you can
browse to it and select
it using the Browse
button.
• It is highly recommended that you keep the “Create Directory for Project” checked. If it is checked, it will create a subdirec-
tory, under the directory the you defined for Path. That subdirectory will have the same name as your project name and will contain
all project files.
Depending on whether you selected Ladder Logic or Flow Chart, your next screen will look like one of the two below. The
large area in the middle is the area where you build your program. With a Flow Chart selected, it will open with a Start block
and the Flow Chart tools in the Toolbox on the right. If you select Ladder Logic, the screen will contain an empty Ladder chart
with one rung that is simply a NO-OP, and Ladder Logic tools in the Toolbox.
The easiest way to Set Up the Project hardware is to have it all connected, powered up and connected to your computer with a
USB cable. If you do that, you can auto configure. You will still have to configure the high speed counters and stepper motion
controls and a few other details, but the majority of the set up will happen automatically.
The other option is to go through the process of manually selecting each device and option. Manual configuration is pretty easy
and quick, as well.
vBuilder will read the attached configuration, then display what it finds. In the example,
below, we connected to a Branch unit that had 12 digital inputs, 12 digital outputs and 6
analog inputs, . The Branch has one Branch Expansion unit with 12 DI, 12 DO and 6AI
attached to the second vLink expansion port. When we autoconfigured, the screen, shown
below, appeared.
Notice that that all of the PLC modules, Ace, Branch or Branch Expansion are shown. For
each module, the Input/Output and connection details are shown in a color coded box.
This particular configuration shows one
Branch unit connected to one Branch
Expansion unit through the second vLink
expansion port. The 2 in the Branch
Expansion block indicates the port 2 con-
nection.
• New or exist-
ing file : If you will be
creating the program that will reside in the Expansion unit, check new. Checking new means that a new program will be created
as the embedded object subroutine. If you already have a subroutine written that you want to place in the Branch Expansion, select
existing file. If you want to place the same new program in more than one expansion unit, select new for each Branch Expansion
and type in the same name.
• Name : If this is a new embedded object subroutine, type in the name that you want to use for it. If you selected “existing file”,
use the browser to select the existing object subroutine that you want to place in the expansion unit. [One key feature of embedded
object is that they can be reused]
• If this is a new embedded subroutine, select whether flow chart or ladder logic will be used to develop the main program.
Click Next
All of the settings can be made by selecting from the drop down lists. In
addition to configuring each port for either Modbus or Custom, selections
for baud rate, parity and the number of stop bits can be made. The key is to
match these selections to the configuration of the device with which you are
communicating.
Click Next
If a thermocouple is select-
ed for the input, the value
placed in the tag named
variable (IO configuration)
will be temperature in
degrees Celcius.
Click Next.
Any IO points that you select for high speed pulse counting or stepper motion are dedicated for those functions and not avail-
able for general purpose IO.
Click Next.
Here is a configuration
consisting of 7 modules at
four levels. Notice that each
module is color coded and
listed on the side.
Click Next.
A key characteristic of
Embedded Subroutines
is that they are a Sub-
routine of the program
above them in the tree
structure. In the config-
uration shown, ‘Conv-
eryor’ and ‘LiftArm’ are
Subroutines of the main
program. ‘Conveyor-
Motion’ is a Subroutine
of ‘Conveyor’.
When you’ve got the definition set up like you want, click Next.
All of the settings can be made by selecting from the drop down lists. In
addition to configuring each port for either Modbus or Custom, selections
for baud rate, parity and the number of stop bits can be made. The key is to
match these selections to the configuration of the device with which you are
communicating.
Click Next
If a thermocouple is select-
ed for the input, the value
placed in the tag named
variable (IO configuration)
will be temperature in
degrees Celcius.
Click Next.
If you select the pull down arrow under High Speed Counter Type, you
will see that you can configure for a simple pulse input, a quadrature
input or none.
If you select a pulse input, you will next need to select one digital input
on the module to dedicate to high speed pulse input. If you select con-
figuration for a quadrature pulse counter, you must select one input each
for the A and the B inputs. The selected inputs will be dedicated to HS
counter usage and not available to use for general IO.
• Selecting the Tag icon, the particular data type and typing into the next unused entry
• In a function block dialog box, type in the new name of a tagname variable
• In a subroutine Input definition dialog box, type in a new tagname
Tagname variables are only available for viewing and entry in context. In the main program, only main program vari-
ables are in context and can be defined, edited, deleted and viewed. In a subroutine, only the object data associated with
the subroutine’s object type are in context. In an embedded object, only the the embedded object’s data is in context.
For IO tags, all of the IO points will be assigned default tagnames at setup. If you want to modify these tagnames to more mean-
ingful names (recommended), you must do so by going through the Tag icon, selecting the name and typing in the new name.
You can come back and edit, add and delete tagnames at any time. Remember that if you delete or change the name of a tag-
named variable that you have used in your program, you will get an error indication informing you that you must resolve the
problem
You can also perform exactly the same operation by selecting a Tag icon, wherever it appears. This happens in every dialog box
that has parameters and the Input/Output dialog box.
During the data type selection, there may also be a check box for “Re-
mote Writeable”. Selecting this box will enable the variable to be written
to via a communications link, such as Modbus. If you do not select this
box, the variable will not be allowed to be written to by a remote device.
With vBuilder, programs are normally developed with subroutines; maybe even embedded subroutines. A big part of the pro-
cess is figuring out how to break up the program logic into subroutines that make logical sense. With just a little practice, this
becomes pretty natural.
The description of all of the ladder function blocks is covered in Chapter 4 : Ladder Logic Programming.
As you are placing contacts, you will encounter situations when the full contact connection will not be made. This enables you
to connect it as you wish. Such a situation is shown on the right.
When the second contact is placed below the first one, the left
side connection is made automatically. The right side terminates
without a connection. To complete the connection so that InBitB2
is in parallel with InBit1, select Wire tool, from the top of the
Toolbox, then move your cursor to where you want to start your
wire connection. In this case,
we want to draw a line from the
end of the InBitB2 block to the
end of the InBitB1 block, so we
move the cursor to the end of
InBitB2, as shown. Click on that
spot, then move to where you want to connect, as shown on
the right. The line with blue dots on each end shows where
the connection will be placed. Click on the top connection
point. The connection will be made and the blue dots will
disappear.
Operation function blocks go on the right end of the rung. Every rung consists of “If this, then do that”. The if portion is built
up from contacts and can range from “if always” (no contacts), to something pretty involved. Every rung must have an opera-
tion block on the end. An example is shown below.
If you move your cursor over one of these points, it will turn solid blue. If you left click,
when a point is solid blue a connection line will appear.
If you move the cursor, while keeping the mouse left button held down, to another block,
that block’s available entry points will show up as blue circles. If you move your cursor to
one of those circle, it will highlight in solid blue, as shown on the right. If you then release
the mouse, the connection will be made.
Once you place the connecting line and make the selection for Yes or No, the flow chart will
show it, as shown on the right.
The solution to this problem is found in the tool at the top of the Toolbox, labeled “Wire Router”.
If you click the Note icon and move your cursor over the flow chart,
the note block will move to where you move your cursor.
When you get the note where you want it, click the left cursor button
again to place it. Immediately, a dialog box, shown on the right, will
pop up. Click inside the box on the left and type whatever note you
want. The box on the right will preview what the note will look like.
If you look on the left side of vBuilder, under Project Files, you will see a list of all
programs that currently exist in the project. In the example shown on the right,
HomeAutomation is the main program for project HomeAutomation (the main
program is given the same name as the project). When Setup was performed to
define the project hardware configuration and Embedded subroutines, three of
the modules were defined as having embedded subroutines, which were given
the names “Conveyor”, “LiftArm” and “ConveyorMotion”.
The colored, numbered boxes on the left of each program name indicates where
the program resides. The unnumbered blue box is the main Branch module. The
orange box labeled ‘1’ indicates that the embedded object program, “Conveyor”,is
located in the Expansion unit labeled with an orange one in the Setup Hardware
diagram. Likewise, the orange ‘2’ and red ‘2’ define the locations of “LiftArm”
and “ConveyMotion”.
Embedded Object programs are the main programs for each of the devices in
which they are resident. They serve as subroutines to the program just above
them. In other words, Conveyor is the main program residing in Branch Ex-
pansion orange 1 and serves as a subroutine to HomeAutomation in the main
PLC. ConveyorMotion is the main program in the red 2 Expansion and serves
as a subroutine to Conveyor in orange 1.
You can select either a new or an existing subroutine. If you have an existing subroutine that you want to re-use in this proj-
ect, you simply select “Select Existing Subroutine”, then select “Click to Select Subroutine” and browse to find the subroutine
(probably in another project folder) to use. Once you’ve found it, click “Add Subroutine”. The subroutine will be copied to this
project’s folder for use.
Re-using subroutines is a powerful capability of vBuilder. Over time, you can create your own library of standard sub-
routines that you can use in project after project. The potential improvement in development efficiency is very substan-
tial.
The new subroutine will show up on the list of Project Files, as shown on the
right. Subroutine tempControl is shown under HomeAutomation, since we cre-
ated it by clicking the “Add Subroutine” under HomeAutomation. That means
it will be a subroutine located in the main PLC and can be called by the Home-
Automation or other subroutines under HomeAutomation.
Notice that there is a numeric adjustment control with the number ‘1’ next to
tempControl. The number (currently 1) is the number of instances of the object
tempControl that are present. By adjusting with the arrows, the number of
instances can be set to any value between 1 and the limit set by vBuilder (cur-
rently 16). Each instance of an object has its own object data.
The top of the dialog box shows a pass key. It shows that a pass
type indicated by a single arrow coming in, is pass by value. Pass by
value means that a numeric value is passed from the calling routine
to this routine. If the numeric value comes from a tagnamed variable
in the calling routine, the subroutine cannot affect the value in the
variable in the calling program. It just uses the value passed in.
The symbol with the highlighted arrows going both ways is a pass
by reference. Pass by reference means that a “reference” to a data
item is passed in. No actual data is actually passed into the subrou-
tine. The tagnamed data for the reference is data that the calling
routine either has or has access to. This is the way data is passed
out of a subroutine. To pass data out, the subroutine uses the refer-
ence to place a numeric value in tagnamed variables that the calling
routine has access to.
To create a new list of subroutine Input and Output tagnames, using the Inputs and
Outputs dialog box, type in a new name (like the very unimaginative “newSubFloat1”
shown) and hit Enter. When you do, a box will pop up, asking you to select the data
type. Click on the data type the you want. For newSubFloat, the selection should be
Float.
If you select OK, the next thing you need to do is select either the single arrow in or the
arrows both ways to define whether this is a pass by value (single arrow in) or pass by
reference (arrow both ways). Pass by value passes a numeric value into the tagnamed
variable that you just created, each time the subroutine is called. Pass by reference
passes a “handle”, or a means to access a variable that is either located in the calling
routine’s data, or is a reference that was passed into it (meaning that the actual tag-
named data is located in another level of routine).
In a vBuilder program, and entire array can be passed in by reference, only. Passing in by value is only available to a particu-
lar element of an array. If you click OK, after entering a new tagname, without an index, and select “Is Array”, the item will
be placed in the Inputs and Outputs list and automatically set to be a pass by reference. In this case, you cannot select pass by
value.
If you either give your array tagname an index when initially typing it in, or go back
and edit it to place an index, you’ve put an element of an array on your pass list. An
array element can be passed by passed by value only.
The linking of subroutines occurs when a subroutine is added. Once you have created a subroutine, the next time you select
“Add Subroutine”, the dialog box has an additional feature. A selection for either “New Data Set” or “Link to Existing Data Set”
is offered. If you select New Data Set, you will be telling vBuilder to not link this subroutine to any existing subroutine.
If you select “Link to Existing Data Set”, you will be telling vBuilder that you are adding another subroutine to an existing
object. The dialog box will allow you to select from all of the existing objects to link to. Each object is identified by the first
subroutine created in the list of linked subroutines. The example below shows the creation of a new subroutine, given the name
TankDrain. The selection is to make it a Linked Subroutine and link it to TankControl.
After the linked subroutine is created, it will show up in the Project Files list. The
illustration on the right shows TankDrain as a subroutine that is part of the Tank-
Control object. Two other subroutines, TankControl and TankInit are also part of
the same object. As members of the object, all linked subroutines have access to
all of the object data. If you create an object tagname while editing one subrou-
tine, it is available to all linked subroutines.
Notice the number 3, with the adjustment controls next to TankControl. The three
indicates that there are three instances of the TankControl object in the project.
You can set the number of instances by using the up/down controls.
The chain symbol next to TankControl, TankInit and TankDrain indicates that
these three subroutines are linked and provide different functionality for the same
object.
Another case of subroutines that are linked, is object BasketPick. That object
includes BasketPick, ArmInit, BatchProcess, TankTransfer and BasketDrop, all
linked as the same object. The adjustment indicator show that there is one in-
stance of this object.
Two other objects, OpControl and DataInit are unlinked subroutines with one
instance each.
If you select ‘rename’ a dialog box will pop up to allow you to change the name. Just type
the new name in the edit box and click on Rename. The subroutine name will be changed
in the listing under Project Files, on the subroutine itself and everywhere in the project
where it is used.
If the subroutine is not linked to other subroutines, the only two options that will be
presented are rename and remove. If you select ‘remove’ the file will immediately dis-
appear from the Project Files list and be disassociated from the project. It will remain
in your project directory, however. If you want to add it back, simply do so with the
standard ‘Add Subroutine’ function. If you do want to totally delete it, remove it, then
use Windows Explorer to find and delete the file.
If you select a file that is linked to other subroutines, the three options shown above will be presented. If you select the ‘remove
subroutine and its linked subroutines’ option, it will act like the remove of an unlinked subroutine, except that all of the linked
subroutines will disappear from the Project Files list and disassociated from the project. The subroutine files will remain in the
project directory. If you later add back any one of the linked subroutines, they will be all be added and linked.
If you are in the Tiled mode, you can simply move your cursor over the routine that you
want to make active and left click. That routine will immediately pop to the front.
The second method is to double click on the name of the routine in the list under Project
Files. The selected routine will pop forward and its name will be highlighed under Project
Files with a light background. This works in both the Full Screen and the Tiled modes.
Print/Print Preview
The active file can be printed or previewed for printing. This can be done, either by selecting Print or
Print Preview from the File menu, or by selecting the small printer icon on the top toolbar.
When you either select Print Preview from the file menu, or select the
print icon, a preview of the active routine’s printout will come up. Since
vBuilder is a graphical programming language, in which you can build
a program which may extend to any length or width, it commonly will
not fit on a single printed page. vBuilder will print the program such
that pages can be placed side by side and top to bottom to show the full
program. An example is shown on the right and below.
When you perform a print preview, a preview screen will pop up. Nor-
mally the screen will display the first page and have a selector wheel in
the upper right corner, which allows you to select any other page. Since
vBuilder programs are labeled with row and column numbers, it is clear
how the various pages fit together.
Another thing to note in preview mode is the toolbar at the top allows
you to zoom, show various views, print to a printer and close the pre-
view.
The second and third pages of this example are shown below on the
right.
After you have Cut a function block, it is attached to your cursor. If you right click your mouse,
it will be deleted. If you don’t right click the mouse, but move to another location, you can left
click the mouse to drop it at a new location. The two screen shots below show a function block
selected, then Cut and the cursor moved.
The screen shot on the right shows a block that has been cop-
ied and pasted.
Delete
To Delete a function block, select it, then either select Delete from the Edit menu, or press the Delete key on your computer.
The screen shot below shows a case where the text is found and the block high-
lighted.
If you select the Rung Delete, the rung will simple be deleted.
If you select a contact, then select Rung Insert Above or Below, space
for an additional row of contacts will be created, as shown in the
example to the right and below.
To Column Insert Before or After, first select a contact. Next, select the
appropriate Column Insert Before or After from the Edit menu. The screen
shots on the right show a contact selected and the result of a Column Insert
Before.
A Column Delete can be used on any rung from the rail to the last con-
tact. To perform a Column Delete, select an contact or connecting rail in
the rung, up through its last contact, then select
Column Delete from the Edit Menu.
• Errors/Warning : This tab contains information that is only applicable while entering or editing a program. It is a list of Errors
(things that you absolutely can’t do) and Warnings (probably not a good idea) associated with the program that you are editing.
• Watch : Applicable only to debug mode. Used to watch selected tagname data while operating in debug mode.
• Call Stack : Applicable only to debug mode. Shows a “stack” of how the program got to where it is (who called who)
• Runtime Errors/Warnings : Applicable to debug mode. A list of errors or warnings that occured during run operation (ex-
ample : divide by zero)
The three debug mode windows are discussed in more detail in the Debug chapter.
The Errors/Warnings window displays items that either must (errors) or should (warnings) be corrected while you are creating
or editing a program.
An example of an error is shown below. Subroutine TankInit was edited after calls to it were placed in another program. An
additional Input parameter
(newTag) was added. This is
fine. However, it creates an
error in every block that calls
TankInit. As the screen shot
shows, the error is highlight-
ed in red in the subroutine
call, indicating that there is
missing information. Also,
in the Status Bar Error tab all
of the errors are listed.
The Setup and Project Files window on the left, the Toolbox on the right and the Status Bar on the bottom are all
collapable wings. If you click on the arrow in the middle of the wing, the wing will collapse, giving more room
for the Edit window. You can also select and hold the heavy bar on the inside edge of each and and move to
adjust the size. The screen shot below shows all of the wings collapsed.
Closing a Project
To close a project, simply select the project’s main
program and close it. To close it, click on the red ‘X’
in the upper right hand corner.
You can close any other file and all that will hap-
pen is the file will be closed. You can re-open it by
double clicking its name under Project Files. If you
close the main program, the whole project will close.
By using this functionality to compose a custom Ladder Logic program, any logical program can be created quickly, easily and
graphically.
After a short review of the history of Ladder Logic to provide backgound information for those new to Ladder Logic, the indi-
vidual vBuilder Ladder Logic program function blocks are detailed.
When the coil is not energized, the spring contact connects the common to a normally closed (NC) terminal, as shown on the
left, below. A relay, with several contacts is shown in its de-energized state on the right.
When power is applied to the coil, it creates a magnetic force, which pulls the contact to connect the common to the normally
closed (NC) terminal, as shown on the left, below. The figure on the right, below, is an energized, multi-contact relay.
For over 100 years, automation designers used combinations of these simple relays to create controllers. By wiring up multiple
relay coils and contacts, combined with switches, in the right pattern, any type of boolean logic operation can be created. The
example, above, shows the control of a pump, feeding into a holding tank. There are two float switches in the tank. The low
limit switch is normally open and closes when the water level falls below the “low level”. The high limit switch is normally
closed and opens when the water level rises above the “high limit”. The controller has one relay, with two contacts. When the
level drops to low, the relay will energize. The contact shown closest to the coil is in parallel with the low limit switch. It will
keep the coil energized until the high level is reached. The other relay contact turns on the pump.
While that example, with one relay and two switches, is simple to understand, imagine what it looks like when the application
requires tens to hundreds of relays and switches. The wiring diagram would quickly become incomprehensible. That is why an
easier to follow form of logic drawing, ladder logic, was developed.
Using ladder logic diagrams, much more complex logic can be defined, much more clearly than with the typical wiring schemat-
ic shown on the previous page. Actual building of controllers still required the physical wiring of the required relay coils and
contacts for 100 years or so. More complex programs were drawn in ladder form, by adding more rungs.
In 1968, Dick Morley invented the PLC. The original PLC was designed to be the electronic equivalent to a system of wired
relays. Instead of wiring, the sequence of relay connections, or ladder logic, was downloaded from a programming device to
the PLC. The PLC interpreted the downloaded ladder logic for execution. The first programming stations were crude, custom
electronic devices. Within a few years, program entry began to be performed in graphical form, on personal computers and
downloaded over RS232 communication ports to the PLC.
Over the next 40 years, more advanced features, such as math, timers, comparison contacts, drum sequencers, PID, counters and
logical operations were added to various manufacturers’ PLC ladder logic. It wasn’t until after 2000 that floating point math
became common place. A lot of incremental improvements to PLCs have enhanced capabilities and improved ease of use, over
time. Howver, the pace has been slow. PLC progamming capabilities have fallen further and further behind the general com-
puter and internet technologies on the market.
The first real breakthrough in PLC ladder logic programming, since the invention of the PLC in 1968, is the Velocio Builder
(vBuilder) Ladder Logic. vBuilder introduces a number of major new capabilities, as well as providing significant enhance-
ments to a number of others. Those features and capabilities are discussed, in detail, within this manual. With the break-
through technology enhancements introduced by Velocio, PLC programming, in ladder logic or flow chart programming, has
advanced to the technological level of the internet age. The graphical programming aspects for software development have
actually moved PLC programming beyond the text based high level language alternatives found in general technology. Graphi-
cal progamming enables much higher productivity, higher confidence levels and enhanced documentation. Since graphical
programming is so intuitive, it brings that capability for application by any logical person.
The following pages decribe the individual building block components of vBuilder Ladder Logic. Subsequent chapters decribe
more advanced and powerful features, including subroutines, object oriented programming in graphical languages, embedded
objects and other topics.
To understand the operation of contacts, within ladder logic, imagine that the rail (the vertical
line on the left hand side) is electrified. Connected to the rail are a series of “rungs”, containing
contacts. Ultimately, at the end of each rung is an operation block. Whether or not the operation
block executes is determined by whether an electrical connection, through the rung contacts, con-
nects the operation block to the electified rail. If the electrical connection is made, the operation
block executes.
Looking at the example below, the rung controls the control state of an output, tagnamed “head-
light”. The rung logic which determines whether it is turned on or off consists of three contacts.
In order for the power to reach the “headlight” output, it must pass through the normally open
“ignition” contact, then pass through either the normally closed “nightSensor” contact or the nor-
mally open “lightSwitch” contact. If the power is able to pass through to the “headlight” coil, the
headlight will turn on. If not, it will turn off.
Contacts in Series
When contacts are placed in “series”, or one after another in a horizontal line, they create an
“AND” logic condition. In order for the rung to solve as true, or pass power from the rail to the
operation block, each contact in series must evaluate to the true or closed contact state. In order
for that to happen, each normally open contact must be “active” (bit value 1), and each normally
closed contact must be “inactive” (bit value 0).
In the example, above, if the normally open ignition contact (or bit) is active (or 1) and the normal-
ly closed nightSensor contact is inactive (or 0), the headlight output coil will become active (or 1).
In the rung above, coil “headlight” will be activated if either normally closed contact “nightSen-
sor” is inactive (or 0) or normally open contact “lightSwitch” is active (or 1).
if “ignition” is active (1) AND if either “nightSensor” is inactive (0) OR lightSwitch is active (1),
then “headlight” will become active (1).
Much more detailed information on the operation of individual contact types is contained in the
pages which follow.
In ladder logic, bits are represented as coils and contacts. Every coil has associated con-
tacts. The coils are representative of output operations on a tagnamed bit - activation or
de-activation, while simple normally open or normally closed contacts are decisions made
based on the state of a tagnamed bit. In ladder logic a bit (or coil) state of 1 is activated, a
bit state of 0 is deactivated. The normally opened or normally closed contacts represent the
state of a deactivated coil.
For the contacts in a ladder rung, logical connections occur through inactive (or bit value 0) nor-
mally closed contacts and active (or bit value 1) normally open contacts.
◊ Example :
In this example, if the “run” button is active (or 1) and the “failSafe” sensor is inactive (or 0), the
“motor” will become active (or 1).
When you place a Normally Open or Normally Closed contact in a rung, a dialog box will pop
up. This box is used to select the
tagnamed bit to associate with the
contact. Select the down arrow to
the right of the Address block to
get a list of all tagnames available,
then pick the one you want and
click OK.
A rising edge contact remembers the state (or value of the bit) from the last time the rung was
evaluated. If the bit was inactive (bit value 0) the last time, and is active (bit value 1) this time, the
contact is closed, or active (1) for this one pass. It will not be determined closed again until the
tagnamed bit is inactive (bit value 0) first.
Rising and falling edge contacts are often used for cases when you want to perform an operation
one time, when a transition is sensed.
Note : Edge contacts compare the current state of a bit to the state of the same bit the last
time the rung was evaluated. If the edge contact is used in a subroutine, remember the logic
evaluation is based on the last time the rung in the subroutine was executed for this object.
◊ Example
In this example, if the “start” button is pressed, a Copy block is used to set initial values for “tar-
getTemp” and “warmTime”
When you place a Rising Edge contact in a rung, a dialog box will pop up. This box is used to
select the tagnamed bit to associ-
ate with the contact. Select the
down arrow to the right of the
Address block to get a list of
all tagnames available, then
pick the one you want and
click OK.
A falling edge contact remembers the state (or value of the bit) from the last time the rung was
evaluated. If it was active (bit value 1) the last time, and is inactive (bit value 0) this time, the con-
tact is closed, or active (1), for this one pass. It will not be determined closed again until it is active
(bit value 1) again, first.
Rising and falling edge contacts are often used for cases when you want to perform an operation
one time, when a transition is sensed.
Note : Edge contacts compare the current state of a bit to the state of the same bit the last
time the rung was evaluated. If the edge contact is used in a subroutine, remember the logic
evaluation is based on the last time the subroutine rung was executed for this object.
◊ Example
In this example, if the “linePower” sensor transitions from active (1) to inactive (0), the “genera-
torStart” bit will be Set (to 1).
When you place a Falling Edge contact in a rung, a dialog box will pop up. This box is used to
select the tagnamed bit to
associate with the contact.
Select the down arrow to the
right of the Address block
to get a list of all tagnames
available, then pick the one
you want and click OK.
◊ Example
In this example, if the tankPressure is Less Than or Equal to the minPressure, the tankFill valve
will be active.
◊ Example
In this example, if cylceCount is Equal to batchTarget, the number 5 will be Copied into pro-
cessStep.
◊ Example
In this example, if statusCode is Not Equal to completeCode, processStep will be incremented.
When you place any numeric comparison contact in a rung, a dialog box will pop up. This box is
used to define the comparison operation associated with the contact. For any comparison, either
select the values to compare from tagnames available in the drop down boxes, or type in a numer-
ic value. Make
sure the com-
parison operation
that you want is
properly indi-
cated by the radio
button selection.
If it is not, select
the one you want.
When you are
done defining the
comparison, click
OK.
◊ Example
In this example, if the currentTemp is Greater Than the MaxTarget, the heater will be reset (turned
off).
◊ Example
In this example, if the currentTemp is Less Than the MinTarget, the heater will be set (turned on).
◊ Example
In this example, if the cycleCount is Greater Than or Equal to the batchTarget, the processStep will
be set to 3.
Timers use 32 bit integer (i32) numbers. An i32 used as a timer will keep time in milliseconds. It
can be compared to values in milliseconds, seconds, minutes, hours, or days. When you place a
Timer Compare contact, a dialog box like that shown below, will pop up. In the dialog box, you
must select the tagname of the timer in the left hand Timer box. The radio button selections to the
right of the Timer box allow you to select whether to check if the Timer is greater than or equal to,
or less than the value on the left. In the selection box on the left, you can either enter a number, or
select a tagnamed variable with the number you want to compare to. The last selection you must
make is the time units the comparison value represents. You can select time units from the drop
down selection list.
If the timer comparison is true, the contact is considered closed. If it is not true, the contact is
open.
◊ Example
In this example, if warmTime is greater than 32 seconds, generatorStart will be set (to 1).
Out Coil
An Out Coil simply places the solution to the contact logic that precedes it into the tagnamed bit.
In other words, if the contacts on the rung are in a state that creates a closed contact path all the
way from the power rail to the Out Coil, the tagnamed bit will be set active (or 1). If it does not,
the tagnamed
bit will be set
inactive (or 0).
◊ Example
In the example shown below, if InBitB1 is active (1) and InBitB2 is inactive (0), OutBitD1 will be
active (1). If either InBitB1 is inactive (0) or InBitB2 is active (1), OutBitD1 will be inactive (0).
◊ Example
In the example shown below, if
InBitB1 is active (1) and InBitB2 is inactive (0), OutBitD1 will be set active (1). If either InBitB1 is inactive (0) or InBitB2 is active
(1), nothing will happen.
Reset Coil
A Reset Coil will turn the tag-
named bit to inactive (0) any time
the solution to the contact logic
that precedes it solves to TRUE.
In other words, if the contacts on
the rung are in a state that cre-
ates a closed contact path all the
way from the power rail to the
Reset Coil, the tagnamed bit will
be set inactive (or 0). If it does
not, the tagnamed bit will not be
changed.
◊ Example
In the example shown below, if InBitB1 is active (1) and InBitB2 is inactive (0), OutBitD1 will be reset inactive (0). If either In-
BitB1 is inactive (0) or InBitB2 is active (1), nothing will happen.
Operators :
+ - * / : Math operators for addition, subtraction, multiplication and division
And &, Or |, Xor + : Boolean And, Or and Exclusive Or operators
( ) : Segmentation brackets
[] : Braces used to contain array index
0x : Hexadecimal number
A, B, C, D, E and F : Hexadecimal 10, 11, 12, 13, 14, and 15
◊ Example
In the example below, if calcBatchWt is active (1), the targetWt will be calculated according to the
formula shown.
When you
place a Copy
block in a
ladder rung, a
dialog box, as
shown on the
right, will pop
up.
The selections
across the top
of the dialog
box are illus-
trated selec-
tion buttons
that enable
the selection
of the appro-
priate type of
copy. As the
selection but-
tons show, the
general Copy
allows you
to copy up to
16 tagnamed
variables or
constant val-
ues to a like
number of
other selected
tagnamed
variables. The Copy Pack provides a function for copying a list of bits to a ui16 integer. The Copy
Unpack does the opposite - copy individual bits from a ui16 integer to bit tagnamed variables.
When you select the different Copy types, the copy details, below the selection buttons, change
accordingly.
The Copy Value function will convert data from one type to another, if the data types don’t match.
The illustration, above, includes a copy into an indexed variable. When you select an indexed
variable, it will appear with the index braces []. You must select inside the braces and type the
index number, or type the tagname of a ui16 variable. The case of typing a variable tagname is
shown above.
◊ Example
In the example shown below, if initRecipe is active (1), the list of six variables and constants will
be copied to the corresponding list of six tagnamed variables.
◊ Example
In the example shown below, if motionEnabled is active (1), the bits identified on the left of the Copy Pack block will be copied
to the bit positions identified next to the bit tag name or value in the ui16 tagnamed variable listed on the right.
◊ Example
In the example shown below, if getMotionFlags is active (1), the bits identified on the right of the Copy Unpack block will be
extracted from the bit positions identified next to the bit tag names from the ui16 variable motionFlags.
Counters are background tasks. Once a counter is set up through a Counter block, it will continue
to operate, behind the scenes, until it is stopped through a Stop Counter block execution. The
counters work in the background, updating once, just prior to the execution of each program logic
pass, based on the state of the selected bit at that time. Once you have started an Up or Down
Counter, your program logic does not need to execute it again on every program pass.
Note : A counter operation is defined by its Output tag name. Therefore there can be only
one count operation active for a given Output tag name.
Up Counter
The Up Counter increments a count by
one, each time a tagnamed bit transi-
tions (checked just prior to each logic
pass) in the direction (either rises or
falls) that is selected. In other words, if
you want to place an Up Counter block
that increments each time a tagnamed
bit changes from 0 to 1, select Counter,
then select “counts up” and “rises”, as
well as the Output (the tagnamed vari-
able that keeps the count) and the tag
name of the bit that is checked “every
time” for the rising transition.
Down Counter
The Down Counter decrements a count
by one, each time a tagnamed bit transi-
tions (checked just prior to each logic
pass) in the direction (either rises or
falls) that is selected. In other words,
if you want to place a Down Coun-
ter block that decrements each time a
tagnamed bit changes from 1 to 0, select
Counter, then select “counts down”
and “falls”, as well as the Output (the
tagnamed variable that keeps the
count) and the tag name of the bit that
is checked “every time” for the falling
transition.
Counter Stop
The Counter Stop simply stops the
selected counter from counting. The
count value will not change. To place
a Counter Stop block, select “Coun-
ter”, then “stop counter” and select the
tagname of the counter that you want to
stop. Then select ‘OK”.
The basic 1.5K byte storage is commonly used for configuration, calibration and ‘recipe’ data stor-
age. This is information that is commonly set up, by the user, to ‘tune’ the operation, or set up
standard operational sequences or modes.
The larger memory can be used for the same type of data storage as listed for the small file memo-
ry. It also can be used for data logging and larger file storage.
Any PLC that has data logging/file storage capability will show two
tabs (once the Setup, using ‘Auto Setup’ is performed) below the Set-
up Hardware window. The first tab, labeled ‘Solution’ is the list and
definition of programs and subroutine in the application program.
The second tab, labeled ‘Logs’ is where data files are defined.
Note : If the ‘Logs’ tab and the ‘Data Log’ tool do not show up,
connect your PC to the PLC and perform an ‘AutoSetup’
A dialog box, shown below, will appear. Enter a name for the file that you
are defining. The figure, below, shows the beginning of the definition of a file, named ‘Recipe’.
If you ‘Use Existing Data Log’, a copy of the lag definition that you choose will be copied to the project file. The data contained
in each record and the number of records in the file will already be defined. You can change the number of records and/or the
data definition of each record. If you do so, it will no longer match the log file that you originally selected.
If you want the record to be automatically time stamped, select the ‘Include time stamp’ check box. To ensure that time stamp-
ing works properly, you will need to set the internal clock to the correct time (See the section on the Real Time Clock).
To select the number of records in the file, use the up and down arrows, next to the ‘# of Records’ numerical box, to adjust to
whatever number that you would like. Remember that the limit on the total amount of file data available is either 1536 bytes or
128K bytes (131,072 bytes), depending on whether you are using a PLC that has the larger file memory option.
To calculate the amount of data that your file definition contains, you need to consider the number of bytes used by each data
type in the record. The following is a list of the number of bytes used by each file data type.
• Bit - 1 byte
• UI8 - 1 byte
• UI16 - 2 bytes
• S16 - 2 bytes
• S32 - 4 bytes
• Float - 4 bytes
For example, for the file definition on the previous page, each record would contain -
4 temp_set (float)
4 temp_deviaiton (float)
2 dwell_time (UI16)
4 transfer rate (S32)
2 agitate_time (UI16)
--------
16 total bytes per record x 10 records = 160 byt
Make sure that the total amount of data used by all of your data files does not exceed the amount of file storage data that is
available.
There are three program functions associated with reading and writing log file records. Those functions are :
• Write Record
• Read Request
• Transfer Record
To write data to a record, you use the Write Record function. The Write Record will set up the data to be written to the file re-
cord storage, handle the actual storage, as a background operation, then set a ‘Ready Bit’ to indicate the record write is complete.
To read data from a record, you use the ‘Read Request’ function to start the read process, then the ‘Transfer Record’ to transfer
the data that has been retrieved from file storage, after the read operation is complete. The ‘Read Request’ function tells the
PLC to read the record data from log file memory. When the read operation is complete, it wil set a ‘Ready Bit’. Your program
should check the Ready Bit. When it becomes a ‘1’, you can use the ‘Transfer Record’ to move the data to program tag name
data.
Remember that
you define the total
number of records
for each file. If the
Record number that
you select is greater than the number of records in the file, the read or write operation will not occur, and the tagnamed bit
variable the you select for the ‘Error Bit’ will be set to 1.
The next thing that you can do is select whether you want a Write Record, Read Record, or Transfer Record block. For writing
to a file record, select Write Record.
Next, select the tag named data that you want to store in this record. For example, if you want your log file to contain recipes for
producing ten different product variations, and you want to store the recipe for product 3, you might enter something like what
is shown in the dialog box image, below.
When a block, like the one shown above, executes, the data listed on the left side of the arrow (prod3_temp, etc.) will be written
to record 3 of Log file ‘Recipe’. When the write is complete, the ‘write_done’ bit will be set to a ‘1’.
If the write does not occur (for example, if the record number was higher than the number of records in the Log file), the Error
Bit, ‘write_error’, will be set to ‘1’.
Logging Data
If you want to log data, say a number of measurements
and statuses over time, you would use the same Write
Record function, just described. However, you might set
the Data Log file up to time stamp each record.
The figure on the right shows the Data Log file set up for
a log file intended to log up to 50 readings of the same
measurement and status information, over time. Since
the ‘Include Time Date Stamp’ check box is checked,
each record will be stamped with the time and date that
it was written.
one hour logging interval is complete. When it is time to log a record, the interval is reset, the Write Record is executed (to start
the record write process) and the step is set to 7.
In Step 7, the Ready Bit that was defined in the Write Record block, ‘write_done’, is checked. When ‘write_done’ is set to 1,
indicating that the write record operation is complete, the record number is incremented to prepare for the next record log. If
the file is not full (we defined the number of records as 50), tStep is set back to 6, to start the process all over again. If the record
number reaches 51, which is more than the number of records defined in our program set up, tStep is set to 8 ; which is should
continue on with whatever program operation is appropriate.
Step 7 also checks the Error Bit defined in the Write Record bock, ‘write_error’ to see if an error occured. A write error can occur
if you try to write to a record number that doesn’t exist.
There is also a check for a read error, in tStep 4. If you try to read a record number that is greater than the number that you’ve
defined for the file, there will be a read error.
The screen
capture, on
the right,
shows a com-
pleted dialog
box for read-
ing the 6th
record of a
time stamped
file.
The program
process for
reading a
time stamped
record is
shown, below.
The Drum function is one of the most intricate and powerful functions in vBuilder Ladder Logic.
The Drum function is basically a predefined sequencer. It is only available in Ladder.
The drum sequencer operation is like that of the old player pianos that were popular from their in-
vention in 1876 until about the start of the Great Depression. Player pianos were pianos designed
to play automatically. They had a rotating drum, where a cylinder with the song music could
be placed. The song cylinders had a pattern of holes that could be sensed by mechanical sensors
in the piano. As the cylinder rotated, the each hole sensed would cause a particular note to be
struck. The cylinder rotated at a constant rate, allowing the hole pattern to completely define the
tune.
The Drum function is like that of the player piano. It controls a pattern of bit outputs that are
sequenced through. The sequence isn’t controlled by a constant speed wheel. The progression of
output pattern steps are sequenced instead, by either programmed times, or events.
The best way to get a sense of a Drum Sequencer operation is to take a look at how the dialog box
is used. An example is shown below. The first thing to notice is the grid. Across the top of the
grid are up to 16 bits that are either activated (1) or deactivated (0), based on the sequence step
that is being executed. Listed along the left side are the events or times that cause the sequencer to
move to the next step. The pattern of dots are the bits that are set active during each step.
There are some settings and entries on the right hand side of the dialog box that are important too.
The selection at the top is the time increment to use for timed events. This example shows sec-
onds. Other available options from the drop down selection list are millisecond, minutes, hours
and days.
If you have selected Duration for any step, you must select an i32 variable tagname to be used to hold the time
value.
The last selection is for a tagnamed ui16 variable to hold the Current step number.
When building the sequence, for each step, first choose either Event or duration. If an event is chosen, the tag-
name required for the associated ‘Causes Drum to Cycle’ field is a bit type. If Duration is chosen, the ‘Causes
Drum to Cycle’ field requires an integer to define the duration time. Any integer type is OK for this entry.
◊ Example
The example we’ve chosen is a Drum Sequencer for a one cookie at a time baking system.
Yeah, we know that such a system doesn’t make any real world sense, but we had to come up with an
example on short notice. Humor us on this one.
A cookie pan is on a conveyor that takes it to batter extraction station, then to the oven, a frosting application
station, glazing station (overkill), then an arm to pick it up, retract and drop it in a box. If you take a good
look at the sequence, you should see that its all there - a one block function control for the whole cookie line.
In this example, all of the activation bits control digital outputs. In a Drum sequencer, they can actually be
any bit. Other common uses are bits that enable particular sections of program code, or particular subrou-
tines.
The Filter function is a background task function. You simply tell it what to filter at what weight
and time interval and the Filtering will happen behind the scene automatically. All you have to
do, once you’ve set up the Filter is use the filtered result value whenever you need it.
When you place a Filter block a dialog box will pop up. The box look like this :
To get a sense of what Filter does, right click and hold the slider shown next to “Less Filter” and
slide it across. The live illustration below the slider shows that with an Example input shown on
the left, the resulting output values will be like that shown on the right. Everytime you click on
the New Example button, you’ll get a new example illustration.
Once you’ve started a Filter, it will continue to operate in the background until you stop it.
To Stop a Filter, place a Filter block and select Stop Filter and select the filtered output value’s tag name. Click OK.
Program looping is available for Ladder Logic and is an effective tool in certain instances.
Never loop, looking for a change in an input. Inputs are updated between logic passes. Its
not going to change. Writing your program as a state machine (see chapter on state ma-
chine programming) is a better way to handle waiting for an input change.
Loop
The Loop program icon is shown on the right. The Loop block defines the start of a program
block that will loop a defined number of times. For every Loop block, you need to place a corre-
sponding Loop Next block after the last rung of the looped section of your program.
Loop Break
A Loop Break causes the Ladder Logic program to “break” from the loop and continue with the
rung after the loop. This is one logic block that requires no additional definition, and therefore
has no dialog box.
The image, below, shows a Loop Break placed in a rung. In this case, if masked_flag is Not Equal
to 0, the Loop Break will cause the program to break out of the loop.
◊ Example
The example, below, illustrates the use of a Loop. In this example, a variable named request_flags
contains a series of individual bits that are requests for different operations. The highest priority
operations are requested through the least significant bits. This loop is used to determine whether
there is an operation requested, and if so, which one. If a request bit is set, the program will exit
the Loop with the number of the request in “counter”. If no request bits are set, the Loop will
complete all passes and the counter will have the value 16.
The high speed pulse counters in each unit are specified for typical operation up to 100KHz.
In reality, general high speed pulse inputs will operate at up to 250KHz. Quadrature inputs
will operate at up to 200KHz. The general high speed pulse counter consumes approxi-
mately 1.6% of total processor time (for the particular PLC unit that it resides in) for every
10KHz pulse rate, while the Quadrature input consumes approximately 2.8% per 10KHz.
As you increase the pulse rate, the CPU usage increases proportionately. Lower pulse rates
consume proportionately less time. Whether, and at what point that might become an issue
is application dependent. Up to 100KHz, it is hard to imagine an issue with most applica-
tions.
To implement high speed pulse counting, you must define a dedicated input pin (pulse) or pins
(quadrature) during the hardware setup. When you are setting up your hardware from the “Setup
Hardware” icon near the upper left corner, the following screen will pop up during the process.
The instructions on the screen are pretty self explanatory. The screen allows you to set up for
a high speed pulse counter, stepper motor output or both. To configure for a high speed pulse
counter, first select the type that you want (pulse or quadrature) from the drop down selection list
shown above.
MotionIn function blocks can only be used for inputs that reside on the PLC unit that
contains a program. In other words, MotionIn for the main program can only be applied to
digital inputs on the main PLC unit (Ace or Branch). MotionIn blocks can be utilized in the
embedded object subroutine and use digital inputs that are local to the Expansion unit that
contains the embedded object.
During hardware setup, the following screen will pop up, with high speed counter and stepper motion configuration options
for the main PLC and all other modules that are set up for embedded object programs. To configure a high speed pulse counter
for that module’s program (either the main program for the Ace or Branch, or an embedded object subroutine for an Expansion),
select the Type as “pulsed” and select the particular digital input to use for your count, as shown below.
When entering your program, select the MotionIn icon and place it on a rung. A dialog box, like the one shown below, will pop
up. Using the dialog box, you can select to count up or down, or stop the count. When selecting count up or down, you can
select whether to count on the rising or falling edge of the input signal.
Quadrature encoders are commonly used in servo motion systems, as well as any motion
or position application. For more information, there are a number of web sites that give
thorough explanations of quadrature encoders, including Wikipedia.
Quadrature Pulse In is restricted to counting transitions on a dedicated pair of digital input signals. One quadrature pulse coun-
ter can be implemented per PLC module (Ace, Branch or Expansion), so up to 15 can be implemented per application.
During hardware setup, the following screen will pop up, with high speed counter and stepper and motion configuration op-
tions for the main PLC and all other modules that are set up for embedded object programs. To configure a quadrature pulse
counter for that module’s program (either the main program for the Ace or Branch, or an embedded object subroutine for an
Expansion), select the Type as “quadrature” and select the particular digital inputs to use for your count, as shown below.
When entering your program, select the MotionIn icon and place it on a rung. A dialog box, like the one shown below, will pop
up. For quadrature MotionIn, you simply need to choose the appropriate Start Counter or Stop Counter selection and an i32
tagname to use for the Count Value.
Stepper motion outputs use two digital outputs. One output is a direction signal, telling the
motion driver to step in either the positive or negative direction. The other signal is a high
speed pulse output, which outputs one pulse to command each stepper motor step.
During hardware setup, the following screen will pop up, with high speed counter and stepper
motion configuration options for the main PLC and all other modules that are set up for embed-
ded object programs. To configure stepper motion for that module’s program (either the main
program for the Ace or Branch, or an embedded object subroutine for an Expansion), select the
digital output pins to use for the Step and Direction signals. The output pins that you select
will be dedicated for stepper motion control and not available for any other operation.
When entering your program, select the MotionOut icon and place the MotionOut block in your
program. A dialog box, like the one shown at the right, will pop up. For a Move command,
select the motor and ‘Move motor to’ and either type in the numeric position that you want to
move to, or select an i32 tagname that contains the target position. Next enter the pulse rate
that you want the motor to move at for the majority of the move (generally the highest pulse
rate). If you want the movement to ramp up to full speed to start and ramp down from full
speed to stop (which is highly recommended) enter the number of milliseconds to allow for the
ramp up and ramp down.
Lastly, provide an i32 tag-
named variable to be used
to maintain the location.
Generally, in a system,
the location variable is
used for all movements.
Usually an initialization
program is used to find
the “home” position. The
home position is normally
assigned a location value.
All movements after that
are to locations relative to
the home position.
When a Move is started, it will operate in the background, until the target position is reached.
The stepper motion output is specified for a pulse rate up to 250KHz total for all step-
per outputs that are active. In other words, if you are driving only one motor, it can
be pulsed at up to 250,000 steps per second. If you have two motion outputs active at
100,000 steps per second each and want to start a third output, its maximum speed will be
50,000 sps.
Next, you must enter a i32 tag named variable for the
PLC to place the sensed position.
The program snippet, on the next page, illustrates the use of the digital input transition capture feature. In this example, mStep
1 starts motion to basically infinity (10,000,000 steps) and sets to capture the position at which the optical sensor detects the lead-
ing edge of the material.
In step 2, the edgeCaught bit is checked to see if the leading edge has been caught. When edgeCaught is true, a calculation block
is used to set the current position at the number of steps past the leading edge that we currently are (at 128,000 step per second,
we could be as much as 30 steps past the sensed point). Then another motion command is executed to move to the precise point
of the first operation.
PID is Proportional - Integral - Derivative control. It is the very commonly used in process control,
heating control and motion control. The PID function calculates the “error’ value between a mea-
sured process variable and the desired setpoint. It adjusts an output in an attempt to minimize the
error. This adjustment occurs on a regular period. Each time an adjustment is made, it takes into
account the magnitude of the error (Proportional), the accumulated total of the error over time
(Integral), and the rate of change of the error (Derivative).
PID control is complex enough that we won’t provide a detailed discussion in this manual. It is
a common control algorithm and there are other excellent reference documents that you should
review to get an understanding, if you are new to PID. One very good description is on Wikipe-
dia at the following link.
http://en.wikipedia.org/wiki/PID_controller
We will also put out an application note on PID control and how to use it in the near future.
In vBuilder, PID control is a background task. That means that you Start it and it will continue to
run in the background, constantly calculating the error, integrating it and determining its rate of
change and updating the output based on these factors combined with the constants that you set
up. Once started, the PID will operate until it is Paused
O = P*E + I * ∫ E dt + D * ∆E/dt
where : O : Output
P : Proportional constant (sometimes referred to as the Gain)
I : Integral constant (sometimes referred to as Reset)
D : Derivative constant (sometimes referred to as Rate)
E : Error
dt : change in time
When you place a PID block in your program, a dialog box, like that shown below, will pop up.
With this dialog box, you can Start the PID operation, Pause it, or Reset the PID’s integral. A PID
function is one that you normally need to “tune” to get the right performance. By tuning, we
mean adjust the constants, try it, adjust again, until the response works like you want.
When you select Start/Continue, you must select or enter a number of parameters. The following is a list of those parameters,
with an explanation of each.
• Output : This is what the PID is actually adjusting. The Output should have a direct impact on the value of the Process Vari-
able. For example, a butterfly valve controlling the gas supply to a boiler’s burners has a direct impact on the temperature of the
boiler.
• Output Max : The maximum value allowable for the Output. Regardless of the result of the PID calculation, the Output will
be restricted to no more than this value. [any variable type except Bit and ui8]
• Output Min : The minimum value allowable for the Output. Regardless of the result of the PID calculation, the Output will be
restriced to no less than this value. [any variable type except Bit and ui8]
• Process Variable : The is the measurement of the parameter that you are trying to control.
• Set Point : This is the desired value of the Process Variable at this time
• Input Max : The maximum value of the Process Variable measurement that will be used for the PID calculation. If the actual
measurement goes above this value, this value will be used.
• Input Min : The minimum value of the Process Variable measurement that will be used for the PID calculation. If the actual
measurement goes below this value, this value will be used.
• Proportional : The constant multiplier to the error.
• Integral : The constant multiplier to the integral of the error.
• Derivative : The constant multiplier to the derivative of the error.
• Sample rate : The amount of time between each PID calculation/adjustment, in milliseconds.
• Freeze bias : This is a selectable option. If selected, it is used to limit the impact of integral portion of the equation to no more
than the entire Output range. This is useful in preventing overreaction after a time period where some factor prevented the actual
control of the Process Variable [which could possibly result in a huge integral value].
When you Start a PID, it will continue operating at the defined sample rate, behind the scene. In other words, once you start it,
you don’t need to continue to execute PID Start/Continue blocks for operation. It doesn’t hurt anything if you do. Its just not
necessary.
PID Reset
A PID Reset sets the Integral value to the value
required to produce an Output equal to the Reset
Value. It is something that you should do when
starting a PID. The Start/Continue does not initialize
the Integral value, because it does not know whether
this is the actual Start or whether it is a Continue.
PID Pause
A PID Pause block stops the PID from operating.
When you place a PID Pause in a ladder rung, select the Output variable of the
PID that you want to pause, as shown on the right.
PWM is the acronym for “Pulse Width Modulation”. Pulse width modulation is a very powerful
function that is commonly used to control the positioning of servo valves. It is also used for laser
pulse control, motion control, light intensity controls and other other applications. The single pulse
feature of the function is applicable to any single pulse output need.
A pulse width modulated output signal is one that has a period and an output “on time”, or duty
cycle, within that period. For example, a typical servo valve control might have a 20 millisecond pe-
riod. Valve position is controlled by the “on time” of the output pulse, within this period. The valve
may be controlled to a fully closed state with a 1 millisecond pulse on time and fully open with a 3
millisecond pulse (actual times are defined by the valve manufacturer). Partial (5%, 10%, 53%, etc.)
opening is generally controlled by an “on time” pulse purportionate between to full open and full
closed limits. Standard PWM signals repeat every period increment.
PWMs Application Limits : PWMs can be applied to any digital output that is physically
present on the PLC module that contains the application program. That means that any Ace
or Branch digital output can programmed to output a PWM signal by the application main
program. Any Branch Explansion PLC which has its own program (embedded subroutine) can
output a PWM signal from the embedded subroutine. Branch Expansion units that are used a
expansion IO, cannot output PWM signals.
Any combination of digital outputs, contained on the PLC with the program, can have PWM output
signals. Each active output has its own “on time”. However, the Period is common to all PWM
signals on the PLC unit.
Set Period
The Period is common to all PWMs in
the PLC. The period is set by select-
ing the “Set Period” radio button, then
either selecting a ui16 tagnamed vari-
able, or entering a number between
100 and 65535. Timing is in micro-
seconds (1 million microseconds = 1
second). That means that the PWM
period can range from 100 microsec-
onds to a little over 65 milliseconds.
Start
The Start selection defines the Output and the
On Time for the PWM signal. It also provides a
selection for either Continuous or Single Pulse.
If the PWM is to be used for a varying On Time
PWM signal, each time the block is executed,
the On Time will update its value on the next
Period.
If you select Continuous operation, PWM pulses will continue, one pulse per period, until you execute a Stop PWM block for the
output. If you select Single Pulse, it will output one pulse on the next Period. After the period is complete, the output will be set
according to the program digital output state for that output.
Stop
To place a block to Stop a PWM ouput, you
simply select the Stop radio button and select
the tagname of the output. If you are placing the
Stop block in a subroutine, place the reference to
the output as the Output Pin.
The Ramp function changes a value from its initial value to a target value, at a defined rate of
change. Optionally, a ramp can include a soft start and soft stop. A soft start ramps the rate of
change up to the defined rate of change gradually, over the defined soft start/stop period. A soft
stop ramps the rate of change from the defined rate to 0, over the defined soft start/stop period.
Ramp is commonly used for motion control. The vBuilder Stepper Motion function has its own
ramp feature built in, so this Ramp function would not commonly be used for stepper motion
control. It would be applicable to servo motion control, typically coupled with a high speed pulse
counter input and PID.
Ramp is also applicable to other machine and process control applications. Any time you want to
change a variable at a defined rate, Ramp can be used.
Ramp is a background task. It only needs to be Started. Once Started, it will continue to
operate in the background until Stopped.
Ramp Start
When you place a Ramp block in a flow chart, a dialog box will pop up. This box will allow you
to Ramp Start, or Ramp Stop. To Start a Ramp, select the Ramp button, then enter the parameters.
• The top selection is the variable that you want to Ramp.
• Next is the ramp rate in units per second of whatever unit the Ramp variable is. The Ramp
Rate is an absolute value. Whether it is a rate of increase or decrease depends on whether the Ramp
variable is above or below the target.
• Next is the Ramp Target - the .final value of the variable after ramping
• Optionally, you can enter a Soft Start/Stop time. If you enter a Soft Start/Stop time the ramp
rate will ramp up to the Ramp rate over the defined period and ramp down over the same defined
period, when approaching the target. This will have the effect of rounding off the value curve, like
that shown in the Ramp button graphic.
◊ Example
The example, below, shows the ramping of a steamPress setpoint. The Ramping is initiated when pressBuild transitions from
inactive (0) to active (1). When the steamPress setpoint becomes greater than or equal to the target value, the Ramp is Stopped.
Select ‘Read’.
Select UI8 (unsigned 8 bit) tag names to transfer the clock data into for the current year,
month, day (of the month), hour, minute, second, and day of the week.
Select ‘Set’.
Select UI8 (unsigned 8 bit) tag names, or constants to transfer the clock data into the
current year, month, day (of the month), hour, minute and second
The Scale function is used to automatically convert an input value to an output value. It is com-
monly used for scaling a raw analog reading to its equivalent value. Scale has the capability to do
piecewise linear scaling between up to 16 points. With piecewise linear scaling between such a
high number of points, Scale can be used to convert values from non-linear transducers as well as
an assortment of other applications.
When you place a Scale block, a dialog box, like that shown below will pop up. In the dialog box,
you need to choose the Input and Output variables. You must also define the scaling in the Input
and Output tables, as shown. The scale curve will automatically be created on the right to illus-
trate the scaling that will take place.
◊ Example 1
The example shown below, shows the simple scaling of a 12 bit A/D conversion of a pressure
transducer that outputs -14.7 to 3000 psi as a 0 to 5V signal. As shown in the graph, it results in a
linear conversion curve.
After clicking OK, the program block will be like that shown below.
The Shift function allows you to shift an integer number left or right, a selected number of bit posi-
tions. A bit value that you choose is shifted into the vacated bit position(s). For signed integers,
The shift can be defined to include or exclude the sign bit (the most significant bit).
The Rotate function is similar to the Shift. The difference is that the bits that are shifted out of one
end of the number are shifted back into the vacated position(s) on the other end.
If you un-
check the Ex-
clude Sign Bit
box, shifting
will include
the entire
number.
Before you can create a Subroutine call, you must have already created the subroutine.
Subroutines are discussed in detail in depth in the chapter on Object Oriented Programming and
Subroutines.
When you place a Subroutine Call block, a dialog box, like the one shown below, will pop up. On
the left side of the box, is a list of all of the defined subroutines. Choose the one that you want to
place. Once you’e done that, the right side of the dialog box will contain a list of Data to Pass to
the Subroutine. Since all Subroutines in Velocio PLCs are objects, the first thing you need to do is
define the Data Set # (object number) that this Subroutine Call is associated with. If you only have
one instance of the Subroutine, you can leave this blank.
Next, you see a list of Passed Data. On the right hand side of the list is the subroutine tag name
associated with each item - in other words, the tag name used in the subroutine. On the left are
selection boxes to allow you to pick the local tagnames of the data to pass. Between the two col-
umns is the Pass Type for each parameter. The following is an explanation of the Pass Types.
• The symbol with a single arrow pointing to the subroutine indicates pass by value. The nu-
meric value of the data on the left (tagname variable data or constant) is passed into the subroutine.
There is no effect on the data in the calling program.
• The symbol with arrows going both directions indicates pass by reference. In this case, actual
data is not passed. What is passed into the subroutine is a “reference” to the tagname variable. This
reference allows the subroutine to read and/or change the value in the calling program. This is how
data is passed back out of a subroutine.
Fill out the Pass Data to Subroutine list and click OK.
The Subroutine Return has no dialog box. In ladder logic, vBuilder automatically places a Subrou-
tine Return block at the end of a subroutine program. You can place additional Subroutine returns
on other rungs, as needed.
◊ Example
The example, below, shows a Subroutine Return block placed in a subroutine.
Timer Start/Continue
When you want to Start a Timer, select the
Start/Continue option in the dialog box.
The only other thing you need to do is
place the tagname of an i32 variable to be
used to contain the time value in the box
labeled Timer.
Timer Pause
A Timer Pause block is used to stop a Timer
from operating. To place a Pause, select the
Pause option in the dialog box and enter the
i32 tagname of the variable that holds the
time value.
In a lot of applications, whether Ladder Logic or Flow Chart programming is utilized is a matter than personal preference.
There are some areas where Flow Charting has distinct advantages. Some of those areas are listed below.
• Test Applications : Test applications are based on pass/fail decisions, which naturally translates to flow chart decision blocks.
• State Machine Applications : Almost any control application is actually a natural state machine. State machine applications are
any applications that breaks down to “if we are in this state and this happens, we do that” and then transition to the next state where
the next set of “if this happens do that, or if this other happens, do a different that, then enter another state”. Almost all control ap-
plications, when you break them down, are state machines.
• Applications that are specified with flow charts : In a lot of cases, specifications use flow charts to clearly define requirements.
That makes it very easy to translate the specification into the application and to demonstrate to the specifier that the requirements
are met.
• Applications that must be maintained by different people over a period of time. Flow charts’ self documenting features make
learning what the previous developer (or even the earlier you) did, a much easier process.
• Most complex applications : Flow chart logic tends to be easier to follow for complex applications.
• Number formats including binary, unsigned 8 bit integer (ui8), signed and unsigned 16 bit integer (i16 & ui16), signed 32 bit
integer (i32), and floating point (Float)
• Tagnames for all variables
• True Object Subroutines
• Embedded Object Subroutines
• Distributed Processing and seamless intermodule data transfer
• Program flow routing definable by programmer
• Notes for documentation
• General Decision blocks
• Numeric Comparison Decision blocks
• Output Turn On/Off
• Calculator (math) operations, including arithmetic and boolean
• Copy (general copy, bit pack and bit unpack)
• Counter (general counter function)
• Filter
• Motion in (high speed general pulse counting and quadrature pulse counting)
• Motion out (stepper motion control)
• PID
• Ramp
• Scale
• Shift/Rotate
• Statistics
• Timer
By using this functionality to compose a custom Flow Chart program, any logical program can be created quickly, easily and
graphically.
After a quick snapshot of a Flow Chart program, the individual vBuilder Flow Chart program function blocks are detailed.
The decision block icons are shown on the right. Decision blocks are available to check bit status,
for numeric comparison and for Timer comparison. With this set of blocks any logical decision
that is necessary in an application can be performed.
The flow chart segment, shown below, provides a general illustration of the use of decision blocks
within Flow Chart programs. This program segment shows the program checking whether the
initButton is ON (1), If it is, subroutine MachineInit is called. If it is not, the NO branch from the
initButton ON decision block loops back to check again.
Shown after the call to subroutine MachineInit is a decision block that checks if tankReady is ON.
If so, the program proceeds to copy 1 into wpStep. If tankReady is not ON, the decision block
branches back to the call to MachineInit.
Note that looping in a program, like shown below is generally not the best way to perform
control. Read the chapter on State Machine Programming to see a more efficient program-
ming strategy.
When connecting out of a decision block, hover your cursor over the
corner where you want to exit. It will turn a solid blue. Left click
and continue to hold down while moving to the point you want to
connect. When you release, a dialog box will pop up to ask whether
this is the Yes or No connection. Click Yes or No to make the selec-
tion. A ‘Y’ for Yes or an ‘N” for No will be displayed on the line to
indicate the decision type.
For the ON? decision block, the tagnamed variable is checked to see if it’s value is 1. If it is 1, the
program will flow in the Yes direction. If it is 0, program flow will proceed in the No direction.
For the OFF? decision block, the tagnamed variable is checked to see if it’s value is 0. If it is 0, the
program will flow in the Yes direction. If it is 1, program flow will proceed in the No direction.
◊ Example :
In this example, if the initButton is ON (1), the ON? decision block program flow will be to the
MachineInit subroutine call. If initButton is not ON, the ON? decision block program flow will be
to the Copy block on the bottom of the chart.
If program flow gets to the OFF? decision block, if tank1Heater is OFF (0), program flow will be to
the the block that turns on the tank1Heater. If tank1Heater is not OFF (1), program flow will be to
the copy block.
When you place any numeric comparison decision block in a Flow Chart, a dialog box will pop
up. This box is used to define the comparison operation associated with the decision. For any
comparison, either select the values to compare from tagnames available in the drop down boxes,
or type in a numeric value. Make sure the comparison operation that you want is properly indi-
cated by the radio button selection. If it is not, select the one you want. When you are done defin-
ing the comparison, click OK.
◊ Example
In this example, if the currentTemp
is Greater Than the MaxTarget, the
heater will be turned off.
◊ Example
In this example, if the currentTemp
is Less Than the MinTarget, the
heater will be turned on.
◊ Example
In this example, if the
cycleCount is Greater
Than or Equal to the
batchTarget, wpStep will
be set to 3.
◊ Example
In this example, if the
tankPressure is Less Than
or Equal to the minPressure,
the tank1Fill valve will be
turned on.
◊ Example
In this example, if
cycleCount is Equal to
batchCount, the number
5 will be Copied into pro-
cessStep.
◊ Example
In this example, if sta-
tusCode is Not Equal
to completeCode,
processStep will be
incremented.
Timers use 32 bit integer (i32) numbers. An i32 used as a timer will keep time in milliseconds. It
can be compared to values in milliseconds (1/1000s of a second), seconds, minutes, hours, or days.
When you place a Timer Compare decision block, a dialog box like that shown below, will pop up.
In the dialog box, you must select the tagname of the timer in the left hand Timer box. The radio
button selections to the right of the Timer box allows you to select whether to check if the Timer
is greater than or equal to, or less than the value on the left. In the selection box on the left, you
can either enter a number, or select a tagnamed variable with the number you want to compare to.
The last selection you must make is the time units the comparison value represents. You can select
time units from the drop down selection list.
If the timer comparison is true, the Yes branch will be taken. If it is not, the No branch will be
taken.
◊ Example
In this example, if warmTime is
greater than 32 seconds, genera-
torStart will be turned on.
◊ Example
In this example, if warmTimer is
greater than 32 seconds, generatorStart
will be turned on.
Operators :
+ - * / : Math operators for addition, subtraction, multiplication and division
And &, Or |, Xor + : Boolean And, Or and Exclusive Or operators
( ) : Segmentation brackets
[] : Braces used to contain array index
0x : Hexadecimal number
A, B, C, D, E and F : Hexadecimal 10, 11, 12, 13, 14, and 15
◊ Example
In the example, if calcBatchWt is On (1), the targetWt will be calculated according to the formula
shown.
The Copy Value function will convert data from one type to another, if the data types don’t match.
The illustration, above, includes a copy into an indexed variable. When you select an indexed
variable, it will appear with the index braces []. You must select inside the braces and type the
index number, or type the tagname of a ui16 variable used for the index. The case of typing a vari-
able tagname is shown above.
◊ Example
In the example shown below, if initRecipe is ON (1), the list of six variables and constants will be
copied to the corresponding list of six tagnamed variables.
◊ Example
In the example shown below, if motionEnabled is ON (1), the bits identified on the left of the Copy Pack block will be copied to
the bit positions identified next to the bit tag name or value in the ui16 tagnamed variable listed on the right.
◊ Example
In the example shown below, if getMotionFlags is ON (1), the bits identified on the right of the Copy Unpack block will be ex-
tracted from the bit positions identified next to the bit tag names from the ui16 variable motionFlags.
Counters are background tasks. Once a counter is set up through a Counter block, it will con-
tinue to operate, behind the scenes, until it is stopped through a Stop Counter block execution.
The counters work in the background, updating once, just prior to the execution of each program
logic pass. Once you have started an Up or Down Counter, your program logic does not need to
execute it again on every program pass.
Note : A counter operation is defined by its Output tag name. Therefore there can be only
one count operation active for a given Output tagname.
Up Counter
The Up Counter increments a count
by one, each time a tagnamed bit
transitions (checked just prior to each
logic pass) in the direction (either
rises or falls) that is selected. In other
words, if you want to place an Up
Counter block that increments each
time a tagnamed bit changes from 0 to
1, select Counter, then select “counts
up” and “rises”, as well as the Output
(the tagnamed variable that keeps the
count) and the tag name of the bit that
is checked “every time” for the rising
transition.
Down Counter
The Down Counter decrements a
count by one, each time a tagnamed
bit transitions (checked just prior
to each logic pass) in the direction
(either rises or falls) that is selected.
In other words, if you want to place a
Down Counter block that decrements
each time a tagnamed bit changes
from 1 to 0, select Counter, then select
“counts down” and “falls”, as well
as the Output (the tagnamed vari-
able that keeps the count) and the tag
name of the bit that is checked “every
time” for the falling transition.
Counter Stop
The Counter Stop simply stops the
selected counter from counting. The
count value will not change. To place
a Counter Stop block, select “Coun-
ter”, then “stop counter” and select
the tagname of the counter that you
want to stop. Then select ‘OK
The basic 1.5K byte storage is commonly used for configuration, calibration and ‘recipe’ data stor-
age. This is information that is commonly set up, by the user, to ‘tune’ the operation, or set up
standard operational sequences or modes.
The larger memory can be used for the same type of data storage as listed for the small file memo-
ry. It also can be used for data logging and larger file storage.
Any PLC that has data logging/file storage capability will show two
tabs (once the Setup, using ‘Auto Setup’ is performed) below the Setup
Hardware window. The first tab, labeled ‘Solution’ is the list and defi-
nition of programs and subroutine in the application program. The
second tab, labeled ‘Logs’ is where data files are defined.
In order to use Log Files, vBuilder must determine what, if any, stor-
age capability the target PLC has. You must select the Setup Hard-
ware, then do an “AutoSetup”, so vBulder can read the PLC’a storage
capabilities. Once vBuilder determines that the PLC has data file stor-
age capability, a ‘Logs’ tab will appear next to the ‘Solution’ tab.
Note : If the ‘Logs’ tab and the ‘Data Log’ tool do not show up,
connect your PC to the PLC and perform an ‘AutoSetup’
A dialog box, shown below, will appear. Enter a name for the file that
you are defining. The figure, below, shows the beginning of the definition
of a file, named ‘Recipe’.
If you ‘Use Existing Data Log’, a copy of the lag definition that you choose will be copied to the project file. The data contained
in each record and the number of records in the file will already be defined. You can change the number of records and/or the
data definition of each record. If you do so, it will no longer match the log file that you originally selected.
If you want the record to be automatically time stamped, select the ‘Include time stamp’ check box. To ensure that time stamp-
ing works properly, you will need to set the internal clock to the correct time (See the section on the Real Time Clock).
To select the number of records in the file, use the up and down arrows, next to the ‘# of Records’ numerical box, to adjust to
whatever number that you would like. Remember that the limit on the total amount of file data available is either 1536 bytes or
128K bytes (131,072 bytes), depending on whether you are using a PLC that has the larger file memory option.
To calculate the amount of data that your file definition contains, you need to consider the number of bytes used by each data
type in the record. The following is a list of the number of bytes used by each file data type.
• Bit - 1 byte
• UI8 - 1 byte
• UI16 - 2 bytes
• S16 - 2 bytes
• S32 - 4 bytes
• Float - 4 bytes
For example, for the file definition on the previous page, each record would contain -
4 temp_set (float)
4 temp_deviaiton (float)
2 dwell_time (UI16)
4 transfer rate (S32)
2 agitate_time (UI16)
--------
16 total bytes per record x 10 records = 160 byt
Make sure that the total amount of data used by all of your data files does not exceed the amount of file storage data that is
available.
There are three program functions associated with reading and writing log file records. Those functions are :
• Write Record
• Read Request
• Transfer Record
To write data to a record, you use the Write Record function. The Write Record will set up the data to be written to the file re-
cord storage, handle the actual storage, as a background operation, then set a ‘Ready Bit’ to indicate the record write is complete.
To read data from a record, you use the ‘Read Request’ function to start the read process, then the ‘Transfer Record’ to transfer
the data that has been retrieved from file storage, after the read operation is complete. The ‘Read Request’ function tells the
PLC to read the record data from log file memory. When the read operation is complete, it wil set a ‘Ready Bit’. Your program
should check the Ready Bit. When it becomes a ‘1’, you can use the ‘Transfer Record’ to move the data to program tag name
data.
Remember that
you define the total
number of records
for each file. If the
Record number that
you select is greater than the number of records in the file, the read or write operation will not occur, and the tagnamed bit
variable the you select for the ‘Error Bit’ will be set to 1.
The next thing that you can do is select whether you want a Write Record, Read Record, or Transfer Record block. For writing
to a file record, select Write Record.
Next, select the tag named data that you want to store in this record. For example, if you want your log file to contain recipes for
producing ten different product variations, and you want to store the recipe for product 3, you might enter something like what
is shown in the dialog box image, below.
When a block, like the one shown above, executes, the data listed on the left side of the arrow (prod3_temp, etc.) will be written
to record 3 of Log file ‘Recipe’. When the write is complete, the ‘write_done’ bit will be set to a ‘1’.
If the write does not occur (for example, if the record number was higher than the number of records in the Log file), the Error
Bit, ‘write_error’, will be set to ‘1’.
Logging Data
If you want to log data, say a number of measurements
and statuses over time, you would use the same Write
Record function, just described. However, you might set
the Data Log file up to time stamp each record.
The figure on the right shows the Data Log file set up for
a log file intended to log up to 50 readings of the same
measurement and status information, over time. Since
the ‘Include Time Date Stamp’ check box is checked,
each record will be stamped with the time and date that
it was written.
A program snip-
pet, that shows
how data logging
might occur, is
shown below. In
this example, data
is logged once per
hour, up to the 50
records that were
defined.
In this example, the logic of tStep 6 check for when the one hour logging interval is complete. When it is time to log a record, the
interval is reset, the Write Record is executed (to start the record write process) and the step is set to 7.
In Step 7, the Ready Bit that was defined in the Write Record block, ‘write_done’, is checked. When ‘write_done’ is set to 1,
indicating that the write record operation is complete, the record number is incremented to prepare for the next record log. If
the file is not full (we defined the number of records as 50), tStep is set back to 6, to start the process all over again. If the record
number reaches 51, which is more than the number of records defined in our program set up, tStep is set to 8 ; which is should
continue on with whatever program operation is appropriate.
Step 7 also checks the Error Bit defined in the Write Record bock, ‘write_error’ to see if an error occured. A write error can occur
if you try to write to a record number that doesn’t exist.
There is also a check for a read error, in tStep 4. If you try to read a record number that is greater than the number that you’ve
defined for the file, there will be a read error.
The screen
capture, on
the right,
shows a
completed
dialog box
for read-
ing the
6th record
of a time
stamped
file.
The program process for reading a time stamped record is shown, below.
The Filter function is a background task function. You simply tell it what to filter at what weight
and time interval and the Filtering will happen behind the scene automatically. All you have to
do, once you’ve set up the Filter is use the filtered result value whenever you need it.
When you place a Filter block a dialog box will pop up. The box look like this :
To get a sense of what Filter does, right click and hold the slider shown next to “Less Filter” and
slide it across. The live illustration below the slider shows that with an Example input shown on
the left, the resulting output values will be like that shown on the right. Every time you click on
the New Example button, you’ll get a new example illustration.
Once you’ve started a Filter, it will continue to operate in the background until you stop it.
To Stop a Filter, place a Filter block and select Stop Filter and select the filtered Output value’s tag name. Click OK.
The high speed pulse counters in each unit are specified for typical operation up to 100KHz.
In reality, general high speed pulse inputs will operate at up to 250KHz. Quadrature inputs
will operate at up to 200KHz. The general high speed pulse counter consumes approxi-
mately 1.6% of total processor time (for the particular PLC unit that it resides in) for every
10KHz pulse rate, while the Quadrature input consumes approximately 2.8% per 10KHz.
As you increase the pulse rate, the CPU usage increases proportionately. Lower pulse rates
consume proportionately less time. Whether, and at what point that might become an issue
is application dependent. Up to 100KHz, it is hard to imagine an issue with most applica-
tions.
To implement high speed pulse counting, you must define a dedicated input pin (pulse) or pins
(quadrature) during the hardware setup. When you are setting up your hardware from the “Setup
Hardware” icon near the upper left corner, the following screen will pop up during the process.
The instructions on the screen are pretty self explanatory. The screen allows you to set up for
a high speed pulse counter, stepper motor output or both. To configure for a high speed pulse
counter, first select the type that you want (pulse or quadrature) from the drop down selection list
shown above.
MotionIn function blocks can only be used for inputs that reside on the PLC unit that
contains the program. In other words, MotionIn for the main program can only be ap-
plied to digital inputs on the main PLC unit (Ace or Branch). For MotionIn application in
Expansion units, an embedded object program must reside in that unit. MotionIn blocks
can be utilized in the embedded object subroutine and use digital inputs that are local to the
Expansion unit that contains the embedded object.
During hardware setup, the following screen will pop up, with high speed counter and stepper motion configuration options
for the main PLC and all other modules that are set up for embedded object programs. To configure a high speed pulse counter
for that module’s program (either the main program for the Ace or Branch, or an embedded object subroutine for an Expanstion
unit), select the Type as “pulsed” and select the particular digital input to use for your count, as shown below.
When entering your program, select the MotionIn icon and place it in the flow chart. A dialog box, like the one shown below,
will pop up. Using the dialog box, you can select to count up or down, or stop the count. When selecting count up or down,
you can select whether to count on the rising or falling edge of the input signal.
When a high speed pulse counter is started, it will continue to operate in the background until a “stop counter” block is execut-
ed.
Quadrature encoders are commonly used in servo motion systems, as well as any motion
or position application. For more information, there are a number of web sites that give
thorough explanations of quadrature endocers, including Wikipedia.
Quadrature Pulse In is restricted to counting transitions on a dedicated pair of digital input signals. One quadrature pulse coun-
ter can be implemented per PLC module (Ace, Branch or Expansion), so up to 15 can be implemented per application.
During hardware setup, the following screen will pop up, with high speed counter and stepper and motion configuration op-
tions for the main PLC and all other modules that are set up for embedded object programs. To configure a quadrature pulse
counter for that module’s program (either the main program for the Ace or Branch, or an embedded object subroutine for an
Expansion), select the Type as “quadrature” and select the particular digital inputs to use for your count, as shown below.
Stepper motion outputs use two digital outputs. One output is a direction signal, telling the mo-
tion driver to step in either the positive or negative direction. The other signal is a high speed
pulse output, which outputs one pulse to command each stepper motor step.
During hardware setup, the following screen will pop up, with high speed counter and stepper
motion configuration options for the main PLC and all other modules that are set up for embed-
ded object programs. To configure stepper motion for that module’s program (either the main
program for the Ace or Branch, or an embedded object subroutine for an Expansion), select the
digital output pins to use for the Step and Direction signals. The output pins that you select will
be dedicated for stepper motion control and not available for any other operation.
When a Move is started, it will operate in the background, until the target position is reached.
The stepper motion output is specified for a pulse rate up to 250KHz total for all stepper
outputs that are active. In other words, if you are driving only one motor, it can be pulsed
at up to 250,000 steps per second. If you have two motion outputs active at 100,000 steps
per second each and want to start a third output, its maximum speed will be 50,000 sps.
In motionStep 2, the subroutine waits until the armPosition is at the targetPosition. When it is, it stops the motion (which is re-
ally not required, since the finished move stops it anyway). Then it passes back motionComplete and the tank, or load/unload
station number where the arm is currently positioned and sets up to wait for the next move command.
Next, you must enter a i32 tag named variable for the
PLC to place the sensed position.
PID is Proportional - Integral - Derivative control. It is the very commonly used in process control,
heating control and motion control. The PID function calculates the “error’ value between a mea-
sured process variable and the desired setpoint. It adjusts an output in an attempt to minimize the
error. This adjustment occurs on a regular period. Each time an adjustment is made, it takes into
account the magnitude of the error (Proportional), the accumulated total of the error over time
(Integral), and the rate of change of the error (Derivative).
PID control is complex enough that we won’t provide a detailed discussion in this manual. It is
a common control algorithm and there are other excellent reference documents that you should
review to get an understanding, if you are new to PID. One very good description is on Wikipedia
at the following link.
http://en.wikipedia.org/wiki/PID_controller
We will also put out an application note on PID control and how to use it in the near future.
In vBuilder, PID control is a background task. That means that you Start it and it will continue to
run in the background, constantly calculating the error, integrating it and determining its rate of
change and updating the output based on these factors combined with the constants that you set
up. Once started, the PID will operate until it is Paused
O = P*E + I * ∫ E dt + D * ∆E/dt
where : O : Output
P : Proportional constant (sometimes referred to as the Gain)
I : Integral constant (sometimes referred to as Reset)
D : Derivative constant (sometimes referred to as Rate)
E : Error
dt : change in time
PID Start/Continue
The Start/Continue selec-
tion in the PID dialog box
creates a function block
that does exactly what it
says. If the PID is not ac-
tive, it will Start the PID’s
operation. If it is already
running, it will continue
operation. A PID actually
only has to be started once.
It will continue to operate
until it is Paused.
• Output : This is what the PID is actually adjusting. The Output should have a direct impact on the value of the Process Vari-
able. For example, a butterfly valve controlling the gas supply to a boiler’s burners has a direct impact on the temperature of the
boiler.
• Output Max : The maximum value allowable for the Output. Regardless of the result of the PID calculation, the Output will
be restricted to no more than this value. [any variable type except Bit and ui8]
• Output Min : The minimum value allowable for the Output. Regardless of the result of the PID calculation, the Output will be
restriced to no less than this value. [any variable type except Bit and ui8]
• Process Variable : This is the measurement of the parameter that you are trying to control.
• Set Point : This is the desired value of the Process Variable at this time
• Input Max : The maximum value of the Process Variable measurement that will be used for the PID calculation. If the actual
measurement goes above this value, this value will be used.
• Input Min : The minimum value of the Process Variable measurement that will be used for the PID calculation. If the actual
measurement goes below this value, this value will be used.
• Proportional : The constant multiplier to the error.
• Integral : The constant multiplier to the integral of the error.
• Derivative : The constant multiplier to the derivative of the error.
• Sample rate : The amount of time between each PID calculation/adjustment, in milliseconds.
• Freeze bias : This is a selectable option. If selected, it is used to limit the impact of integral portion of the equation to no more
than the entire Output range. This is useful in preventing overreaction after a time period where some factor prevented the actual
control of the Process Variable [which could possibly result in a huge integral value].
When you Start a PID, it will continue operating at the defined sample rate, behind the scene. In other words, once you start it,
you don’t need to continue to execute PID Start/Continue blocks for operation. It doesn’t hurt anything if you do. Its just not
necessary.
When you place a PID Reset in a flow chart, select the Out-
put variable of the PID that you want to reset, as shown on
the right. Select the value of the PID output to start the PID
with.
PID Pause
A PID Pause block stops the PID from operating.
When you place a PID Pause in a ladder rung, select the Output variable of the
PID that you want to pause, as shown on the right.
◊ Example
The example, shown below, illustrates a PID used to control a boiler. The PID Start and Reset will occur in processStep 1, the
boilerEn-
able is ON
(1). In
processStep
2, the PID
continues
to run until
boilerEn-
able is
OFF (0),
then PID is
Paused.
PWM is the acronym for “Pulse Width Modulation”. Pulse width modulation is a very powerful func-
tion that is commonly used to control the positioning of servo valves. It is also used for laser pulse
control, motion control, light intensity controls and other other applications. The single pulse feature
of the function is applicable to any single pulse output need.
A pulse width modulated output signal is one that has a period and an output “on time”, or duty cycle,
within that period. For example, a typical servo valve control might have a 20 millisecond period.
Valve position is controlled by the “on time” of the output pulse, within this period. The valve
may be controlled to a fully closed state with a 1 millisecond pulse on time and fully open with a 3 mil-
lisecond pulse (actual times are defined by the valve manufacturer). Partial (5%, 10%, 53%, etc.) open-
ing is generally controlled by an “on time” pulse purportionate between to full open and full closed
limits. Standard PWM signals repeat every period increment.
PWMs Application Limits : PWMs can be applied to any digital output that is physically present
on the PLC module that contains the application program. That means that any Ace or Branch
digital output can programmed to output a PWM signal by the application main program. Any
Branch Explansion PLC which has its own program (embedded subroutine) can output a PWM
signal from the embedded subroutine. Branch Expansion units that are used a expansion IO, can-
not output PWM signals.
Any combination of digital outputs, contained on the PLC with the program, can have PWM output
signals. Each active output has its own “on time”. However, the Period is common to all PWM sig-
nals on the PLC unit.
Set Period
The Period is common to
all PWMs in the PLC. The
period is set by selecting
the “Set Period” radio but-
ton, then either selecting
a ui16 tagnamed variable,
or entering a number
between 100 and 65535.
Timing is in microseconds
(1 million microseconds =
1 second). That means that
the PWM period can range
from 100 microseconds to a
little over 65 milliseconds.
Start
The Start selection defines
the Output and the On Time
for the PWM signal. It also
provides a selection for either
Continuous or Single Pulse. If
the PWM is to be used for a
varying On Time PWM signal,
each time the block is execut-
ed, the On Time will update its
value on the next Period.
If you select Continuous operation, PWM pulses will continue, one pulse per period, until you execute a Stop PWM block for
the output. If you select Single Pulse, it will output one pulse on the next Period. After the period is complete, the output
will be set according to the program digital output state for that output.
Stop
To place a block to Stop a PWM ouput, you
simply select the Stop radio button and select
the tagname of the output. If you are placing
the Stop block in a subroutine, place the refer-
ence to the output as the Output Pin.
The main portion of the example program consists of three steps. Step 1 looks for whether InBitC1, InBitC2 or InBitC6 are
turned on. When one of these inputs becomes ‘on’ at least one PWM output will start. If the C6 input is turned on, both PWM
outputs will be turned on. The on times are set to out1Period and out2Period respectively. The other thing that will happen in
this example is that the state machine step will advance to 2.
Step 2 will output a Single Pulse on output D3, then advance to step 3.
In step 3, the PWM pulse or pulses that were started in step 1, will continue until InBitC5 is turned on. When that happens, the
PWMs will be turned off and the state machine set back to step 1. It doesn’t matter it a PWM signal is turned off when it isn’t
on. If that is the case, when the program block is executed, nothing happens.
The Ramp function changes a value from its initial value to a target value, at a defined rate of
change. Optionally, a ramp can include a soft start and soft stop. A soft start ramps the rate of
change up to the defined rate of change gradually, over the defined soft start/stop period. A soft
stop ramps the rate of change from the defined rate to 0, over the defined soft start/stop period.
Ramp is commonly used for motion control. The vBuilder Stepper Motion function has its own
ramp feature built in, so this Ramp function would not commonly be used for stepper motion
control. It would be applicable to servo motion control, typically coupled with a high speed pulse
counter input and PID.
Ramp is also applicable to other machine and process control applications. Any time you want to
change a variable at a defined rate, Ramp can be used.
Ramp is a background task. It only needs to be Started. Once Started, it will continue to
operate in the background until Stopped.
Ramp Start
When you place a Ramp block in a flow chart, a dialog box will pop up. This box will allow you
to Ramp Start, or Ramp Stop. To Start a Ramp, select the Ramp button, then enter the parameters.
• The top selection is the variable that you want to Ramp.
• Next is the ramp rate in units per second of whatever unit the Ramp variable is. The Ramp
Rate is an absolute value. Whether it is a rate of increase or decrease depends on whether the Ramp
variable is above or below the target.
• Next is the Ramp Target - the .final value of the variable after ramping
• Optionally, you can enter a Soft Start/Stop time. If you enter a Soft Start/Stop time the ramp
rate will ramp up to the Ramp rate over the defined period and ramp down over the same defined
period, when approaching the target. This will have the effect of rounding off the value curve, like
that shown in the Ramp button graphic.
◊ Example
The example, below, shows the ramping of a steamPress setpoint. In processStep 5, the Ramp is initiated, then processStep is set
to 6. In processStep 6, when the steamPress setpoint is greater than or equal to the target value (it will actually stop ramping at
equal to), the Ramp is Stopped.
Once you’ve set the time, it will be shown at the top of the dialog box.
Select ‘Read’.
Select UI8 (unsigned 8 bit) tag names to transfer the clock data into for the current year,
month, day (of the month), hour, minute, second, and day of the week.
Once you click ‘OK’, the block will be placed in the program. An
example is shown on the right. Whenever this block is executed,
the real time clock will be read and the data will be transferred to
the tagnamed variables defined in the block. In other words, the
year reading will be placed in ‘year’, month reading in ‘month’,
etcetera.
Select ‘Set’.
Select UI8 (unsigned 8 bit) tag names, or constants to transfer the clock data into the
current year, month, day (of the month), hour, minute and second
Once you click ‘OK’, the block will be placed in the program. An example is shown
on the right. Whenever this block is executed, the real time clock will be set with
the data data from the tagnamed variables defined in the block. In other words, the
year will be set to the value held in in ‘year’GMT, month set from ‘monthGMT’,
etcetera.
The Scale function is used to automatically convert an input value to an output value. It is com-
monly used for scaling a raw analog reading to its equivalent value. Scale has the capability to do
piecewise linear scaling between up to 16 points. With piecewise linear scaling between such a
high number of points, Scale can be used to convert values from non-linear transducers as well as
an assortment of other applications.
When you place a Scale block, a dialog box, like that shown below will pop up. In the dialog box,
you need to choose the Input and Output variables. You must also define the scaling in the Input
and Output tables, as shown. The scale curve will automatically be created on the right to illus-
trate the scaling that will take place.
◊ Example 1
The example shown below, shows the simple scaling of a 12 bit A/D conversion of a pressure
transducer that outputs -14.7 to 3000 psi as 0 to 5V. As shown in the graph, it results in a linear
conversion curve.
The Shift function allows you to shift an integer number left or right, a selected number of bit posi-
tions. A bit value that you choose is shifted into the vacated bit position(s). For signed integers,
the shift can be defined to include or exclude the sign bit (the most significant bit).
The Rotate function is similar to the Shift. The difference is that the bits that are shifted out of one
end of the number are shifted back into the vacated position(s) on the other end.
If you uncheck the Exclude Sign Bit box, rotating will in-
clude the entire number.
Before you can create a Subroutine call, you must have already created the subroutine.
Subroutines are discussed in detail in depth in the chapter on Object Oriented Programming and
Subroutines.
When you place a Subroutine Call block, a dialog box, like the one shown below, will pop up. On
the left side of the box, is a list of all of the defined subroutines. Choose the one that you want to
place. Once you’ve done that, the right side of the dialog box will contain a list of Data to Pass to
the Subroutine. Since all Subroutines in Velocio PLCs are objects, the first thing you need to do is
define the Data Set # (object number) that this Subroutine Call is associated with. If you only have
one instance of the Subroutine, you can leave this blank.
Next, you see a list of Passed Data. On the right hand side of the list is the subroutine tag name
associated with each item - in other words, the tag name used in the subroutine. On the left are
selection boxes to allow you to pick the local tagnames of the data to pass. Between the two col-
umns is the Pass Type for each parameter. The following is an explanation of the Pass Types.
• The symbol with a single arrow pointing to the subroutine indicates pass by value. The nu-
meric value of the data on the left (tagname variable data or constant) is passed into the subroutine.
There is no effect on the data in the calling program.
• The symbol with arrows going both directions indicates pass by reference. In this case, actual
data is not passed. What is passed into the subroutine is a “reference” to the tagname variable. This
reference allows the subroutine to read and/or change the value in the calling program. This is how
data is passed back out of a subroutine.
Fill out the Pass Data to Subroutine list and click OK.
Calling Embedded
Object Subroutines
Calling an Embedded
Object Subroutine is basi-
cally the same as calling
a local subroutine. There
are a couple of differ-
ences though.
• Parameters
passed to and from
Embedded Objects are
In and Out. There is no
pass by reference. You
either send data to the
object or receive it from
the embedded object.
• If there is more
than one device con-
figured for the same
embedded object, you
must select which one
you are calling. The
particular embedded
object is defined by
its branch path. The
branch path is defined
by its port connection
relative to the unit the
call is made from. For
the example shown on
th right, the choice is between the unit connected through its first vLink port, then through that
unit’s first vLink port (>>1>>1), or the one connected through its first vLink port, then through
that unit’s second vLInk port. The Setup graphic makes it pretty clear. In this case, the two
choices are yellow 1 and yellow 2.
The Subroutine Return has no dialog box. It simply can be placed in the Flow Chart.
◊ Example
The example, below, shows a Subroutine Return block placed in a subroutine.
Timer Start/Continue
When you want to Start a Timer, select the
Start/Continue option in the dialog box. The
only other thing you need to do is place the
tagname of an i32 variable to be used to con-
tain the time value in the box labeled Timer.
Timer Pause
A Timer Pause block is used to stop a Timer
from operating. To place a Pause, select the
Pause option in the d--ialog box and enter
the i32 tagname of the variable that holds
the time value.
Almost all control applications that have any level of complexity are natural state machine applications and are most
logically, efficiently and effectively implemented with state machine style of programming.
How do we know this? Through years of developing a myriad of control systems for everything from material handling, to
cereal fill line automation, to municipal water and wastewater systems, to semiconductor wet processing, toxic gas distribution,
chemical mix and delivery, full semiconductor fabs, hoovercraft control and simulators for NASA’s astronaut trainers, automat-
ed testers ... and on and on and on. Every single system was designed with a state machine control architecture.
Because state machine design was the best solution for every single application, we didn’t use a PLC. Traditional PLCs have
been very poor tools for implementing state machine logic. Ladder logic in a single large program doesn’t work very well for
state machine applications. It’s possible to use traditional PLCs to develop one long ladder program using state machine logic,
but it is a tortured process at best.
Velocio’s Ladder Logic, with object subroutine and embedded object functionality lends itself much better to state machine ap-
plications. For PLC programmers who prefer ladder logic, state machine programming in vBuilder Ladder is quite straightfor-
ward.
vBuilder Flow Chart programming is an absolute natural for state machine program development. It is perfectly suited for
breaking the application down to small, logical components, tying those components together and implementing the sequence
logic to implement all of the requirements of any given application. It will also yield a finished program that self documents
and is much easier to maintain, modify and propogate than anything else available. If we had a control application to do today,
we’d absolutely choose a Velocio PLC as the best solution. We’d utilize vBuilder Flow Chart programming using State Ma-
chines.
The next few pages go through the concepts of State Machine programming.
Imagine yourself sitting in your living room, watching TV. That’s your state. Your state is the situation that you are in. In that
state, there are a number of things that could happen. Here’s a few examples.
• Break your program up into logical subroutines that directly relate to natural components of the application
• If a subroutine still contains a great deal of complexity, break it up into the next level of subroutine
• Sketch out the main program loop with a flow chart. The main program will be a super loop that calls the state machine sub-
routines for the various logical components of the operation.
• For each subroutine, start breaking it down to a sequence.
-- Start with the initialization state
-- Continue with what happens after initialization is complete
-- Each step in the sequence should be designed along the lines of “while in this state do this; if this happens, do this, then transi-
tion to this state”
• Never loop the program waiting for an event to occur
• Sketch out a flow chart, on paper, with your logic. That way you can quickly & easily mark it up.
-- Create an integer as as step number to keep track of your state, or step
-- Start with the state that exists after initialization (or if this program does the initialization, the state at power on). Make that
your first step. Put in blocks to do what ever needs to be done in the first step. Add decision blocks that check events that would
cause you to move to another state.
-- For each state, put in blocks that perform the operations that are required in this state and the decisions that trigger a transis-
tion to another state.
-- Make sure that you have every potential state covered.
• Repeat for every subroutine
The drawing on the next page shows the general flow of a subroutine written in state machine style of programming. The con-
cept is very simple. When applied to a program of any size the result is very powerful.
If you Google the advantages of object oriented programming, you will find innumerable lists compiled by various software
experts, architects and general users. Everybody has their own list, but almost everyone agrees that there is a long list and that
object oriented programming is a major advance in the software industry. We have summarized what we believe to be the high
points, as associated with control applications, below
• Structure : Application of object oriented programming promotes program development in a structured manner. In fact, to a
large degree, it forces structure. Structure, in turn, enhances design productivity, maintainability and documentation.
• Modularity : Objects are program components that focus on specific pieces of the application. By definition they form pro-
gram modules.
• Partitioning of design focus : Objects are self contained with a clearly defined interface. When developing an object, you are
totally focused on that object alone, without the distraction of other aspects of the total system. That focus leads to higher levels of
productivity.
• Reusability/portability : A huge benefit for anyone who develops multiple applications which have certain functions in
common, is that objects can be re-used. Any object that you develop in Velocio Builder is automatically seperately stored in its own
independent files. Those files are portable and can be reused in other applications. This is a huge factor in development efficiency,
software quality and reliability. In addition, since multiple instances of the same object can be used in a program, object modules
are reusable even in the same system.
• Isolation/reliability : Since objects contain (encapsulate) all of their required data and subroutines (functionality), they totally
isolate a portion of the program. That isolation enhances debug and maintenance and leads to greater application reliability.
• Maintainability : System maintainability is enhanced due to the modularity and isolation of the object components. Main-
tenence is clearly focused only on those areas that need to be modified. Objects that require no modification do not need to be
touched. The simplification of the application makes future maintenance, even by someone other than the original developer, much
easier to perform and less susceptible to error.
• Protection against unintended consequences : In traditional PLC application programs, all memory is global (accessible
everywhere) and the program is just one long sequence of program rungs. That frequently leads to situations where a developer
is trying to work on one area of the program causes something unintended to happen in another area. By encapsulating data with
functionality, objects prevent that from happening.
If this all sounds high minded to the point of being ovewhelming, don’t worry about it. vBuilder makes object oriented pro-
gramming very easy to do. The following pages will explain.
• A subroutine is program that is called by another program to perform some special function. It is a way of logically breaking
up a larger program into smaller, logical blocks that performs specialized functions. A subroutine is programmed the same way as
the main program. The difference is that it can have information passed into it by the program that calls it and it can be designed to
pass information back to the program that called it. Another feature of a subroutine is that it can be called from multiple places.
• A program object is like a component. Think of a wheel on an automobile. The wheel is an object. Similarly a program object
is a software component that is clearly defined and “encapsulated”. It has clear boundaries and a clear interface. Just like a wheel
is a clearly defined component of a car, with a clear function (to support the vehicle and roll), and has a clear interface with the car’s
hub and mounting bolts, a program object has a clear function that you define and a clear interface of data that is passed in and out.
All other data that is used by the program object belongs to the program object and is not accessible by any other part of the pro-
gram.
The following description may appear to be a little abstract at first. Don’t let your eyes glaze over. Its short & you’ll un-
derstand it soon. We’ll get into examples that make it make sense soon, but we have to lay out the basic principles first.
All subroutines in vBuilder are object subroutines. What that means is that they have there own section of memory for their
own private data. A vBuilder Object is a set of data plus defined functionality. The functionality is the subroutine program
functionality. There can actually be more than one subroutine associated with an Object, but we’ll get into that later.
The first time you create a subroutine in a project, you create an object. You can define tagname variables for that subroutine,
just like you can for the main program. You’ll notice that when you define the subroutine
tagnames that you don’t see the tagnames for the main program or any other subrou-
tine. That is because you are defining the data that this object works with. Any data
that comes into the object from the program that calls it or is sent back, is defined in the
Subroutine Inputs and Outputs block.
Look at the figure on the right. This is an illustration of how memory is set up in the
PLC. The main program has its data, which includes all of the IO and any tagname vari-
ables that are defined for the main program. The figure shows a program that has a main
program and two types of Objects. These are two subroutines. The first subroutine has
three “instances”. The second subroutine has two instances. The first subroutine, or ob-
ject type has more local data than the second. Each “instance” has a seperate set of data.
Objects are generally created to relate to the control of something real. In this case, con-
sider this to be a building control and security system. The building has three main work
rooms and two bathrooms. To control it, we might create an object called “workRoom”
and a second object called “bathRoom”. The workRoom objects would each have a
thermostat, ventilation controls, window security, smoke detector, door security, light-
ing control and audio controls. There would be tagnamed data defined for each of these
items, which would constitue the Object Data. The bathroom would have ventilation
controls, lighting controls, automatic periodic flush controls and hand dryer controls,
constituting its Object Data.
We have three workRooms that all operate the same way, but are likely all in different
conditions at any given time. Therefore we need three seperate Objects. Each Object has
the same set of data, but each Object’s data is seperate from the others, because it needs
to hold different status and values and it must not be affected by what is going on in the
other rooms. The same for the bathrooms. So that’s what we create with our Object Sub-
routines. We have two subroutines, one for workRoom and one for bathRoom. Work-
Room has three instances or sets of object data. BathRoom has two instances, or sets of object data.
There are a lot of interrelated topics included in vBuilder object subroutine programming. Here is a general list -
• subroutines
• objects
• embedded objects
• multiple instances of objects
• linked subroutines
We’ll start simple. In fact, if you went through the Tutorials, you’ve already written a program with object subroutines.
This is the Flow Chart version of Tutorial 2. From this screen shot, you can see some of the fundamentals.
If you have not entered TutorialFlow, go back to chapter 2 and go through its entry and debug. We’re going to use it to
explain object subroutine concepts.
In the call to
Cycle3 object
1, a reference
to cycleStep is
passed to cStep.
In the call to
Cycle3 object
2, a reference
to cycle2Step is
passed to cStep.
Inside Cycle3,
cStep is what is
used. The actual
data for cStep
is in the main
program’s tag-
named variable
whose refer-
ence is passed
in. The same
applies to out-
States/outStates2
and cycleData.
Each time the Subroutine Call to Cycle3 is made, the two references, along with the current data passed to ‘run’ is passed to the
Subroutine.
Program the PLC. Put it in Debug mode. Select Values display. Click Run to start the program.
If you look at the main program, you should see that the value
of 1, which is the state or value of the cycleSelect input is being
passed to Cycle3 object 1’s run bit. The value 0, which is cycle-
2Select’s bit value when the B2 switch is off, is being passed to
Cycle3 object2’s run bit. Consequently, even though the same
subroutine is called in both cases, object 1 is cycling the outputs
while object 2 is not. You can see this happen with the cycleData
that is changed by the subroutine and unpacked in the Unpack
blocks right after the Subroutine Calls.
Switch back
and forth
between
Name and
Value modes
so you clearly
understand
what you are
observing.
Switch back and forth between the two objects. See how differently they are executing.
To further illustrate, clear the breakpoint and click Run again. Place a breakpoint on the Timer Pause block. This time, the pro-
gram will stop at the Pause block and change the display to show object 2.
Turn the cycle2Select (B2) switch on. You should now see both groups of three outputs cycling. They will very likely be cycling
at different times. The Cycle3 subroutine was created with one timer - interval, which determines the time to Shift the outputs.
The interval timer is part of the Cycle3 object, so each instance of Cycle3 has its own interval timer. If you look at the data illus-
tration a few pages back, you should see the to instances of interval clearly illustrated.
vBuilder object data is a separate package of data for each instance of each type of object. That concept was clearly illus-
trated in the last few pages. If you don’t clearly understand object data and instances of object, please review the pages
of this chapter, prior to this point, before proceeding.
Any number of suroutines can be linked together as part of an object. By employing seperate subroutines for each type of be-
havior, program efficiency and clarity can be greatly improved. A typical object might have linked sutboutines for the following
purposes.
• Initialization (setting up initial data, plus the acquisition of references used in operation)
• Normal operation
• Special case operation (there many be more than one of these)
• Shutdown
There many other reasons and strategies for creating linked subroutines. Let’s get into the concepts through an example.
The example that we will go through is a program that does the same thing as the tutorials that cycle the outputs -Tutorial
Example 2, discussed in both chapter 2 and earlier in this chapter. We’ll accomplish the same program operation, but do it with
linked subroutines.
If you have looked at Tutorial Example 2 recently, you know that the main program handles the actual I/O processing, while the
Cycle3 subroutine handles the logical operation of controlling the cycling of the outputs, including timing. Actual I/O informa-
tion is passed into Cycle 3 and passed back to the main program through references.
In this example, we will do things a little differently. Initialization will occur in an initization subroutine, linked to the linked-
Cycle3 operatational subroutine. Rather than pass data from the main program to Cycle3 for processing then handling output-
ting the outputs in the main program, we’ll do that in linkedCy-
cle3. This will become clear as you go through the example.
Next, select Add Subroutine and fill out the dialog box to add a
New Subroutine named linkedCycle3, using Flow Chart pro-
gramming. Click Add Subroutine.
When the dialog box comes up, select “New Subroutine”. Enter “initCycle3” in the Name box. Select “Link to Existing Data
Set”. On the far right, a
new entry box, labeled
“Data Set” will pop
up. The selection box
will make available
all of the objects types
that currently exist, for
you to choose from.
So far, we only have
one object type, called
linkedCycle3. Select it
and click Add Subrou-
tine.
The listing under Project Files will now appear as shown on the right. The main program - LinkedCycle -
is shown as residing in the main PLC (the only one necessary for this example). Under it is linkedCycle3.
Next to linkedCycle3, the object count adjustment shows that this object is named by the “linkedCycle3”
subroutine to its left and there is currently only one object defined. Adjust the number of objects to 2.
Below linkedCycle3 is initCycle3. The chain links that start at linkedCycle3 and end at
initCycle3 show that all subroutined within this range are linked to the same object.
Double click to select the Subroutine Inputs and Outputs in initCycle3. Enter the four
pass by reference bits shown on the right.
What you are defining to pass into the linkedCycle3 object, when initCycle3 is called, is
references to one digital input and three digital outputs. The digital input will serve as
the run switch, which will enable or disable the cycling of outputs. The outputs are the
three outputs which will be cycled.
Click OK.
Open up the Tags (while initCycle3 is still selected). You should see the four tags that
you just defined as bits passed in by reference, listed as register bits. As far as the
linkedCycle3 object subroutines are concerned, these are simply bits that they can use.
While the Tag dialog box is open, create ‘cStep’ and ‘outputs’ as ui16 tagnamed vari-
ables and ‘interval’ as an i32.
When initCycle3 is called by the main program, it will initial everthing that
linkedCycle3 needs initialized. An important aspect of the initialization is actu-
ally not in the program logic of the initCycle3 program. It is in the Subroutine
Inputs and Outputs. When initCycle3 is called, references to the input used for
run and the three outputs are passed into the object. They are thereafter there
to use by any of the linked subroutines. By including the reference passes in the
initialization routine, these references never need to be passed in again.
The next thing that initCycle3 does is initialize the step or state counter, cStep to 1
and set the initial state of the 3 outputs to outputting the first output on and other
two off. This subroutine doesn’t actually write to the outputs. The linkedCycle3
subroutine will.
Select and enter the linkedCycle3 subroutine. There are no Subroutine Inputs
and Outputs required, so leave that blank. Enter the subroutine as shown below.
Everything after the Start block is shown. The flow is very similar to the previous
example. A major difference is the fact that this subroutine now directly ac-
cesses the inputs and output through the references that were passed in its linked
subroutine, initCycle3. An unpack block at the end of the subroutine writes to the
actual outputs.
Traditional PLCs have one CPU that executes the application program. IO modules can be added, sometimes in a modular
fashion - generally with a backplane bus. Velocio can do that as well, with greater flexibility, through vLink communications.
With traditional PLCs, if you have multiple PLCs that need to share information, or have PLCs that take commands from other
PLCs, you must set up communication links or networks. This tends to be an extremely complex, time consuming and er-
ror prone undertaking. In addition, debugging such a system generally requires multiple development systems that are not
linked.- an unwieldy undertaking.
Velocio PLCs were designed with multiprocessing as a fundamental feature of the architecture. They are designed to provide
machine to machine sharing of data, with multiprocessing program execution and do so transparently.
Let’s start with the basics. Say that you have a system with one Branch PLC
and two Expansion PLCs. Each Expansion is connected directly to the Branch
through a vLink communications cable. This configuration is shown on the right.
With this configuration, the Branch Expansion units could simply provide expan-
sion IO for the Branch. The entire program operation could occur in the Branch
PLC. In many cases, that is what you want.
In this scenario, the ideal solution would be an implementation that places the program logic in each individual PLC (a pro-
gram in the Branch and programs in each Expansion), with data passed between the Branch and Expansion units. Ideally, this
data transfer would occur many times per second, so real time control/coordination and interdependent operations can occur.
That is what Velocio’s Embedded Objects are designed to do. That is just one of a myriad of scenerios to which they apply.
Any time that direct, on the site control, coupled with system integration is required, Embedded Objects can provide the solu-
tion. Any time that a system can be subdivided into clearly defined subsystems, Embedded Objects provide a better solution.
As we’ve done throughout this manual, lets introduce the concepts, through a simple examples, starting on the following page.
We will go through this simple Embedded Object example in three phases. Each phase will add a little complexity and should
provide additional clarity to the subject of Embedded Objects.
Phase 1 : Develop a program with one Branch and one Branch Expansion
• Cycle three outputs on the Branch based on the status of a switch in the Expansion.
• Cycle three outputs on the Expansion based on the status of a switch in the Branch
Phase 2 : Add a second Expansion
• Cycle three other outputs on the Branch based on the status of a switch in the Expansion
• Cycle three outputs on the second Expansion based on a second switch in the Branch
• Keep previous operation from Phase 1
Phase 3 : Add “heartbeat” monitoring
• Each of the Branch Espansionss monitor communications from the Branch and adjust their operation accordingly
• Branch unit monitors each Expansion and adjust its operation accordingly
By the time you get through all three phases, you should have a good handle on Embedded Objects.
For the next screen, we don’t have any high speed counters or stepper motors in this application, so leave everything “none”
and press Done.
Your screen
should now look
similar to that
shown on the
right. The Setup
Hardware window shows that you have a Branch (the blue square) connected to a Branch Expansion from the Branch’s vLink
port 1 (the green square labeled 1).
Program the PLCs and put them in the Debug mode. After you select Run :
• If you switch the B1 switch of the Branch unit, the Expansion outputs should cycle.
• If you switch the B1 switch of the Expansion unit, the Branch outputs should cycle.
Looking at the main programs for the Branch and Expansion units, side by side, switch the Branch unit’s B1 switch back and
forth. You should see the value change in both programs. The Branch B1 is the bit passed into runXCycle, shown in the Embed-
dedCycle Subroutine call to XCycle, and shown as the Embedded Subroutine Inputs and Outputs (the in bit).
Try it with the B1 switch of the Expansion unit. Again, the same status should appear on both sides. You have entered and are
running a program where you are communicating real time data between two independently running PLCs. You did it without
setting up all kinds of communications functions. Its just a Subroutine call.
To demonstrate that the two PLCs are running independently, click the linkedCycle3 block on the XCycle program window.
You will see that the XCycle pro-
gram stops at that block, while
the EmbeddedCycle program in
the Branch unit continues to op-
erate. In addition to the view on
the vBuilder screen, you should
see this happening in the actual
PLC operation.
click the other square, the focus will change. The bold 1 indicated that it is focused on object 1 of the unit.
Start by turning off Debug mode and connecting a second Branch Expansion PLC to
port 2 of the Branch.
We will configure the Setup Hardware by doing Auto Setup again. We always prefer
to Auto Setup, to make sure that everything is present, connected and communicating
before we begin programming.
Select “XCycle.vio-
fes” and Open.
You have now configured the Hardware to place XCycle Embedded Objects in both Expansion units. We do have to make some
other program changes before we’re ready to go though.
You have created an application in which three PLC units are each executing their program logic simultaneously and passing
information seamlessly. Granted, this one is a simple example. It does demonstrate the basic concepts that can be scaled to any
level.
Notice that if you disconnect the vLink cable between the Branch
and one of the Expansions, both sides will continue to operate based on the switch status that existed prior to the disconnect.
Disconnecting communications means that the data does not get updated. Sometimes this is OK. Sometimes, you want to know
if communications is lost. You may need to have a program that performs operation differently when communications is active
versus when it is inactive. That is the subject of Phase 3.
A very simple solution to this problem is the addition of a “heartbeat” to the communications parameters. The concept is
simple.
• The device on one side of the link toggles a tagnamed bit at a predefined frequency (the heartbeat)
• The heartbeat bit is included in the parameters of the Embedded Subroutine Call
• The device on the other side of the link checks that the hearbeat is changing state within a reasonable time period. If it is not,
it discerns that the link is not active.
Select Add Subroutine under the EmbeddedCycle list and add a Subroutine called HeartBeat.
In HCheckInit, define
‘beatToCheck’ and ‘talk-
ing’ as pass by reference
bit Inputs. Create an i32
tagnamed variable called
‘listenTime” and a bit
called ‘lastBeatState’.
Enter HCheckInit, as
shown below.
Add two bits to the Inputs and Outputs. HBin is the heartbeat from its master.
HBout is the Embedded Object’s heartbeat to its master.
Under Program Files (far left), under XCycle, select Add Subrou-
tine. Click “Select Existing Subroutine”, then select HeatBeat. We
are putting the same HeartBeat program in the Expansions as in the
Branch.
The expected operations should be fairly obvious. The heartbeat communications is handled transparently in the Subroutine
Call in the Branch unit’s program.
You should see the three PLCs operate like they did before. The two groups of Branch outputs cycle, based on switches from the
two Expansions. The Expansions outputs cycle based on the B1 and B2 Branch inputs.
You can
continue
to play
with the
program.
To start
Expansion
1 operating
again, clear
the break-
point and
click Run.
Disconnect-
ing cables
should have
the same
affect as
stopping a
unit’s pro-
gram.
Bottom Line : Developing a distributed processing system is easy with Velocio PLCs & vBuilder. Adding a heartbeat for
each unit is recommended in most cases. What you do with the heartbeat is going to be application dependent.
Protocol definition for Modbus RTU communications is readily available. If you don’t already have that documentation, simply
Google Modbus protocol. A large number of links to documents will come up. If you are unfamiliar with Modbus, we’d recom-
mend that you go through this documentation first. Modbus RTU is a very simple protocol. To simplify it further, you only
need to review the messages that are actually used. Those messages are listed below.
As a matter of fact, you don’t even have to implement all of the function codes. Function codes 01 and 02 read the same infor-
mation. Function codes 03 and 04 do also. You only need to implement either function code 01 or 02 and either function code 03
or 04.
Velocio Networks supports Modbus RTU communications over USB. The USB standard supports a number of “profiles”. A
profile is an implementation of communications that works over USB in a particular manner to optimize a particular type of
data transfer. Some profiles are standard. Some are proprietary. There are standard profiles for communications with a USB
mouse, for doing high speed data transfers to devices like a USB thumb drive. There is also a standard profile, called the CDC
profile, that makes the USB port operate like an RS232 serial port. In fact, if you’ve got a USB to RS232 conversion cable, the USB
profile used is the CDC profile.
In the USB world, one side of the communications link is the “host”. The other side is the “device”. A PC almost always oper-
ates as a “host”. Velocio PLCs operate as a “device”.
If you are implementing Modbus RTU communications to a Velocio PLC, your apparatus must be a “host”
If you are implementing communications from a PC or similar type of machine, it will naturally be configured as a host. If you
are communicating from an embedded instrument, like an HMI panel, your product design must incorporate a host USB port.
In vBuilder, any global tagname can be selected for Modbus communications. Additionally, each selected tagname can be set
for either read only or to allow to be written to by an external device over a communications link (Modbus). The following
paragraphs will descibe how to perform Modbus configuration for a vBuilder program. You can write your own programs,
configure them as you’d like and test your communications. In addition, Velocio has a vBuilder program already written and
configured to communicate via USB Modbus and a demonstration application that runs on any PC and clearly illustrates Mod-
bus communications to a Velocio PLC. Also available from Velocio is an Application Note that goes through the demonstration.
To select a tagname for Modbus mapping, select it from the drop down box, or type in the tag name. Next, select a Modbus
address to associate with the tagname. If you simply click inside the Modbus address box, next to the tag name, vBuilder will
automatically assign the next avail-
able address. You can change it if
you want, by typing in the address
that you would like.
If you look at the dialog box above on the right, you will see that the floating point number is assigned Modbus addresses 1 and
2. The unsigned 16 bit number is in address 3. The two ui8 numbers are in individual registers 4 and 5.
Any available PLC software, for download, is available at the Velocio website - Velocio.net.
Download the software from the web site.
In order to download software to one or more PLCs, the PLC(s) must be connected to the
PC with vBuilder and powered up. Check the USB symbol in the lower right hand corner to
verify the USB attachement.
Select ‘Bootload’ under the Help menu. A window, like the one shown below, will pop up.
It will show the PLCs that are currently attached and the version of software in each unit.
For example, the screen on the right
shows that there is a Branch and two
Expansions. All three units have ver-
sion 1.00 software in them.