MitsubishiFXSeriesPLCData Types and Array Types Explained
1. Introduction
TheMitsubishiFXSeriesPLCis a widely used programmable logic controller in the field of industrial automation. In its programming, the proper use of data types and arrays is crucial for the structure and efficiency of the program. This article will provide a detailed introduction to the basic and complex data types supported by theFXSeriesPLCand illustrate their application methods through specific examples.
2. Basic Data Types
TheMitsubishiFXSeriesPLCsupports various basic data types, each with specific data ranges and purposes.
|
Data Type |
Size |
Range |
Description |
|
Bit (Bit) |
1 bit |
0 or 1 |
Represents switch states, such asX, Y, M, S, etc. |
|
Byte (Byte) |
8 bits |
0 to 255 |
8 bit unsigned integer |
|
Word (Word) |
16 bits |
0 to 65535 |
16 bit unsigned integer, such asD registers |
|
Double Word (Double Word) |
32 bits |
0 to 4294967295 |
32 bit unsigned integer, composed of two consecutive words |
|
Integer (Integer) |
16 bits |
-32768 to 32767 |
16 bit signed integer |
|
Double Integer (Double Integer) |
32 bits |
-2147483648 to 2147483647 |
32 bit signed integer |
|
Float (Float) |
32 bits |
±1.18×10-38 to ±3.4×1038 |
IEEE 754 single-precision floating point |
1. Bit Array Example: Multi-Station Control
In an automated production line, it is often necessary to control the start and stop of multiple stations. Using a bit array can efficiently achieve this function.
// Define an array of start states for 8 stations M0 ~ M7: Start flags for stations 1~8 // Use bit array for batch control
MOV K2X000 D0 // ReadX0-X7‘s input status toD0
MOV D0 K2M0 // TransferD0‘s value toM0-M7, controlling the start of each station
In this example, the bit array achieves batch reading and control of multiple station states, improving programming efficiency.
2. Word Array Example: Temperature Data Collection
In a temperature monitoring system, it is necessary to collect data from multiple sensors and process it.
// Define an array to store data from 10 temperature sensors D100 ~ D109: Store temperature values from sensors 1~10
// Simulate reading temperature values and storing
LD M8000 // Run normally open contact
MOV K100 D100 // Temperature value from sensor 1
MOV K102 D101 // Temperature value from sensor 2
…
MOV K118 D109 // Temperature value from sensor 10
// Calculate average temperature
LD M8002 // Initial pulse
DDIV D200 K10 D210 // Calculate total and divide by10, result stored inD210
This example demonstrates how to use a word array to store data from multiple sensors and perform simple data processing.
3. Complex Data Types
TheMitsubishiFXSeriesPLCsupports some complex data types for handling more complex data structures.
1. Structure (Structure)
Structures allow combining different data types into a whole, making it easier to manage related data.
Example1: Motor Control Structure
When controlling multiple motors, a structure can be used to organize the relevant parameters and control states of each motor.
// Define motor control structure (simulated using multiple registers)
// Each motor occupies5 registers:
// D-Base address: Start flag (bit), running speed (word), running time (double word)
// Motor 1:D500-D504
D500: Control flag (bit0:Start/Stop, bit1:Forward/Reverse, bit2-15:Reserved) D501: Running speed (0-1000)
D502-D503: Running time (32 bit counter)
// Motor 2:D505-D509
// …
// Set motor 1 parameters
MOV H0001 D500 // Set start flag and forward
MOV K500 D501 // Set running speed to500
MOV K0 D502 // Clear running time low16 bits
MOV K0 D503 // Clear running time high16 bits
This example demonstrates how to use multiple registers to simulate a structure and organize motor control parameters.
Example2: Product Information Structure
On the production line, a structure can be used to store information for each product.
// Product information structure (occupies4 registers)
// D-Base address: ProductID(word), production date(word), quality status(bit), counter(word)
// Product 1:D600-D603
D600: ProductID
D601: Production date (Format:MMDD)
D602: Quality status (bit0:Qualified, bit1:Unqualified, Other bits:Reserved)
D603: Production quantity counter
// Set product information
MOV K1001 D600 // Set productID
MOV #1225 D601 // Set production date to12 month25 day
MOV H0001 D602 // Set quality status to qualified
INC D603 // Increment production counter by1
This example demonstrates how to use a structure to manage product information, improving data organization and readability.
2. Array (Array)
An array is a collection of elements of the same data type, which can be accessed by index.
Example1: Multi-Channel Data Collection Array
In a data collection system, an array can be used to store collected data from multiple channels.
// Define an array for data collection from 16 channels D700 ~ D715: Collected data from channels 1~16
// Use loop to process collected data
LD M8000 // Run normally open contact
MOV K0 Z0 // Clear index register
FOR K16 // Loop16 times
LD M8000 MOV D700Z0 D720 // Transfer current channel data to processing register
// Data processing logic can be added here
INC Z0 // Point to the next channel
NEXT // End of loop
This example demonstrates how to use an index register to implement loop processing of an array, improving code simplicity and reusability.
Example2: Recipe Data Array
In the production process, an array can be used to store recipe parameters for different products.
// Define recipe array:5 types of products, each with4 parameters
// D800-D819: Recipe data (5×4=20 registers)
// Product 1 recipe:D800-D803
// Product 2 recipe:D804-D807
// …
// Product 5 recipe:D816-D819
// Select current product recipe
LD X000 // Product selection signal1
MOVP K0 Z0 // Set offset to0
LD X001 // Product selection signal2
MOVP K4 Z0 // Set offset to4
LD X002 // Product selection signal3
MOVP K8 Z0 // Set offset to8
// Use current recipe parameters
MOV D800Z0 D500 // Parameter1 transferred to control register
MOV D801Z0 D501 // Parameter2 transferred to control register
MOV D802Z0 D502 // Parameter3 transferred to control register
MOV D803Z0 D503 //Parameter4 transferred to control register
This example demonstrates how to use an array to store recipe data and achieve quick switching of recipes through index registers.