6 PROGRAMMING
MELSEC-Q
6 PROGRAMMING
This chapter describes the programs of the A/D converter module.
When applying any of the program examples introduced in this chapter to the actual system, verify the applicability and confirm that no problems will occur in the system control.
6.1 For Use in Normal System Configuration
System configuration used in the program explanation
(1) System configuration
6
X/Y0 to
X10 to
Y20 to
X/YF X1F Y2F
Perform the following intelligent function module switch settings in advance.
• Switch 1 0030
H
(CH1: 4 to 20mA, CH2: 0 to 5V, CH3: -10 to 10V)
• Switch 2 Empty
• Switch 3 Empty
• Switch 4 0000
H
(Normal mode (A/D conversion processing))
• Switch 5 0000
H
(0: Fixed)
(2) Program conditions
This program reads the digital output values that have been A/D converted using
CH 1 to CH3 of the Q64AD. CH1 performs sampling processing, CH2 performs averaging processing every 50 times, and CH3 performs averaging processing every 1000 ms. An error code appears in BCD format if a write error occurs.
(a) Contents of initial setting
• A/D conversion enable channel
........................................CH1 to CH3
• Channel performing averaging processing using number of times
........................................The average number of times set for CH2 is 50.
• Channel performing averaging processing using time
........................................The average time set for CH3 is 1000 ms
(b) Devices used by the user
• Error reset signal ................................................................ X10
• Input signal for digital output value read command ........... X11
• Error code display (3-digit BCD) ........................................ Y20 to Y2B
• CH1 digital output value ..................................................... D11
• CH2 digital output value ..................................................... D12
• CH3 digital output value ..................................................... D13
• Error code ......................................................................... D14
6 - 1 6 - 1
6 PROGRAMMING
MELSEC-Q
6.1.1 Programming example using the utility package
(1) Operating the utility package
(a) Initial setting (see Section 5.4)
CH1, CH2, CH3 A/D conversion enable/disable setting ...."Enable"
CH1 Sampling process/averaging process setting ............"Sampling"
CH2 Sampling process/averaging process setting ............"Averaging"
CH2 Time/number of times specifying................................"Number of times"
CH2 Average time/average number of times setting ........."50"
CH3 Sampling process/averaging process setting ............" Averaging"
CH3 Time/number of times specifying................................"Time (ms)"
CH3 Average time/average number of times setting ........."1000"
(b) Auto refresh setting (see Section 5.5)
CH1 Digital output value................."D11"
CH2 Digital output value................."D12"
CH3 Digital output value................."D13"
Error code ......................................."D14"
6
6 - 2 6 - 2
6 PROGRAMMING
MELSEC-Q
(c) Writing the intelligent function module parameters (see Section
5.3.3)
Write the intelligent function module parameters to the CPU module.
This operation is performed using the parameter setting module selection screen.
(2) Programming example
Digital output value read processing
Read digital values
Module
READY
A/D conversion completed flag operating condition setting request
CH1 Digital output
CH2 Digital output
Transfer digital output values D11 to D13 read using auto refresh to
D101 to D103 after A/D conversion is completed.
CH3 Digital output
Error code display and reset processing
Error reset signal
Error flag
Error code
Output the error code to Y20 to
Y2B by BCD code.
Error reset request
Error flag
Error clear request
Clear the error code.
Error clear request
6 - 3 6 - 3
6 PROGRAMMING
MELSEC-Q
6.1.2 Programming example without using the utility package
(1) Programming example using the FROM/TO commands
Set the A/D conversion enabled channel (initial setting)
CH1 to CH3 are A/D conversion enabled
Module
READY
Set the average number of times for CH2 to 50 times
Set the average time for CH3 to
1000 ms
Specify averaging processing
Operating condition setting request
Set Y9 (operating condition setting request) from ON to OFF and enable the initial setting
Operating condition setting request
Operating condition setting request
Operating condition setting completed
Digital output value read processing
Read digital values
Module
READY
A/D conversion completed flag
Operating condition setting request
CH1
Digital output
CH2
Digital output
Read digital output values for
CH1 to 3
CH3
Digital output
Error code display and reset processing
Error reset signal
Error flag
Error code
Output the error code to
Y20 to Y2B by BCD code.
Error code
Error clear request
Clear the error code.
Error clear request
Error clear request
Error flag
6 - 4 6 - 4
6 PROGRAMMING
MELSEC-Q
(2) Programming example using the intelligent function module device
(U \G )
Set the A/D conversion enabled channel (initial setting)
CH1 to CH3 are A/D conversion enabled
Module
READY
Set the average number of times for CH2 to 50 times
Set the average time for CH3 to 1000 ms
Specify averaging processing
Operating condition setting request
Set Y9 (operating condition setting request) from ON to OFF and enable the initial setting
Operating condition setting request
Operating condition setting request
Operating condition setting completed
Digital output value read processing
Read digital values
Module
READY
A/D conversion completed flag
Operating condition setting request
CH1
Digital output
Read digital output values for CH1 to 3
CH2
Digital output
CH3
Digital output
Error code display and reset processing
Error reset signal
Error flag
Error code
Output the error code to
Y20 to Y2B by BCD code
Error clear request
Error flag
Error clear request
Clear the error code
Error clear request
6 - 5 6 - 5
6 PROGRAMMING
MELSEC-Q
6.2 For Use in Remote I/O Network
System configuration used in the program explanation
(1) System configuration
Remote master station (Network No. 1) Remote I/O station (Station No. 1)
Power supply module
Q n
C
P
U
Q
J
7
1
L
P
2
1
Q
X
1
0
Q
Y
1
0
Power supply module
L
P
2
5
Q
J
7
1
Q
X
1
0
Q
Y
1
0
Q
6
4
A
D
X/Y100 to
X/Y10F
X/Y110 to
X/Y11F
X/Y120 to
X/Y12F
Perform the following intelligent function module switch settings in advance.
• Switch 1 0030
H
(CH1: 4 to 20mA, CH2: 0 to 5V, CH3: -10 to 10V)
• Switch 2 Empty
• Switch 3 Empty
• Switch 4 0000
H
(Normal mode (A/D conversion processing))
• Switch 5 0000
H
(0: Fixed)
(2) Program conditions
In this program, the digital output values that have been A/D converted using
CH1 to CH3 of the Q64AD are read by the CPU of the remote master station.
CH1 performs sampling processing, CH2 performs averaging processing every
50 times, and CH3 performs averaging processing every 1000ms. An error code appears in BCD format if a write error occurs.
(a) Initial settings
• A/D conversion enable channel.............CH1 to CH3
• Count-based averaging processing channel ..............Average count setting of CH2
: 50 times
• Channel performing averaging processing using time ..........Average time setting of CH3
: 1000ms
(b) Devices used by the user
• Initial setting request signal .....................................X20
• Digital output value read command input signal .....X21
• Error reset signal......................................................X23
• Error code display (BCD 3 digits) ............................Y30 to Y3B
• CH1 digital output value...........................................D11 (W11)
• CH2 digital output value...........................................D12 (W12)
• CH3 digital output value...........................................D13 (W13)
• Error code.................................................................D14 (W14)
POINT
For details on the MELSECNET/H remote I/O network, refer to the Q
Corresponding MELSECNET/H Network System Reference Manual (Remote I/O
Network).
6 - 6 6 - 6
6 PROGRAMMING
MELSEC-Q
6.2.1 Programming example using the utility package
(1) Operating GX Developer
(a) CPU parameter setting
• Network type
• Starting I/O No.
• Network No.
• Total stations
• Mode
• Network range assignment
: MNET/H (Remote master)
: 0000
H
: 1
: 1
: Online
:
• Refresh parameters :
6 - 7 6 - 7
6 PROGRAMMING
MELSEC-Q
(2) Operating the utility package
Operate the utility package on the remote I/O station side.
Set the following in the Intelligent function module parameter setting module select area.
• Start I/O No. : 20
• Module type : A/D Conversion Module
• Module model name : Q64AD
(a) Initial setting (see Section 5.4)
CH1, CH2, CH3 A/D conversion enable/disable setting ......"Enable"
CH1 Sampling process/averaging process setting .............."Sampling"
CH2 Sampling process/averaging process setting .............."Averaging"
CH2 Time/number of times specifying.................................."Number of times"
CH2 Average time/average number of times setting ..........."50"
CH3 Sampling process/averaging process setting .............." Averaging"
CH3 Time/number of times specifying.................................."Time (ms)"
CH3 Average time/average number of times setting ..........."1000"
6 - 8 6 - 8
6 PROGRAMMING
(b) Auto refresh setting (see Section 5.5)
CH1 Digital output value..................."W11"
CH2 Digital output value..................."W12"
CH3 Digital output value..................."W13"
Error code ........................................."W14"
MELSEC-Q
(c) Writing the intelligent function module parameters (see Section 5.3.3)
The intelligent function module parameters are written to the remote I/O station.
This operation is performed using the Intelligent function module parameter setting module select screen.
(3) Programming example
Digital output value read
Error code display and reset
Read the CH1 digital output value
Read the CH2 digital output value
Read the CH3 digital output value
Output the error code in BCD
Turn ON the error clear request (YF)
Turn OFF the error clear request (YF)
POINT
To write the intelligent function module parameters, set the target remote I/O station from [Online] - [Transfer setup] on GX Developer.
They can be written by:
• Directly connecting GX Developer to the remote I/O station.
• Connecting GX Developer to another device such as a CPU module and passing through the network.
6 - 9 6 - 9
6 PROGRAMMING
MELSEC-Q
6.2.2 Programming example without using the utility package
POINT
The dedicated instructions used for reading/writing the buffer memory of the intelligent function module on a remote I/O station (REMTO and REMFR) are the execution type for which several scans are needed. Therefore, transmissions of the execution results are not synchronized with the I/O signal operations. When reading a digital output value on an A/D converter module after changing the operating condition during operation, be sure to read the A/D conversion completed flag (buffer memory address 10) at the same time.
Also, for the case of changing the operating condition, insert an interlock to prevent the execution of the REMFR instruction.
(1) Operating GX Developer (CPU parameter setting)
• Network type
• Starting I/O No.
• Network No.
• Total stations
• Mode
• Network range assignment
: MNET/H (Remote master)
: 0000
H
: 1
: 1
: Online
:
• Refresh parameters :
6 - 10 6 - 10
6 PROGRAMMING
(2) Programming example
Remote I/O station operating status checking
MELSEC-Q
Master station baton pass status checking
Master station data link status checking
Remote I/O station baton pass status checking
Remote I/O station data link status checking
Remote I/O parameter communication status checking
Set the A/D conversion enabled channel (initial setting)
Master module status checking
A/D conversion enable/disable setting
CH2 Average time/average number of times
CH3 Average time/average number of times
Averaging processing setting
Write to buffer memory
Turn ON the operating condition setting request (Y9)
Turn OFF the operating condition setting request (Y9)
6 - 11 6 - 11
6 PROGRAMMING
Digital output value read processing
Error code display and reset processing
MELSEC-Q
Concurrently reads the A/D conversion completed flag and
CH1-to-CH3 digital output values.
Read the CH1 digital output value
Read the CH2 digital output value
Read the CH3 digital output value
Read the error code
Output the error code in BCD
Turn ON the error clear requset (YF)
Turn OFF the error clear requset (YF)
6 - 12 6 - 12