User: jonas22, Location: Dresden
Asked on: Thursday, September 19, 2024 at 3:42 am EDT
Answered on: Thursday, March 6, 2025 at 2:38 am EST
Question: Hello,I have a small experience in programming PLC. I have a little problem with my project, becasue i have to control stepper motor through my PLC S7 1513.Driver stepper motor is CW5045.I can't use a technology object, becasue I have to buy expansion card. I would like to avoid it.Do you have any solution? Do you have any examples? I don't know how control direction.Is it possible control this without expansion card?Thanks you advance
Yes, it's absolutely possible to control a stepper motor with an S7-1513 PLC without using a technology object or a dedicated expansion card! You'll be using the PLC's digital outputs to generate the step and direction signals for your CW5045 driver. Here's a breakdown of how to do it, along with considerations and example code snippets.
Understanding the CW5045 Stepper Motor Driver Step (PUL or CLK)
Each pulse you send to this input advances the motor one step (or microstep, depending on the driver's configuration).
Direction (DIR or CW/CCW)
A logic level (high or low) on this input determines the direction of rotation.
Wiring1. PLC Digital Outputs
Choose two available digital outputs on your S7-1513 PLC. Let's assume you choose `Q0.0` for the Step signal and `Q0.1` for the Direction signal.
2.
CW5045 Connections
Connect `Q0.0` from the PLC to the `PUL` (or `CLK`) input of the CW5045 driver. Connect `Q0.1` from the PLC to the `DIR` (or `CW/CCW`) input of the CW5045 driver.
3.
Ground
Ensure you have a common ground connection between the PLC and the CW5045 driver. This is crucial for signal integrity.
PLC Program Logic (TIA Portal)
Here's the core logic you'll need to implement. This is a basic example and can be expanded upon for more complex control. I'll use Ladder Logic (LAD) for the examples.1. Direction Control
Create a boolean tag (e.g., `Motor_Direction`). `TRUE` for clockwise, `FALSE` for counter-clockwise. Assign this tag to the `Q0.1` output:ladder// Set DirectionNETWORKTITLE = "Set Motor Direction"A "Motor_Direction";= Q0.1;
2. Step Pulse Generation
This is the most important part. You need to generate a pulsed signal on `Q0.0` to trigger the stepper motor. You'll need to use a timer (e.g., TP - Pulse Timer) to create the pulses.ladder// Step Pulse GenerationNETWORKTITLE = "Generate Step Pulse"//Inputs:// - Start_Motor (BOOL): Enables the stepping process.// - Step_Frequency (REAL): Desired step frequency in Hz (e.g., 100.0 for 100 Hz).//Outputs:// - Q0.0: Step output// - Motor_Running (BOOL): Indicates motor is running.//Variables:// - Step_PulseTimer (TP): Pulse timer// - Calculated_PulseTime (TIME): Calculated time for the TP timer.//Calculate pulse time in milliseconds. This is done once at the start or whenever the frequency is changed.NETWORKTITLE = "Calculate Pulse Time"IF "Start_Motor" AND NOT "Motor_Running" THENL 1000.0; // 1000 ms/second/ "Step_Frequency"; // Divide to get the time per step in millisecondsRND; // Round to whole numberL DINT_TO_REAL(REAL_TO_DINT(ACCU1)); //Convert from DINT to REAL back to DINTTOD "Calculated_PulseTime";S "Motor_Running";END_IF;NETWORKTITLE = "Step Pulse Logic"A "Start_Motor"; //Enable MotorTONR "Step_PulseTimer"(IN := TRUE, PT := "Calculated_PulseTime", Q := , ET := );A "Step_PulseTimer".Q;= Q0.0; // Output to Step pinNETWORKTITLE = "Stop Motor"A NOT "Start_Motor";= R "Step_PulseTimer".IN;= R "Motor_Running";
Explanation of the Step Pulse Generation
`Start_Motor`
A boolean tag that enables the stepping process. When `TRUE`, the motor should start stepping. When `FALSE`, the motor should stop.
`Step_Frequency`
A real (floating point) tag specifying the desired step frequency in Hz. Higher frequencies result in faster motor speeds. Important: The maximum frequency depends on your motor, driver, and load. Start with a low frequency (e.g., 10 Hz) and gradually increase it.
`Step_PulseTimer`
A `TP` (Pulse Timer) function block. This timer generates a pulse of a specific duration.
`Calculated_PulseTime`
This is where the magic happens. The code calculates the time duration required for each pulse based on the desired `Step_Frequency`. The higher the frequency, the shorter the pulse duration. It essentially converts the frequency into the pulse width required by the `TP` timer. This value is calculated in milliseconds.
Logic
When `Start_Motor` is TRUE, the `Step_PulseTimer` is activated. The TP timer will pulse and then turn off. The `Q` output of the `Step_PulseTimer` is directly connected to the `Q0.0` output, which is the Step signal for the stepper motor driver. When `Start_Motor` is FALSE, the `Step_PulseTimer` is reset, stopping the pulse generation.
3. Configuration Considerations
Microstepping
The CW5045 supports microstepping. Configure the DIP switches on the driver to select the desired microstepping resolution. Higher microstepping leads to smoother motion but requires more pulses per revolution. Adjust the `Step_Frequency` accordingly.
Acceleration and Deceleration
This code example doesn't include acceleration and deceleration. If you start or stop the motor abruptly at a high frequency, you're likely to experience missed steps and/or motor stalling. You'll need to implement ramp-up and ramp-down profiles by gradually increasing and decreasing the `Step_Frequency` over time. This is more complex but essential for reliable operation, especially at higher speeds.
Frequency Limits
Experiment to find the maximum stable `Step_Frequency` for your setup. Go too high, and you'll lose steps.
PLC Scan Time
The PLC's scan time can influence the accuracy of your pulse generation, especially at high frequencies. Ensure your scan time is fast enough to accurately control the pulse width. You might need to optimize your PLC program to reduce scan time if you encounter issues.
Driver Configuration
Consult the CW5045 driver's manual for proper configuration of voltage, current limiting, and microstepping. Incorrect settings can damage the motor or driver.
Complete Example (Ladder Logic)
Here's a more complete example incorporating basic start/stop control and direction:
ladder// Global Tags // Start_Motor (BOOL) : Start/Stop Motor// Motor_Direction (BOOL) : TRUE = Clockwise, FALSE = Counter-Clockwise// Step_Frequency (REAL) : Desired Step Frequency in Hz// Motor_Running (BOOL) : Indicates motor is running// Static Tags // Step_PulseTimer (TP) : Pulse timer// Calculated_PulseTime (TIME) : calculated pulse time// Set DirectionNETWORKTITLE = "Set Motor Direction"A "Motor_Direction";= Q0.1;//Calculate pulse time in milliseconds. This is done once at the start or whenever the frequency is changed.NETWORKTITLE = "Calculate Pulse Time"IF "Start_Motor" AND NOT "Motor_Running" THENL 1000.0; // 1000 ms/second/ "Step_Frequency"; // Divide to get the time per step in millisecondsRND; // Round to whole numberL DINT_TO_REAL(REAL_TO_DINT(ACCU1)); //Convert from DINT to REAL back to DINTTOD "Calculated_PulseTime";S "Motor_Running";END_IF;// Step Pulse GenerationNETWORKTITLE = "Generate Step Pulse"A "Start_Motor"; //Enable MotorTONR "Step_PulseTimer"(IN := TRUE, PT := "Calculated_PulseTime", Q := , ET := );A "Step_PulseTimer".Q;= Q0.0; // Output to Step pinNETWORKTITLE = "Stop Motor"A NOT "Start_Motor";= R "Step_PulseTimer".IN;= R "Motor_Running";Key Considerations Before Implementation