10-77
10 Sample Programming
NJ/NX-series CPU Unit Motion Control Userās Manual (W507)
10-2 Basic Programming
Samples
10
10-2-16 Changing a Cam Data Variable and Saving the Cam Table
This sample uses the user program to change a cam data variable that was created on Cam Editor of
the Sysmac Studio. The displacements for phases of 0° to 180° are multiplied by 2 and the displace-
ments for phases of 181° to 360° are multiplied by 0.5.
If the changes to the cam data are completed, the motion control instruction MC_SaveCamTable is
used to save the cam data variable to non-volatile memory in the CPU Unit. When saving the data is
completed, the MC_CamIn (Start Cam Operation) instruction is executed to start cam motion.
Precautions for Correct UsePrecautions for Correct Use
⢠If the phases are not in ascending order, an error occurs when the MC_CamIn (Start Cam
Operation) instruction is executed. The order of the phases are not checked in this sample. To
check the order of the phases, execute the MC_SetCamTableProperty (Set Cam Table Prop-
erties) instruction.
⢠There is a limit to the number of times that you can write non-volatile memory in the CPU Unit.
Save cam table data only when necessary.
⢠If the power supply to the Controller is turned OFF before the data is saved with the MC_Save-
CamTable instruction, the cam data variable will revert to the contents from before it was
changed by the user program.
* The array elements ARRAY[0..N] are set with the Cam Editor in the Sysmac Studio. The range of the array is 0 to
360 in this sample.
10-2-16 Changing a Cam Data Variable and Saving the Cam Table
Main Variables Used in the Programming Samples
Variable name Data type Default Comment
MC_Axis000 _sAXIS_REF --- This is the Axis Variable for axis 0.
MC_Axis001 _sAXIS_REF --- This is the Axis Variable for axis 1.
CamProfile0 ARRAY[0..360] OF
_sMC_CAM_REF
--- This is the cam data variable.*
Pwr1_Status BOOL FALSE This variable is assigned to the Status output vari-
able from the PWR1 instance of the MC_Power
instruction. It is TRUE when the Servo is ON.
Pwr2_Status BOOL FALSE This variable is assigned to the Status output vari-
able from the PWR2 instance of the MC_Power
instruction. It is TRUE when the Servo is ON.
StartPg BOOL FALSE When StartPg is TRUE, the Servo is turned ON if
EtherCAT process data communications are active
and normal.
WriteCamdata BOOL FALSE This variable is used to start changing the cam
data. It is changed to TRUE to start editing.
WriteDone BOOL FALSE This variable is used to indicate that the changes to
the cam data are completed. It is changed to TRUE
when the changes to the cam data are completed.
SaveCamtable BOOL FALSE This variable is used to execution the Save Cam
Table instruction.
_MC_COM.Status.
CamTableBusy
BOOL FALSE This system-defined variable is TRUE while cam
table data is being saved.
Sv_Cam_Ex BOOL FALSE This variable is used to execute the MC_SaveCam-
Table instruction.
Camin_Ex BOOL FALSE This variable is used to execute the MC_CamIn
(Start Cam) instruction. It is used in ST program-
ming.