How-to
Editing a cam curve from an HMI on a running motion axis
Short answer
The HMI never writes the cam technology object itself. It fills a global array of interpolation points on the motion controller, sends it in chunks under a command/acknowledge handshake, and the controller validates and interpolates the curve while the axis runs. Send about 20 pairs per chunk, write the command word last, and wait for the done state before the next chunk.

On this page
A WinCC flexible panel cannot open and edit the cam technology object, but it does not need to. The cam object is a table of interpolation points in controller memory, and that memory is writable from the HMI while the controller runs. The operator builds the curve on the panel, the HMI fills a global array under a command/acknowledge handshake, and a short routine in the controller validates the table and interpolates the cam. No trip to the engineering tool is needed for an operator profile. This article walks through the variable interface, the chunked transfer, the arithmetic behind the chunk size, and the validation that must happen in the controller before the follower ever sees the new curve.
What the cam object accepts from an HMI #
A cam on a motion controller stores a function y = f(x): the leading value x comes from the master axis, and the following value y is what the coupled axis commands. Two data models exist. An interpolation-point table is an array of x/y pairs that the technology object interpolates between; a polynomial-segment definition stores coefficients per segment and suits generated motion laws such as rise, dwell and return. The point table is the model an operator can edit cell by cell, so it is the one this procedure uses.
Before writing any screen, open the cam technology object configuration in the engineering tool and read the maximum number of interpolation points configured there. The HMI table length must not exceed that number. Oversizing fails at the interpolate call, not at transfer, so settle it now rather than after the screens are built.
Declare the array and the handshake variables #
Declare everything the HMI touches as global unit variables in the interface section of an ST unit, flag that unit for HMI access in the engineering tool, and import the symbols into WinCC flexible so the tags appear on the controller connection. Keep the interface minimal, because every exported symbol consumes access bandwidth on the connection. The names below are an example interface, not a manufacturer requirement; your own can differ, but keep one write direction per variable and the same roles.
| Variable | Type | Direction | Role |
|---|---|---|---|
camReq.bufX, camReq.bufY |
ARRAY OF LREAL | HMI to controller | One chunk of leading and following values |
camReq.pointCount |
DINT | HMI to controller | Valid pairs in this chunk |
camReq.totalPoints |
DINT | HMI to controller | Expected total for the profile |
camReq.checksum |
LREAL | HMI to controller | Sum of all following values sent |
camReq.command |
DINT | HMI to controller | 0 idle, 1 store chunk, 2 interpolate |
camAck.received |
DINT | Controller to HMI | Pairs stored so far |
camAck.state |
DINT | Controller to HMI | 0 idle, 1 busy, 2 done, -1 error |
camAck.errorId |
DINT | Controller to HMI | Return value of the last cam system call |
There is no atomicity across HMI tag writes, so order matters. Write the payload first, then the counts, then the command word last, and clear the command only after the acknowledgement changes. One array write of one chunk costs one job on the connection; the same data as scalar tags would cost one job each, which is why the buffer is an array and not forty separate fields.
Sending the table in chunks #
- Reset: write
camReq.totalPoints, setcamReq.commandto 0, and wait untilcamAck.receivedreads 0 andcamAck.statereads 0. - Fill
camReq.bufXandcamReq.bufYwith one chunk and writecamReq.pointCount. Begin with chunks of 20 pairs; increase the size only while the acknowledgement round trip stays deterministic. - Write
camReq.command= 1 as the last write of the chunk. - Poll
camAck.stateuntil it reads 2, then readcamAck.receivedand confirm it advanced by exactlycamReq.pointCount. - Clear
camReq.commandback to 0 and repeat from step 2 until every pair is in. - Write
camReq.checksum, thencamReq.command= 2 to trigger validation and interpolation in the controller. - Gate activation on
camAck.state= 2 withcamAck.errorId= 0, and give the poll loop a timeout: if the state does not change within a fixed number of cycles, abort and mark the buffer invalid.
Before any curve work, prove the path: with camReq.command at 0, read camAck.state on the panel and expect 0. Then write a known value to a scratch DINT from an I/O field and read it back in the engineering tool's symbol view. That confirms symbolic access in both directions.
Working a 40-pair table in chunks of 20 pairs #
The inputs, all illustrative for a modest profile: a table of 40 x/y pairs; a chunk size of 20 pairs, the value step 2 starts from; the command and acknowledgement words from the table above; and a cam technology object whose configured maximum interpolation points is at least 40, read from the object configuration in the engineering tool.
The rule in words: chunks equal the table length divided by the chunk size, rounded up; each chunk costs one array write, one command write and one done poll; the whole transfer ends with one interpolate command.
The arithmetic: 40 pairs / 20 pairs each = 2 chunks. Chunk handshakes: 2. Interpolate commands: 1. Total command/acknowledge cycles: 2 + 1 = 3. Array writes: 2, replacing what would otherwise be 40 scalar tag writes. The camAck.received counter must read 40 at the end, and the checksum computed in the controller must equal camReq.checksum before interpolation starts.
The result: the complete table moves in 3 handshake cycles carried by 2 array writes. The decision: keep each chunk near 20 pairs, and if the done poll ever times out, halve the chunk to 10 pairs before changing anything else. If a planned profile exceeds the configured maximum interpolation points, the interpolate call fails no matter how clean the transfer looked, so trim the table or raise the configured maximum first, then resend.
Validate and activate in the controller #
Validate in the controller, never in the panel script. The leading values must increase strictly, because a duplicate or reversal makes the interpolation call fail and leaves the cam undefined. The point count must fit the configured maximum. The following values must lie inside the follower axis's software limit switches, or the axis faults on activation instead of on interpolation. Compare the controller-computed checksum against the value the HMI sent, and on a mismatch reject the table.
After interpolation succeeds, switch to the new curve at a defined master position. Never let activation fall through on an unvalidated buffer: a follower handed a wrong following value can drive into the mechanics at full speed. How crisply the follower then tracks the new curve depends on its own position loop tuning, and the same curve can look tight on one axis and lagging on the next for exactly that reason — see how axis loop tuning changes the follow behavior in KV factor range explained by axis loop tuning differences.
Where the operator curve comes from #
An I/O field matrix bound to array elements is practical up to roughly twenty points. For bigger tables, recipes fit the job: one data record is one cam profile, the recipe view gives the operator an editable grid, and export and import move records to and from a CSV file on the runtime PC. If the recipe area pointer for synchronized transfer is not available on this connection, configure the recipe without synchronization and drive the handshake yourself with the command and acknowledgement words above. The transfer of records to and from the PC side is covered in editing WinCC flexible recipes from a PC without the engineering tool.
For curves produced outside the panel entirely, read the file in a runtime script. The example below is illustrative; it declares its own variables and runs on the PC runtime, where the file system object and array addressing of tags must be confirmed against your runtime's script reference:
Dim fso, ts, parts, i, n
i = 0
n = 0
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile("D:\cams\profile_1.csv", 1)
Do While Not ts.AtEndOfStream And i < 20
parts = Split(ts.ReadLine, ";")
SmartTags("camReq_bufX")(i) = CDbl(parts(0))
SmartTags("camReq_bufY")(i) = CDbl(parts(1))
i = i + 1
n = n + 1
If i = 20 Then
SmartTags("camReq_pointCount") = n
SmartTags("camReq_command") = 1 ' payload first, command word last
' poll camAck.state here or in a cyclic task; never trust line order
i = 0
End If
Loop
Assigning a tag from a script queues a write job, and the next script line executes before the controller holds the value. That is precisely why the command word goes last and the script polls the acknowledgement instead of trusting statement order — the same ordering trap that makes an HMI screen freeze until a script finishes when a script blocks on a value that has not arrived (see why an HMI screen freezes until a script finishes).
Show the result and catch the errors #
A trend view is the right tool to display the cam output against the master position, but it is display only: nothing flows from the drawn curve back into tags. For diagnostics, route camAck.errorId into a message view so a failed interpolation call is visible at the panel instead of only in the controller log, and if technology alarms never appear on the panel at all, check the alarm mapping described in why SIMOTION technology alarms stay missing on a TIA HMI.
The decision, case by case: for a profile the operator tweaks on the machine, build the recipe or I/O field path and send 20 pairs per chunk with the handshake above; for free-form curves imported from a measurement or a curve generator, store the CSV on the runtime PC and let the script read and chunk it; for anything describable by a handful of numbers such as start angle, rise angle, stroke and dwell width, transfer only those numbers and build the table in ST, which removes the chunked transfer entirely and keeps all validation in the controller.
Questions asked
Can the operator change the cam while the axis is following?
Yes. The transfer fills buffer memory, not the running cam, so the active profile stays in effect until the interpolate and activate handshake completes. Switch to the new curve at a defined master position and only after the acknowledgement reads done with no error, so the follower never inherits an unvalidated table.
Why does the interpolate command fail after a clean transfer?
The two usual causes are leading values that are not strictly increasing and a table longer than the maximum interpolation points configured in the cam technology object. Sort the leading values, remove duplicates, then either trim the table or raise the configured maximum in the engineering tool, resend, and run the interpolate command again.
Can a trend object on the panel create the curve?
No. A trend view only samples tags and draws them; nothing flows from the drawn curve back into tag values. Build the curve with I/O fields, a recipe record, or a runtime script that reads a CSV file, and use the trend only to display the result against the master position.


