The problem was described in owen.ru forum.
Here’s the problem:
- The motor shaft of the material transport is connected to the encoder that has resolution of 500 pulses / rev
- The maximum engine speed is 3000 rev / min (typically about 2000 / min)
- The time to supply the desired amount of material is near 0.4..0.6 seconds
- The motor has low inertia, so the stop occurs almost instantly.
The task is to count the required number of pulses and stop the motor.
As described above the counter should be reliable up to 30 kHz.
If you have Hardella IDE opened, you can either open
code sample in the IDE, or you can create a new project with this code (
Let’s create a enumeration for the system state (in order to do that you need to right-click, then select
Then we need to create a ST logic:
It is more or less clear: it performs one or the another action depending on the current state.
If the movement is complete (that is current state is
STOP), then it waits for the
enable to become
In the initial state
INIT it waits for the setup of run length (
runLength), then it waits for the start flag (
During the run, it counts the run length into
offset variable and stops as the required run length is achieved.
PRU program is just 3 lines long:
- The first line calls ABZ encoder to get its position
- The second line calls the cutter logic. It uses the value of 4th input for the
- The motor is controlled via fast output 3 (
out3), and the value comes from the cutter logic (