Table of contents |

Configuring DC Brush Motor with SnapAmp and Single-Ended Encoder to KMotion

This example will proceed through the following steps:

  1. Wiring the Motor, Encoder, and Power
  2. Configuring the Software
  3. Testing the Encoder
  4. Testing the Motor/Amplifier
  5. Closing the Loop
  6. Tuning the Servo
  7. Executing a simple C Program Motion Sequence

Here is a video overview (wmv).

Wiring the Motor, Encoder, and Power

This example configuration shows a single dc brush motor connected to the first of 4 available full bridge drivers on a single SnapAmp 1000. A single-ended encoder is connected to KMotion's JP3 connector as encoder input #0 for Servo feedback. (The KMotion board is hidden underneath the SnapAmp in the photo). Note: Encoders typically come as one of two types - differential outputs (having A+, A-, B+, B-) or single ended outputs (A B). A differential encoder may be used as a single ended encoder by only using the A+ and B+ signals (and leaving the A- and B- unconnected). However single ended signals are more susceptible to noise than differential signals. KMotion has 4 single ended encoder inputs. SnapAmp 1000 has 4 differential encoder inputs. In this example a KMotion single-ended encoder input is used. Some encoders have a index pulse that occurs once per revolution usually labeled as channel Z. In this example the index is not used and is not connected.

Wiring the Motor

Wiring the Motor

Wiring the Motor

Configuring the Software

After the motor and encoder connections have been made, the software is configured and the encoder feedback and motor is tested.

Although any of KMotion's 8 axes could be used, axis 4 will be configured since axes 0-3 are normally used for KMotion's on-board amplifiers.

In the KMotion Executive program three screens involve setting an axis's configuration: The Configuration Screen, the Step Response Screen, and the Filters Screen. These three screens and our choice of initial settings are shown below:

Execute the KMotion executive program and set the Options for a single SnapAmp. See below:

Configuring the Software

On the Configuration screen Axis Channel 4 is selected, the input type is set to Encoder at encoder channel 0, the output type is set to DC Servo at PWM channel 8, and a very large following error is set.

On the Filters Screen all filters are disabled by "Clearing" all filters to have a gain of 1.

Filters off

The Step Screen servo loop (PID) parameters are set to only very low proportional gain. The max output is set to a small value that should still allow some motor motion. SnapAmp DC Servo mode outputs current commands in the range of -1000 to +1000 which corresponds to approximately -30Amps to +30 Amps. So a max output of 100 will limit the current to 3 Amps. Although the Integrator will not be initially used we set the max integrator to also be 100. The max error is set to a large number. The motion profile parameters are set to values that we will expect to eventually achieve. Our example uses a low speed torque motor being driven off of only 12V. This encoder has 4000 counts/rev so a speed of 50,000 cnts/sec corresponds to 12.5 rev/sec (750 RPM).

With the Motor Power Supply tuned off, pushing the Enable button will download the parameters from all screens and enable the axis without any motor motion. This will allow us to ensure the axis is properly wired and configured as encoder input and of the correct encoder channel.

Screen Low Gain

Testing the Encoder

We can now rotate the motor/encoder shaft by hand and should observe counts on Axis Channel 4 on the Analog Status Screen. Note if one of the other axis's configurations also is defined as input Encoder channel 0 then that axis may count as well. The default configuration for axis 0 is Encoder input from channel 0. To avoid confusion, disable any other axis by selecting that axis, define the input/output types as "No Input" and "No Output", then download, then disable the axis. To test the encoder, rotate the encoder and check if the expected number of counts per rev are obtained. Rotating the axis the opposite direction should count in the opposite direction.

Counts changing

Testing the Motor Amplifier

In order to test the Motor Amplifier functionality Console commands (PWMC - Pulse-Width-Modulation Current Mode) will be entered to drive the motor in the forward and reverse direction. The axis should and must be disabled to issue these commands, otherwise they will be immediately overwritten with servo output commands. Small values should be used initially. Note: PWMC commands may only be used with a SnapAmp (Software Version 2.31 or later), the KMotion onboard amplifiers do not have current feedback mode so PWM commands should be used instead. SnapAmps's PWMC current commands range from -1000 to +1000 which corresponds to approximately -30Amps to +30 Amps. So a value such as 100 might be used to provide a drive of 3 Amps.

Before issuing the PWMC commands, SnapAmp's peak current fault levels should be set. After verifying that the axis is disabled (on the Analog Status Screen), load and execute the following program to set the peak current limits. The Fault Green LED on the SnapAmp should turn off. The "I'm alive" Green LED should remain blinking.

Set High Current Limits

Setup the Console Screen as shown below. Sending the commands should drive the motor in one direction, then no motor drive, then drive in the other direction respectively.

Console PWMC

Closing the Loop

If the motor and encoder are working we are ready to attempt to close the servo feedback loop. All that is required is to enable the axis by pressing "Enable" on the Step response Screen. Normally one of two things will occur. Either the axis will respond as a weak servo, or the servo will have positive instead of negative feedback and runaway from the target destination rather than toward the target destination.

If the servo has positive instead of negative feedback, something should be reversed. Either the Motor leads may be reversed, the encoder signals may be reversed, or a Input Gain of -1 may be entered on the Configuration Screen (as shown below).

Negative Input Gain

If the servo has proper feedback and responds as a weak servo, as the motor/encoder shaft is turned the servo will cause torque to restore the position back to where it was. With the example proportional gain of 0.01, turning the sharft 1 turn should generate an error of 4000 counts. 4000 counts multiplied by a gain of 0.01 = 40 PWMC counts or 40 / 1000 * 30Amps = 1.2 Amps.

Tuning the Servo

Once the servo loop is functional Servo Tuning should be performed to move the performance, hopefully up to the desired levels. Servo tuning is a complex subject that has been written about extensively. The basic idea is to increase the feedback gains in order to reduce following errors and speed of response without going unstable (oscillating wildly). KMotion has extensive plotting tools to help tune and understand how well a set of parameters performs.

To test the current performance, disable the axis, manually move it to a position where it may move +10000 counts, then push the "Move" button. A plot such as that shown below should be observed. Set the plot type and axis selections to agree with those shown below. The blue plot is the desired path as defined by the motion profile and the motion is made for 10,000 counts and then a second motion is made back to zero. The red plot is the measured encoder position. Note that the red plot attempts to follow the blue plot but with a large error of thousands of counts. Gradually increase the P gain (possibly by factors of 2) while pushing the Move button and the following error should reduce. At some point the system will probably go into oscillation and become unstable. It may be necessary to disable the axis, reduce the gain, and re-enable the axis.

Poor Plot

Increasing the gain 500X (from 0.01 to 5) results in a much better response. Notice the blue (desired) plot is almost completely hidden behind the red measured plot. However by zooming in to the purple rectangle (left click mouse drag) we can see oscillation. See the second plot below.

Better Plot

Oscillation

Increasing the derivative gain can often reduce oscillation. In the plot below we have set the D gain to 16. Notice the oscillation has been reduced.

Derivative Gain

A Bode plot is useful in understanding the frequency response and for designing advanced servo loop filters. Below is the Bode plot response of the system. Important features to look for in a Bode plot is where the Magnitude (blue plot) first passes through the 0 db line. This is the bandwidth of the system. Another important measure is the "phase margin" which is how far away the phase is from -180 degrees when the magnitude is at 0db. In this case the phase margin is 28 degrees. See the Bode Screen in the main Help section for more information

Bode Plot 65Hz

Executing a simple C Program Motion Sequence

The C program below is an example of a simple program to perform a sequence of moves and repeat. There are 5 moves of 8000 counts (2 motor revs) and then a move back to the start. After each small move there is a wait until the motion is complete followed by a 0.2 second delay. Here is a video of the mechanism executing the motion.

Move Mechanism