Support/Service
Signal generators
Analog value processing
Signal generators
 

Function blocks for signal generation

On this page, you find several digital signal generators which can be used to create signals (ramps, sawtooth, triangle, sinus, etc.) for control purposes, for example for internal setpoint setting in programmed control circuits.

The quality of the generated periodic or non-periodic signals depends on the following causes: The constancy of the used time base and the resolution of the digital signal. Generally, the following applies: A higher resolution requires a higher number of discrete signal values and, the higher the resolution is, the more precise a signal shape can be reproduced. However, the number of discrete values again depends on the possible clock speed and the cycle duration. Here, the very important role of the used time base for the generator becomes apparent.

As clock generator for the signal generator, the cycle time of the PLC program can be used (or the defined task cycle time, in case of a cyclic task in the context of which the signal generator is executed). However, this interval is subjected to a certain jitter resulting from the CPU load and the influences of tasks with higher priority (as the case may be).
More exact results can be achieved by controlling the signal generator via the output of a timing element (timer or counter). Since timing elements are based on the constant processor system tick, they allow more precise signals to be generated. However, timing elements are executed asynchronous to the program cycle which results in a slight jitter for each sampled value.

This page describes various functions blocks for signal generation. In addition, the library that can be downloaded at the end of this page, contains some more signal generators.

   
 

Simple ramp generator: SRAMPE1

At its output 'out_real', SRAMPE1 delivers a linearly rising impulse (ramp), the maximum value of which can be limited using the input 'endwert_int'.

Used time base: program cycle time.
Programming language: Structured Text (double-click the FB symbol to open the code body).

 
 

Mode of operation: The local Integer variable 'int_wert' (wert = German for value) is incremented with each program cycle. Due to the following Modulo operation, 'int_wert' cannot become greater than the value of the Integer variable 'endwert_int'. Prior to applying the value at output 'out_real', a data type conversion Integer-to-Real is performed.

 
 

Ramp generator with control functionality Start/Halt/Stop: SRAMPE2

At its output 'out_real', SRAMPE2 delivers a linearly rising impulse (ramp), the maximum value of which can be limited using the input 'endwert_int'. The generator is controlled via the Boolean inputs 'start', 'halt' and 'stop'.

Used time base: program cycle time.
Programming language: Structured Text (double-click the FB symbol to open the code body).

 
 

Mode of operation: The ramp at output 'out_real' (data type REAL) starts with a rising edge (FALSE > TRUE) at the Boolean input 'start'. The generator signalizes activity by setting 'run' = TRUE. By setting input 'halt' to TRUE, the ramp is held unchanged until 'halt' is set back to FALSE. Then, the ramp continues beginning with the hold position. During the halt state ('halt' = TRUE), the activity indicator 'run' remains TRUE. The value TRUE at the Boolean input 'stop' stops the generator, resets the ramp value to 0 and 0.0 respectively and sets 'run' to FALSE.
Output 'run' shows TRUE as long as the block is executed. The actual "generator kernel" works identically as the kernel of block SRAMPE1, by incrementing the local Integer variable 'int_wert' in each program cycle, followed by a Modulo operation and an Integer-to-Real conversion before to applying the ramp value at the REAL output.

 
 

Sawtooth generator on counter base: FSAEGZA

FSAEGZA provides a sawtooth pulse with a slow slope and a fast fall-off at its outputs. At the Integer output 'out_int', the passed value range is 0 to 100, the value range at the REAL output 'out_real' is 0.0 to 100.0. The generator is enabled by applying TRUE to input 'lauf'.

Used time base: Counter.
Programming language: Function Block Diagram FBD (double-click the FB symbol to open the code body).

 
 

Mode of operation: The generator kernel (network 4 in the figure) is realized by the up/down counter CTUD which periodically counts up and down between 0 and 100. This maximum value, which also determines the signal amplitude of the sawtooth, is defined via the counter input 'PV' and loaded into the counter via 'richtimpuls', generated in network 1. The period time of the produced sawtooth is defined by two times: 'ruecklauftakt' defines the duration of the falling edge and 'hochlauftakt' specifies the duration of the rising edge. Within the clock generator (network 2 in the figure), these two values are selected alternately as 'takt' (=clock) for the counting direction inputs CU (count up) and CD (count down). Switching the counting direction is done via the RS element in network 3 which toggles the signal 'richtung' (=direction) depending on the counter states 'ugw' and 'ogw'.

 
 

Triangle generator based on the program cycle time: TRIAG1

TRIAG1 outputs a triangular signal as Integer and Real value. The Boolean output 'square' provides a synchronous digital signal set to TRUE in case of a rising triangle slope. The amplitude of the triangle can be set via the Integer variable 'amplitude_int'. Using the input 'offset_int', the triangle can be moved on the amplitude axis.
Used time base: program cycle time.
Programming language: Structured Text (double-click the FB symbol to open the code body).

 
 

Mode of operation: After having created a defined start condition in the first IF statement, the generator kernel generates the wave by incrementing the variable 'm2'. By the following comparison of value 'm2' with the applied maximum amplitude value 'amplitude_int', the square wave is defined and the 'inkrement' value is defined positive or negative. The generator uses the program cycle time as time base. Therefore, the velocity of the increment and thus the period time of the triangular wave cannot be influenced by the user. Prior to applying the triangle to the outputs, the connected Integer offset is added and a conversion of the Integer value for the additional Real output is done.

 
 

Triangle generator on timer base: TRIAG2

TRIAG2 also generates a triangular wave at its both outputs. However, this generator allows to adjust the upper and lower maximum value of the amplitude ('upper_limit_int' and 'lower_limit_int'). The period time of the triangular wave is set at the TIME input 'period_time'.

Used time base: Timer function block 'TP'.
Programming language: Structured Text (double-click the FB symbol to open the code body).

 
 

Mode of operation: After having defined fixed start conditions in the first IF statement (triangle starts with rising edge), a further statement checks whether the applied values allow enabling of the generator (a minimum period time is required and the maximum amplitude must be greater than the minimum value). Then, the sample time for the clock generator is derived from the applied period time and the increment values for the generator kernel are calculated by the applied amplitude limit values. Based on the sample time, the clock generator provides the control pulse 'puls' which in turn is the time base used for incrementing in the generator kernel. Finally, the Integer output signal is created and the conversion for the additional Real output is done.

 
 

Sinus generator on timer base: SINGN1

SIGN1 generates a sinusoidal wave with adjustable amplitude and period time. The time at input 'tastzyklus_time' (=sample period) defines the resolution of the wave, i.e. it determines how often a new sine value is calculated.

Used time base: Timer function block 'TP'.
Programming language: Structured Text (double-click the FB symbol to open the code body).

 
 

Mode of operation: First, the number of sampling points 'schritte' (=steps) for each sine period is calculated from the applied 'period_time' and the desired resolution ('tastzyklus_time'). Later, this step value is used to calculate the number of angle steps. This conversion is necessary because the used trigonometric function SIN(winkel) (=angle) is only able to process values given in radian measures. Based on the applied 'tastzyklus_time' value, the clock generator provides the control pulse 'takt' (clock) which in turn is the time base used for incrementing in the generator kernel. Finally, the Real output signal is generated using the trigonometric SIN function.

 
 

Bit pattern generator for 4 bits: BITMG

The function blocks FBITMG1 and FBITMG2 provide at their outputs 'spur_a' to 'spur_d' a 4 channel bit pattern corresponding to the outputs of a 4-level dual counter. A further output provides the internal pulse. The generator kernel receives its clock from a timer element. Thus, the output rate of the pattern can be set via the TIME input 'period_time'.

Used time base: Timer function block 'TP'.
Programming language: Function Block Diagram FBD (double-click the FB symbol to open the code body).

 
 

 
Download of the function blocks
You can download a MULTIPROG FB library containing the blocks described here and some further blocks free of charge. Unzip the downloaded archive into the MULTIPROG library directory and insert the blocks as user library into a project.


[Download signal generator FBs   0,31 MBytes]

 

 
[Print version] [Send to friend] [Top]
Address
KW-Software GmbH
Lagesche Straße 32
32657 Lemgo (Germany)
+49 (0) 52 61 / 93 73-0
info@kw-software.com
You are here
Homepage
Support/Service
Tips & Tricks
FBs
Quick Links
Directions
Contact Person
Demo Software
Information Enquiry