Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Example programs
Using the example programs
This document contains sample applications of our products for certain areas of application.
The application notes provided here are based on typical features of our products and only
serve as examples. The notes contained in this document explicitly do not refer to specific
applications. The customer is therefore responsible for assessing and deciding whether the
product is suitable for a particular application. We accept no responsibility for the
completeness and correctness of the source code contained in this document. We reserve
the right to modify the content of this document at any time and accept no responsibility for
errors and missing information.
Note
The program presented below serves as an initial introduction to the options for evaluating
the data from a mains monitoring terminal. The user is free to change the program to suit
his ideas or to use only part of the code.
Table of contents
Example 1: Diagnosis and
evaluation of input data
- Commissioning of the
example program
Adaptation of the PLC
to the selected
oversampling factor
Adaptation of the
calculation of voltage and
current from the raw data
- Description of the
function of the example
program
Visualization
Selection of the size of
the FIFO buffer
Performance of the
calculations
- Starting the example
program
Procedure for starting
the program
for all active tasks the exceeding counter should not increment and an even utilization
should be displayed
you should decrease the buffer size, if necessary, advice regarding this is given below
if the following sync errors are displayed in the ADS logger window
or in the DiagMessages
the frames received by the EL3773 are corrupt . In this case you should check the
notes above.
the synchronization can be essentially impeded, if such effects occur in the start-up
phase. It is also possible, that the EL3773 does not change to OP state in this case.
Cycle time and oversampling freely configurable, presetting: 5 ms cycle time, 20-fold oversampling
WC, State, EtherCAT Master DevState, WcState, FrmState and status of the channels are cyclically
checked
The data from each cycle are placed in a FIFO buffer so that, for example, the evaluation can take place at a
higher level. The size of the FIFO buffer is freely configurable
Apparent, active and reactive power for each channel and in total
The following list shows an overview of the calculation of the values. More details in the item "Performance of the
calculations"
The calculations can be switched on and off for each individual channel
on the basis of the supplied time stamp of the next sample, all other samples are provided with 64 bit DC
time stamps; these are necessary for determining the frequency
default values are passed on in case of invalid input data; the error which occurred is displayed in the
visualization
Connection diagram:
The current is measured via three current transformers and the connections IL1, IL2, IL3 and IN (star point of
the current transformers).
The program serves as an initial introduction to the options for evaluating the data from a mains monitoring terminal.
The user is free to change the program to suit his ideas or to use only part of the code.
CPU utilization when using the program
Note
The CPU utilization when using the program strongly depends on the selected cycle time
and the selected size of the FIFO data buffer. The results of internal company tests have
shown that CPU utilization is approximately anti-proportional to the cycle time (i.e. the faster
the cycle time, the greater the CPU utilization) and proportional to the size of the FIFO data
buffer. The default settings of a 5 ms cycle time and a FIFO size of 800 places resulted in a
CPU utilization of about 35% with the following hardware:
1024MB DDR3-RAM
The selected oversampling factor had hardly any effect on the CPU utilization in the tests
Use of the program with the oversampling factor 1
Note
If the operating mode DC Oversampling 1 is selected in the System Manager, then the
PDO assignment 0x1A60 must be activated in the Process Data tab for the calculation of
the StartTimeNextLatch. After that the PDO must be linked with the corresponding variable
(default:MAIN.fbEL3773.uliStartTimeNextLatch).
The constant global variable CnMaxOvs corresponds to the selected oversampling factor.
Furthermore, the size of the FIFO buffer must be specified (see description of the function of the example
program). The size is specified by the constant global variable CnSizeOfFIFOBuffer
The variable CnMaxRecordedValues specifies the number of values that are used for the floating average
calculation of the RMS values. The smallest possible value is 1
The global variable bValuesZeroWhenDataInvalid specifies whether the FIFO buffer is to be filled with zeros
in case of invalid data. In case of invalid data no more calculations take place for the channel concerned in
any case. Filling the FIFO buffer with zeros may make it easier to find the source of the error.
All necessary settings for the calculation of the respective voltage and current values are made in the MAIN.
The presets correspond to the standard settings of the EL 3773
iMaxRawValue specifies the raw value of the terminal at the maximum measuring voltage.
The three variables rTransformerFactor specify the transformation factors of the current
transformers for the respective current channels
Furthermore, offsets can be specified per channel. The inclusion of the offsets in the calculation of
the measured values takes place directly by means of adaptation of the respective raw value.
Fig. 2b: Border around the "Go to Errors" button if errors have occurred
Errors that have occurred are displayed on the second page of the visualization (see fig. 2c). In this case, for
example, the EtherCAT cable from the controller to the coupler was removed during operation.
Fig. 2c: Second page of the visualization of the EL3773 example program
Selection of the size of the FIFO buffer
The recorded samples are copied per cycle into a FIFO buffer in which the newest values are saved "at the front" and
the oldest values are discarded "at the rear". The size of the FIFO buffer can be specified at the beginning and should
be selected according to the oversampling factor, the cycle time and the connected frequency. Important for an
accurate evaluation of the connected voltages and currents is a sufficiently large memory of recorded values. If the
connected frequency is, for example, 50 Hz, then 4 values will be recorded per PLC cycle with an oversampling factor
of 20 and a cycle time of 5 ms. The period at a frequency of 50 Hz is 20 ms and with the selected settings an entire
period is sampled with 80 values. Hence, the size of the FIFO buffer should be an integral multiple of 80, for example
800.
The following illustration provides an overview of the principle of operation of the data buffer:
The respective lower and upper limits for the summation are specified by the size of the FIFO buffer. The RMS values
are calculated by means of a sliding calculation of the entire size of the FIFO buffer in each cycle.
The result of the calculation is written in turn to a FIFO buffer, which is used to calculate the value displayed in the
visualization by means of a sliding calculation:
The range for the summation is specified by the user via the global variable CnMaxRecordedValues.
Note
The frequency is calculated by determining the zero point of the zero crossing from positive
to negative. This time is constantly determined and compared with the previous zero
crossing.
The frequency is calculated from the time difference. The method used for frequency
calculation serves only as a starting point for the determination of a possible algorithm.
It is up to the user to check the practical suitability of the method for a certain application.
Practical tests have shown that the frequency calculation of a very noisy signal with the
method used will not supply any reliable values. However, the calculation of the frequency
of the 50 Hz mains voltage worked reliably in the tests performed.
The same applies to the determination of the sign of the reactive power Q, because this is
determined by comparing the times of the zero crossings of the voltage and current.
The application examples have been tested with a test configuration and are described accordingly. The program
serves as an initial introduction to the options for evaluating the data from a mains monitoring terminal. The user is
free to change the program to suit his ideas or to use only part of the code.
The following hardware and software was used for the test configuration:
TwinCAT Master PC with Windows XP Professional SP 3 as operating system, TwinCAT version 2.11 (Build
2230) and Intel PCI Ethernet adapter
After clicking the Download button, save the zip file locally on your hard disk, and unzip the *.TSM
(configuration) and the *.PRO (PLC program) files into a temporary working folder
Run the *.TSM file and the *.PRO file; the TwinCAT System Manager and TwinCAT PLC will open
Connect the hardware and connect the Ethernet adapter of your PC to the EtherCAT coupler (further
information on this can be found in the corresponding coupler manuals)
Select the local Ethernet adapter (with real-time driver, if one) under System configuration, I/O configuration,
I/O devices, device (EtherCAT); on the "Adapter" tab, "Search..." box, select the appropriate adapter and
confirm (see Fig. 3a + 3b)
In TwinCAT PLC, under the "Project" menu, select "Rebuild all" to compile the project (Fig. 6)
In TwinCAT PLC: log in with the "F11" button, confirm loading the program (Fig. 7), run the program with the
"F5" button