Programming of the cam controller through the PLC
In order to ensure the function of the cam controller, the PLC program must enable the cam controller and individual output tracks. Errors must be monitored and reset if necessary. Optionally, cam parameters (such as switching positions) can also be modified through the PLC program. A PLC library is available for this purpose.
Click here to save the library
Definition of variables for the process image
Input and output variables of the same type are created in the program in order to make the process image of the cam controller available for the PLC program.
VAR_GLOBAL
(* Digital Cam Server Input Process Image - PLC --> DigitalCamServer *)
ReverseMode AT %Q* : UDINT;
Coupled AT %Q* : UDINT;
HPMPreset AT %Q* : UDINT;
HPMDifference AT %Q* : UDINT;
ResetIOErrors AT %Q* : UDINT;
ResetEncoderError AT %Q* : UDINT;
ResetShaftError AT %Q* : UDINT;
ResetHPMError AT %Q* : UDINT;
BrakeEnabled AT %Q* : DWORD;
PlcAndMask AT %Q* : DWORD;
PlcOrMask AT %Q* : DWORD;
(* Digital Cam Server Output Process Image - DigitalCamServer --> PLC *)
ActualHPM AT %I* : UDINT;
IOerrors AT %I* : UDINT;
EncoderError AT %I* : UDINT;
ShaftError AT %I* : UDINT;
HPMError AT %I* : UDINT;
CamInputs AT %I* : DWORD;
CamOutput AT %I* : DWORD;
END_VAR
The process image described here corresponds to a configuration with one output group, i.e. 32 digital outputs. If more than one output group (up to 10) is created, is the process image is extended, involving additional variables. In this case the variables BrakeEnabled, PlcAndMask, PlcOrMask and CamOutput apprehensive be created as an ARRAY.
Once the PLC program is compiled and imported into the TwinCAT System Manager, these variables can be linked with the associated process image variables of the digital cam controller. The PLC program then has access to the content of these variables.
Programming of the cam controller via the process image
To activate the cam controller, several steps are required within the PLC program as a minimum:
- The required set speed of the cam controller is entered in variable HPMpresest (rpm). This speed serves as the basis for the cam calculation and for monitoring functions and should match the actual speed of the cam encoder.
The unit of HPM Preset is [1/min] if the Use Encoder precision encoder parameter is set to FALSE. When high precision is enabled, the unit changes to [1/1000 min] - The maximum speed deviation is entered in variable HPMdifference (e.g. 1 rpm). This value is required for monitoring functions and for recalculating the cam switching points.
- Output tracks must be activated via variable PlcAndMask as soon as the cam encoder has reached its constant speed. In the simplest case the variable PlcAndMask is set to value 16#FFFFFFF in order to enable all 32 output tracks for the cam controller. (A configuration with more than one output group can have up to 10 PlcAndMask variables (ARRAY), through which up to 320 outputs can be activated.)
- If brake cams are used, the associated output tracks are activated by setting the associated bits of the BreakEnabled variables (like the PlcAndMask).
- As soon as the encoder has reached its constant set speed, the variable Coupled is set to 1, thus enabling monitoring of the cam controller.
PLC library TcDigitalCamServer.lib
The PLC library TcDigitalCamServer.lib contains function blocks for configuring the cam controller through the PLC.
Reading and writing of the encoder configuration
Encoder parameters can be read or written with an associated function block. In order to change individual parameter, such as the encoder offset, the encoder dataset should initially be read and written back after a value was changed. Writing cam data causes the recalculation of the digital cam.
The parameter data structure is defined in the library.
TYPE ST_DigitalCamEncoder :
STRUCT
EncoderID : UDINT; (* unique ID of the cam encoder *)
EncoderType : UDINT; (* type of the cam encoder *)
EncoderName : STRING(79);
EncoderRevDir : UDINT; (* encoder uses inverted counting direction when TRUE *)
EncoderBoxAddr : UDINT;
EncoderZeroOffset : UDINT; (* zero offset of the encoder position in steps of [1/1000 degrees] *)
EncoderMask : DWORD; (* encoder bit mask defines the maximum counter value passed to the control system *)
END_STRUCT
END_TYPE
Reading and writing of cam parameters
The parameter dataset for each cam can be read and written. Here too, the complete cam dataset should be read before changing a parameter, such as the switching position, and written back again after the change.
.
The resolution of the position parameters in the data structure below depends on the parameterized encoder resolution. If the Use Encoder Precision parameter in the encoder configuration is set, all position data is defined as [1/1000 degrees]; otherwise as [1 degrees].
The parameter data structure is defined in the library.
TYPE ST_DigitalCamStruct :
STRUCT
CamID : UDINT; (* unique cam ID from 1 to 2048 *)
CamType : UDINT; (* type E_DigitalCamType: 1=distance cam, 2=time cam, 3=brake cam *)
CamLine : UDINT; (* number of cam output 0 to 319 that is cam is active on *)
PresetTime : UDINT; (* preset time in steps of [1/10 ms] *)
Counter : UDINT; (* activation counter: 0=inactive, 1=every cycle, 2=every 2nd cycle, etc. *)
HysteresisInc : UDINT; (* not supported *)
StandardActive : UDINT; (* this cam is active when the standard cam table is activated by the PLC *)
ReverseActive : UDINT; (* this cam is active when the reverse cam table is activated by the PLC *)
DynamicEnabled : UDINT; (* preset time is used when TRUE *)
HysteresisEnabled : UDINT; (* not supported *)
StartPosition : UDINT; (* start position of the cam in steps of [1/1000 or 1 degrees] *)
EndPositionOrDuration : UDINT; (* end position of distance cams in steps of [1/1000 or 1 degrees] or duration of time cams in steps of [1 ms] *)
END_STRUCT
END_TYPE
The CamType can be assigned the following values:
TYPE E_DigitalCamType :
(
CAMTYPE_NONE, (* undefined cam type *)
CAMTYPE_DISTANCE,
CAMTYPE_TIME,
CAMTYPE_BREAK
);
END_TYPE
Creating and deleting cams
Cams are generally configured in the TwinCAT System Manager. The PLC program should then only change the cam parameterisation. In some cases it may be necessary to create new cams or delete cams through the PLC program. The parameter data structure used here matches the structure during reading and writing of the cam data.
Recalculation of the cam table
The digital cam controller converts all cam parameters within a cam table for fast output. This cam table is calculated for a certain, user-specified velocity and only calculated in the event of deviations from this velocity. Via the function block DCS_CalcCamData the user can specifically initiate recalculation of the cam table and therefore ensure the calculation for a certain velocity level.
Output signals of the function blocks
All function blocks described in this documentation are triggered by a rising edge at the Execute input. The Busy output changes to TRUE to indicate that the execution of the function is in progress. The process is completed when Busy changes back to FALSE. At the same time the Done output indicates that the function was completed successfully. Otherwise the Error output becomes TRUE to indicate an error with the associated error number in ErrorID. Busy, Done and Error are exclusive, only one of the signals can be TRUE at any one time.