With this SoftMotion device it is possible to control a Stepper motor just with the GPIO-Pins of a Raspberry Pi and a motor driver via position and velocity. For projects with several motors you need to add more devices, as each device controls one motor.
The device is configurable, so it is possible to use different motors and to choose the GPIO-Pins free.
With this device you can use different Raspberry Pis, motor and motor driver models, as the wiring is similar. The maximal velocity of the motor depends on this three components.
The GPIO-Pins of the Raspi are connected to the Input pins of the motor driver and the motor to the Output pins of the driver. The supply voltage for the motor and the driver are connected to the driver. If the motor only requires 5V, it can be supplied by the 5V Output pin of the Raspi. Nevertheless, it is recommended to use an external voltage supply because the Raspi is not as stable as an external supply, especially when more than one motor are provided.
Take a close look that no wires are mixed up and everything is connected correctly. Otherwise the motor will not turn correctly!
You can add the device to your project the same way as other SoftMotion devices.
With a right click on the „SoftMotion General Axis Pool“ you open the menu „Add device“. The „SM_Drive_RaspiStepper“ is under „Softmotion drives“ and „position controled drives“, which you can add now by clicking „Add Device“.
With a double click on the device in the device tree the editor for the configuration opens. The motor specific parameters like number of motorincrements, the velocity unit or the maximal velocity can be set as in other SoftMotion devices.
Special to this one is that you have to set the GPIO-Pins, the motor is attached to in the parameters. You do not need another GPIO-device.
Besides the GPIOs you have to set the Motorpowertime. To preserve the coils, the motor is not under power the whole Taskcycle. The Parameter „MotorPowerTime“ defines the percentage part of the Cycletime, the motor is under power. If you want to power the motor the whole, you can set „MotorPowerTime“ equal to one.
You can also decide wether the motor runs in fullsteps or halfsteps. The default setting is fullstep, to run in halfsteps you have to set the boolean variable "xHalfStep" in the Prameters Scaling High.
To call up the motor in the project, a program must be added to the application as a "POU". There you create an instance of "SMC_StartupDrive" and assign this instance to the SoftMotion axis.
PROGRAM PLC_PRGVAR sud: SMC_StartupDrive;END_VAR -----Sud(Axis:=SM_Drive_RaspiStepper);
The motor can now get controlled like other SoftMotion devices with the SoftMotion-FBs
How it works
Every SoftMotion axis creates a own task, which runs in the background. This task calls the functionblock (FB) "StepperControl". In the FB the set GPIOs are declared as outputs, then the cycletime is calculated by the reciprocal of a frequency, which is defined by the set velocity and the ratio of the number of motor steps to the velocity unit.
The position is determined by the counter of tasks that were run through. For the next motorstep the modulo of the counter and the number 8 sets the next byte of the logicarray and sends it to the GPIOs.