Programming 32 Axes with Xinjie PLC (C Language Version) – Essential Guide

System Learning

Life is like a marathon; sometimes you need to pause and take a break to go further.

Recently, there have been many industrial control PLC projects, so the upcoming content will mostly focus on industrial control PLC topics. All programming knowledge is provided by project team member “Tang Lu Lu” and organized and explained by Xiao Yu. Please feel free to point out any shortcomings.

First, let’s look at the effect.

About Axis Control

For axis control, I still used FB blocks to write this program, but I drove it using C language.About Xinjie PLC version:Programming 32 Axes with Xinjie PLC (C Language Version) - Essential Guide

About the Software

Programming 32 Axes with Xinjie PLC (C Language Version) - Essential Guide

Program Section

For the program section, you can refer to this article on how to write FB. The download link is in the article.Writing the 32-axis program for Xinjie PLC-EtherCAT communication

Click to jump to it.

When driving with C language, we need to instantiate the FB.

A global variable table can be established.

Programming 32 Axes with Xinjie PLC (C Language Version) - Essential Guide

Program Introduction

The programs needed first includeFB function blocksProgramming 32 Axes with Xinjie PLC (C Language Version) - Essential GuidePosition judgment FC for the axisProgramming 32 Axes with Xinjie PLC (C Language Version) - Essential GuideSimple version division operation (not used here) FCProgramming 32 Axes with Xinjie PLC (C Language Version) - Essential Guide64-bit to 32-bit data type FCProgramming 32 Axes with Xinjie PLC (C Language Version) - Essential GuideMulti-bit operation FCProgramming 32 Axes with Xinjie PLC (C Language Version) - Essential GuideRising edge FB blockProgramming 32 Axes with Xinjie PLC (C Language Version) - Essential GuideFalling edge FB blockProgramming 32 Axes with Xinjie PLC (C Language Version) - Essential Guide

Axis control C language section

Programming 32 Axes with Xinjie PLC (C Language Version) - Essential Guide

Various variable tables

Programming 32 Axes with Xinjie PLC (C Language Version) - Essential Guide

C Language Program Introduction

Define pointers for 32 axes as a prerequisite; this step is to determine which axis I need to drive.When I input AXIS[0], I am driving axis 0 output. And so on.Programming 32 Axes with Xinjie PLC (C Language Version) - Essential Guide

Enable Section

Here, I unified the enable conditions for all axes to the M200 register as a master switch.

The parameter BMC_A_Power_BODY indicates that I instantiated the enable FB block.

Programming 32 Axes with Xinjie PLC (C Language Version) - Essential Guide

Specific parameters can be viewed here.

Programming 32 Axes with Xinjie PLC (C Language Version) - Essential Guide

Display Position Speed Torque

I designed the touch screen to give the variable h_statusDat a value of 0, 1, 2 to display the data on the touch screen.

Programming 32 Axes with Xinjie PLC (C Language Version) - Essential GuideProgramming 32 Axes with Xinjie PLC (C Language Version) - Essential Guide

Position range judgment of 5mm

This directly adjusts the position judgment FC block and gives the corresponding axis output.

Programming 32 Axes with Xinjie PLC (C Language Version) - Essential Guide

Soft Limit

The soft limit here directly uses Xinjie’s registers starting from SFD8084 and SFD8068, with each axis increasing by 300 addresses corresponding to the soft limit of that axis.

Programming 32 Axes with Xinjie PLC (C Language Version) - Essential Guide

Model Number Management

I used h_number as the display number, with 1~40 for single model output and 101~110 for loop mode.

To avoid affecting the settings, I used a rising edge to clear the corresponding number during switching.

Programming 32 Axes with Xinjie PLC (C Language Version) - Essential GuideProgramming 32 Axes with Xinjie PLC (C Language Version) - Essential Guide

Manual Mode

The manual mode can only perform jog control and model writing. Set the origin.

Programming 32 Axes with Xinjie PLC (C Language Version) - Essential GuideProgramming 32 Axes with Xinjie PLC (C Language Version) - Essential GuideProgramming 32 Axes with Xinjie PLC (C Language Version) - Essential Guide

Jogging

For jogging, I used a variable h_Axis_jogNumber, which can only be activated by the selected axis on the touch screen. Rising edge starts, falling edge stops, and both rising and falling edges are given to JOG_R_TRIG, and then output.

JOG_R_TRIG[i].IN1 = JOG_F[i].Val || JOG_B[i].Val; // Input for forward or reverse rotation

Stopping is simply done using the stop FB block.

Programming 32 Axes with Xinjie PLC (C Language Version) - Essential GuideProgramming 32 Axes with Xinjie PLC (C Language Version) - Essential Guide

Model Saving

For model saving, I used a structure for data storage,h_number is the selected number, and the data from the touch screen is cyclically saved to the PLC.

Here,h_showPOT[i] is the 32 data displayed on the touch screen, and clicking saveh_ZXSave.Val saves the data into the structure I set up.

Model Reading

It is the rising edge I just mentioned in the number setting, which generates a rising edge signal when switching numbers, and then reads the new data.

Programming 32 Axes with Xinjie PLC (C Language Version) - Essential GuideProgramming 32 Axes with Xinjie PLC (C Language Version) - Essential Guide

Loop Saving

Loop saving is similar to number saving, just that the structure has more data.

However, I only have 12 loops for 12 cycles.

Programming 32 Axes with Xinjie PLC (C Language Version) - Essential Guide

Automatic Running Mode

The automatic running mode is divided into two types: one is when I select the number from 1 to 41 for single number startup, and the other is when the number is from 101 to 110 for loop mode.

The program has annotations, so I won’t elaborate further.

Programming 32 Axes with Xinjie PLC (C Language Version) - Essential GuideProgramming 32 Axes with Xinjie PLC (C Language Version) - Essential Guide

Loop Mode

Here, I used a while loop to read the required models sequentially. The loop number is saved directly as the single number startup number. Finally, I added a break in the while loop to ensure it only enters once.

Programming 32 Axes with Xinjie PLC (C Language Version) - Essential GuideProgramming 32 Axes with Xinjie PLC (C Language Version) - Essential Guide

Then, I check whether the conditions are met; if they are, I enter the while loop again.

Programming 32 Axes with Xinjie PLC (C Language Version) - Essential Guide

Reset and Stop

One is to clear various conditions in the program, and the other is to clear the servo alarms.

Programming 32 Axes with Xinjie PLC (C Language Version) - Essential GuideProgramming 32 Axes with Xinjie PLC (C Language Version) - Essential Guide

That’s all for this issue; I hope it helps you.

If you like it, please give a thumbs up and share to support more valuable content.

Teaching a man to fish is better than giving him a fish.

Programming 32 Axes with Xinjie PLC (C Language Version) - Essential Guide

Leave a Comment