Navigation:  Equipments (Devices) > PLC200 > Program > Motion - Stepper Motor >

MW_PlcSpeed

Previous pageReturn to chapter overviewNext page

Block for speed control with ramp generation and specified number of pulses.

 

wpshelp_common_fig_note

NOTE!

In firmware versions prior to 1.2.0 of the PLC200, the block did not work with axis control enabled and could not control the axis direction.

To facilitate stepper motor control, this block has been integrated into the axis control block set.

The main differences are:

Axis control must be enabled for the block to work.
The "NumberOfPulses" input has changed from DWORD to DINT to allow axis direction control.

 

Ladder Representation

 

MW_PlcSpeed_G0

 

Block Structure

 

Variable Type

Name

Data Type

Description

VAR_INPUT

EN/Execute

BOOL

Block enabling

AxisNumber

CONST

Selected axis

NumberOfPulses

DINT

Total number of pulses of the block execution

TargetFrequency

DWORD DINT

Final pulse frequency [Hz]

DeltaTime

DWORD

Step time until reaching the target frequency [ms]

DeltaFrequency

DWORD DINT

Frequency variation of each step [Hz]

VAR_OUTPUT

DONE

BOOL

Output enabling

Active

BOOL

Indicates that the block is active

Busy

BOOL

Indicates that another block is using the selected output

Error

BOOL

Indicates that an error occurred when calling the block

ErrorID

BYTE

Indicates the error generated

VAR

MW_PlcSpeed_INST_0

MW_PlcSpeed

Instance of access to block structure

 

Operation

 

This block, when it detects a rising edge on the EN input, starts generating pulses for the selected axis with a frequency starting from 0 Hz up to the desired frequency (targetFrequency) (between 0 and 300 kHz).

 

At each time step (deltaTime), the frequency is increased by deltaFrequency until reaching the desired frequency (targetFrequency).

 

The axis direction depends on the signal of the NumberOfPulses input.

 

 

The pulses are stopped when the total number of pulses (NumberOfPulses) has been generated.

 

As long as the number of generated pulses does not reach the Pulses value, the "Active" output remains at high level.

 

When EN is FALSE, DONE remains FALSE. The DONE output is activated when the block successfully completes execution, remaining TRUE until EN becomes FALSE.

 

To stop pulse generation during movement, use the MW_PlcStop1 block. In this case, the block considers the movement to be completed.

 

The minimum number of pulses that can be generated is two.

 

If this limitation is not observed, no pulse is generated.

 

The minimum number of pulses that can be generated per step is 2.

 

If this limitation is not respected, the frequency ramp will not be generated, meaning that upon enabling the block, the pulse frequency will directly start from the targetFrequency value.

 

The MW_PlcChangeSpeed ​​block can be used together to change the output frequency during the execution of this block. See the help for the MW_PlcChangeSpeed ​​block for more information.

 

wpshelp_common_fig_note

NOTE!

If other PWM blocks running use the same output, the one called first will have priority and the "Busy" output is set.

 

 The figure below shows the default operation of the block, without using the MW_PlcChangeSpeed block together.

 

 MW_PlcSpeed_example03

 

If there is any error in the execution, the Error output is enabled and ErrorID displays an error code according to the table below.

 

Code

Description

0

Executed successfully

1

Axis control not enabled

2

Invalid number of steps

3

Invalid ramp

4

Configuration error

 

wpshelp_common_fig_note

NOTE!

Stepper motor control must be enabled for the selected axis. Look at the user manual and parameter manual.

 

wpshelp_common_fig_note

NOTE!

After enabling axis control in the parameters, it is necessary to perform a new download of the program or restart the product.

 

Example in Ladder

 

MW_PlcSpeed_example01

In the example above, the "start" contact enables a PWM signal at output DO1 with an initial frequency of 0 Hz and duty cycle of 50%. The frequency will be increased by 2000 Hz every 100ms until it reaches 20000 Hz, that is, the total ramp time will be 1 second. In total executing the block, 100000 pulses will be sent to the output. Once the block has finished successfully, the DONE output is activated and COIL is activated.

 

 

MW_PlcSpeed_example02

In the example above, the start contact enables a PWM signal at output DO1 with an initial frequency equal to the targetFreq. The ramp will not be generated as it is not possible to generate 2 pulses at 10 Hz within the 100 ms step time. In total executing the block, 1000 pulses will be sent to the output. Once the block has finished successfully, the DONE output is activated and COIL is activated.

 

Example in ST

 

 The example below displays instructions for applying the functional example in ST language.

 

 

VAR

   start : BOOL := 0 ;

   nPulses : DWORD := 100000;

   targetFreq : DWORD := 20000;

   stepTime : DWORD := 100;

   stepFreq : DWORD := 2000;

   MW_PlcSpeed_INST_0 : FB_MW_PlcSpeed;

END_VAR

 

MW_PlcSpeed_INST_0.EN := start;

MW_PlcSpeed_INST_0(

  OutputNumber:=1,

   NumberOfPulses:=nPulses,

   TargetFrequency:=targetFreq,

   DeltaTime:=stepTime,

   DeltaFrequency:=stepFreq);

COIL := MW_PlcSpeed_INST_0.DONE;