Kanalog Dual-DAC Commutation Setup for Brushless Servo Motors

Tom Garrett10 min read
Motion ControlOther ManufacturerTechnical Reference
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

Overview

The Kanalog analog amplifier daughter board extends a Dynomotion KFLOP motion controller with dual high-speed analog outputs suitable for driving external three-phase brushless motor amplifiers that accept a two-phase (sin/cos or equivalent quadrature) command input. A dual-DAC amplifier internally reconstructs the third phase or operates as a true two-phase drive, so the controller only needs to command two phase-current setpoints and produce the correct commutation angle as a function of rotor position. This reference explains how to compute invDistPerCycle for a multi-pole brushless servo, how to use the bundled AutoPhaseFindDualDACs.c and DualDACPhaseFindAndCommutateV2.c programs, and how to verify CommutationOffset when the encoder index is aligned to a known phase. The procedures apply to any KFLOP firmware that exposes the Kanalog DAC pair and the standard commutation primitives.

System Topology and Signal Flow

A KFLOP+Kanalog dual-DAC system typically consists of the following blocks:

  1. KFLOP controller running the trajectory planner and commutation math.
  2. Kanalog daughter board providing two 16-bit analog outputs (DAC A and DAC B) and the encoder interface.
  3. An external brushless servo amplifier with two differential analog command inputs (often labeled REF1 and REF2 or I_CMD_SIN and I_CMD_COS).
  4. A brushless motor with a multi-pole rotor and an incremental encoder (typically with index).

The two analog outputs represent commanded phase A and phase B currents. The amplifier generates the third phase C internally using IC = -IA - IB for a wye-connected three-phase winding, or it may operate strictly as a two-phase drive. Encoder counts feed back into KFLOP through the Kanalog JP4 connector, providing both commutation angle and closed-loop position feedback.

Electrical Cycles Versus Mechanical Revolutions

A brushless motor with P poles produces P/2 pole pairs. Each pole pair corresponds to one full electrical cycle of the phase back-EMF. Therefore:

electrical_cycles_per_mech_rev = P / 2

Common pole counts and corresponding electrical cycles per mechanical revolution:

Poles (P) Pole Pairs Electrical Cycles / Mech Rev
2 1 1
4 2 2
6 3 3
8 4 4
10 5 5
14 7 7
20 10 10

For the example in the supporting notes (14-pole motor with a 2048 PPR encoder), the motor completes seven electrical cycles per mechanical revolution.

Calculating invDistPerCycle

The parameter invDistPerCycle expresses the inverse of how far the motor travels in user-position units per electrical cycle. It is the reciprocal of DistPerCycle and is used by the commutation routine to convert the encoder position into the electrical angle:

electrical_angle_rad = 2 * pi * position_counts * invDistPerCycle

The exact computation depends on the encoder resolution configured in KFLOP. With a 2048 PPR encoder and x1 decoding (counts = PPR), and seven electrical cycles per mechanical revolution:

invDistPerCycle = electrical_cycles_per_mech_rev / counts_per_mech_rev

invDistPerCycle = 7 / 2048 = 0.00341796875

If x4 quadrature decoding is enabled, counts per mechanical revolution become 8192 and:

invDistPerCycle = 7 / 8192 = 0.0008544921875

Always confirm the encoder mode (x1, x2, x4) on the KFLOP configuration screen before computing the value. Setting the wrong ratio will cause the commutation angle to advance too quickly or too slowly, producing cogging, torque ripple, or a stalled axis.

Bundled Example Programs

KFLOP/Kanalog ships with several C example programs intended to bring up a dual-DAC brushless axis. Each has a distinct role and they are normally used in sequence:

Program Purpose Output Behavior
AutoPhaseFindDualDACs.c Determines commutation offset and (optionally) verifies invDistPerCycle by injecting controlled current pulses and observing rotor motion. Drives Kanalog DACs with low-amplitude diagnostic currents.
DualDACPhaseFindAndCommutateV2.c Continuous closed-loop commutation using the values discovered by the auto-phase routine. Demonstrates velocity-mode operation. Outputs the configured DAC pair (or NO_OUTPUT_MODE for dry-run testing).
DualDACRotateForever.c Open-loop or closed-loop continuous rotation test using the Kanalog DACs. Drives DACs based on trajectory output.

The recommended workflow is to (1) set invDistPerCycle manually using the formula above, (2) run AutoPhaseFindDualDACs.c to capture the required offset, (3) commit the offset into the axis configuration, and (4) run DualDACPhaseFindAndCommutateV2.c or DualDACRotateForever.c to verify smooth torque production.

Running AutoPhaseFindDualDACs.c

The auto-phase routine removes the need to manually align the encoder index to a specific phase. It performs the following steps automatically:

  1. Locks the amplifier enable.
  2. Drives a small DC current into phase A only, observes the resulting rotor motion with the encoder, and records the equilibrium angle.
  3. Repeats the test for phase B and (implicitly) phase C.
  4. Computes the electrical offset between encoder zero and the position of maximum phase-A torque.
  5. Prints the computed CommutationOffset and (in some firmware revisions) a recommended invDistPerCycle to the KFLOP console.

Use this routine any time the encoder is remounted, the amplifier gain changes substantially, or the motor is replaced. The reported values should be written into the persistent axis configuration so the commutation routine starts with the correct parameters on every power-up.

Safety: Ensure the motor is mechanically free to move through at least one electrical cycle (and ideally several) before running the auto-phase routine. A restrained rotor will report a wrong offset and may saturate the amplifier during the test pulses.

DualDACPhaseFindAndCommutateV2.c Output Modes

The V2 example supports several output modes selectable via a constant near the top of the program. The most important modes are:

Mode Constant Effect Typical Use
NO_OUTPUT_MODE Trajectory and commutation math execute, but Kanalog DAC outputs remain at zero. KFLOP performs no electrical output to the amplifier. Dry-run verification of trajectory parameters without energizing the amplifier.
OUTPUT_DAC_MODE Both Kanalog DAC channels are driven by the computed phase currents. Standard closed-loop operation with an external amplifier.

When NO_OUTPUT_MODE is active, the trajectory profile (position, velocity, acceleration, jerk, motion time) is still calculated and the commutation routine still advances its internal angle based on encoder counts. The motion profile is independent of the output mode and independent of the motor topology; only the final DAC write is suppressed. Engineers frequently use NO_OUTPUT_MODE to verify that invDistPerCycle, the encoder polarity, and the trajectory parameters behave as expected before applying real current.

OutputChan0 and OutputChan1 Settings

Both example programs expose OutputChan0 and OutputChan1 parameters. In the dual-DAC example these are not direct DAC channel selectors. Instead they are integer identifiers used by the companion Commutation Program (for example CommutationDualDAC.c) to know which KFLOP/Kanalog resources to bind:

  • OutputChan0: index of the first Kanalog DAC channel used to drive phase A.
  • OutputChan1: index of the second Kanalog DAC channel used to drive phase B.

With NO_OUTPUT_MODE the values stored in OutputChan0 and OutputChan1 are inert because no DAC writes occur. They are still recorded in the axis state for reference and become live the moment the output mode is switched to a value that actually writes the DACs.

Motion Profile Parameters in Dual-DAC Mode

The KFLOP trajectory generator produces a position setpoint each servo cycle regardless of the selected output mode. The values below affect the axis even when NO_OUTPUT_MODE is active:

Parameter Units Effect
Velocity counts / second Peak trajectory speed during a move.
Acceleration counts / second^2 Rate of velocity change at the start of a move.
Jerk counts / second^3 Rate of acceleration change; controls S-curve smoothing.
Motion Time seconds Total move duration when using time-based profiling.

Because the profile is computed in software and only the final DAC stage is skipped under NO_OUTPUT_MODE, you can verify trajectory behavior by reading the encoder count and comparing it to the requested position. A consistent lag or overshoot indicates a tuning issue, not an output-mode issue.

CommutationOffset and Index Pulse Alignment

CommutationOffset is the count offset (in encoder counts) between encoder zero (or the index pulse) and the electrical angle at which phase A produces maximum positive torque. It is the single most important parameter for correct commutation and must be determined before the axis is allowed to produce torque.

If the encoder index is mechanically aligned so that phase A is at maximum torque at the index position, then:

CommutationOffset = 0

If the index is aligned to the phase-A zero-torque crossing instead (a common situation when the encoder is keyed to the rotor without a torque-aligned reference), the commutation angle at the index is effectively shifted by a quarter of an electrical cycle:

CommutationOffset = +/- (counts_per_electrical_cycle / 4)

For the 14-pole / 2048 PPR / x1 example the counts per electrical cycle are 2048 / 7 = 292.57 counts (use 8192 / 7 = 1170.29 with x4 decoding). A quarter cycle would be approximately 73 counts (x1) or 293 counts (x4). The exact direction (positive or negative) depends on which side of the zero crossing the index falls. Rather than computing this by hand, allow AutoPhaseFindDualDACs.c to determine the offset experimentally: it injects phase currents and observes the rotor motion to identify the actual torque-producing direction.

Verification Procedure

After the auto-phase routine completes, verify commutation using the following checks:

  1. Command a small constant current in phase A only and confirm the rotor settles to a stable angle that does not drift. A drifting rotor means the commutation angle is moving while the rotor is not, indicating a wrong invDistPerCycle or a wrong sign on the encoder counts.
  2. Command a slow constant velocity move and observe phase A and phase B current on a scope. The two waveforms should be sinusoidal, 90 degrees out of phase, and locked to the rotor position.
  3. Reverse the commanded velocity and confirm that the phase currents swap appropriately. Reversed commutation produces torque in the wrong direction and will slam the motor into a hard stop if the amplifier enable is on.
  4. Run DualDACRotateForever.c for several minutes and listen/look for cogging or stepping. Cogging at a fixed electrical cycle rate indicates that CommutationOffset is off by a fraction of a cycle.
  5. Compare the KFLOP-reported electrical angle with the angle computed offline from the encoder counts; they should agree within a small fraction of a count over a full mechanical revolution.

Troubleshooting Matrix

Symptom Likely Cause Remedy
Motor stalls at first current pulse after auto-phase CommutationOffset is 1/4 cycle off because the index aligns to the zero-torque crossing instead of the peak-torque angle. Re-run AutoPhaseFindDualDACs.c with the motor free to rotate, or shift the offset by counts_per_electrical_cycle / 4.
Motor oscillates or vibrates at a fixed frequency proportional to commanded velocity invDistPerCycle mismatch (encoder mode set to x4 but formula computed for x1, or vice versa). Recheck the encoder decoding mode and recompute invDistPerCycle.
Phase currents are correct but motor rotates the wrong direction Encoder sign reversed, or phase A/phase B wiring crossed. Set EncoderSign negative or swap the two DAC output channels.
NO_OUTPUT_MODE trajectory test passes but real amplifier faults immediately Amplifier gain or current limit too low for the diagnostic pulses used by AutoPhaseFindDualDACs.c. Reduce auto-phase test current, or raise amplifier current limit per its manual.
Reported offset drifts every time the routine is run Mechanical load is too stiff or the rotor cannot complete the small motion required during the phase test. Decouple the load and rerun.
Commutation math advances but DAC outputs are stuck at zero Output mode is still NO_OUTPUT_MODE; OutputChan0/OutputChan1 settings are stored but not used until a real output mode is selected. Switch the example program to OUTPUT_DAC_MODE and recompile/run.

Persistent Configuration

Once the correct values for invDistPerCycle, CommutationOffset, encoder sign, and OutputChan0/OutputChan1 are known, persist them in the axis configuration so they survive a controller power cycle. KFLOP stores axis parameters in the persistent configuration and reloads them on boot. Always re-run AutoPhaseFindDualDACs.c after any hardware change (motor swap, encoder remount, amplifier replacement) before resuming production motion.

Frequently Asked Questions

How do I compute invDistPerCycle for a 14-pole motor with a 2048 PPR encoder?

Divide the number of electrical cycles per mechanical revolution (pole pairs = 7 for a 14-pole motor) by the encoder counts per mechanical revolution. With x1 decoding that is 7 / 2048 = 0.00341797. With x4 decoding it is 7 / 8192 = 0.00085449.

Do velocity, acceleration, and jerk still affect the axis when the example uses NO_OUTPUT_MODE?

Yes. The trajectory generator runs every servo cycle regardless of the output mode, so all profile parameters are applied. Only the final DAC write is suppressed, which lets you verify motion profile and encoder feedback without energizing the amplifier.

What does setting OutputChan0 and OutputChan1 actually do?

They tell the companion Commutation Program which Kanalog DAC channels to bind to phase A and phase B. With NO_OUTPUT_MODE the values are recorded but no DAC write occurs; with an active output mode the bound channels are driven by the computed phase currents.

If the encoder index is synced to phase A, is CommutationOffset always zero?

Not necessarily. It depends on whether the index marks the maximum-torque angle or the zero-torque crossing of phase A. If the index marks the zero crossing, the offset is roughly one quarter of an electrical cycle (counts_per_electrical_cycle / 4). Use AutoPhaseFindDualDACs.c to determine the correct value empirically.

Why does AutoPhaseFindDualDACs.c report a different offset every time I run it?

The most common causes are a mechanically restrained rotor, a sticky bearing, or an external load that prevents the motor from completing the small diagnostic motion. Free the rotor, lower the test current if the amplifier is faulting, and rerun the routine.

Back to blog