3.a.10. Command 192: Set Current Limit

Effect: Sets the current limit for the specified motor and the current control constant P (proportional component of PID). The current limit is provided as an 8-bit value that is continuously compared to the corresponding motor current average measured using the ADC. The control constant P is a 7-bit value that determines how the motor behaves in the vicinity of the current limit. Additionally, P affects what the motor does in response to a motor fault. If P is zero, the motor will shut down if it experiences a fault. Otherwise the motor will attempt to recover from the fault by toggling the control lines. The following pseudocode details how the current limit is handled:

    if current limit == 0:
        no current limit, take no actions based on motor current average
    else if P == 0:
        shut down motor if motor current average > current limit
        (or if a motor fault occurs)
        adjust pwm every 10 ms according to the formula:
            internal pwm word += min( acceleration, P * ( current limit – current ))
            actual pwm = min( target pwm, ( internal pwm word + 5 ) / 10 )

The pwm is internally tracked with two-byte precision rather than one to provide added resolution. When using a non-zero current limit and P, the effect is that that pwm is decreased each update if the average current exceeds the current limit. If the average current is below the current limit and the pwm is below the target pwm, the pwm will be increased each update either based on our acceleration setting or based on a value proportional to the difference between the average current and the current limit, whichever increment is smaller. Acceleration and P combine to influence how the pwm will change each motor update cycle.

It is important to note that current sensing is not possible in joint motor mode. As such, this command has no effect when running in joint motor mode. It is also important to note that current sensing is only possible when using a motor driver daughter board that has VNH2SP30s (the VNH3SP30 does not provide current sense feedback).

This command does not save this setting to EEPROM, however it can be saved by issuing separate EEPROM-write commands (240—Section 3.d.02) that store the values at the appropriate addresses (5 for motor 1 current limit, 6 for motor 1 P, 7 for motor 2 current limit, and 8 for motor 2 P). P must be stored as a 7-bit value (i.e. P must be <= 127).

Note: this command is bugged in firmware version 1.00, however it has been fixed in version 1.01.

Values sent: current limit (8 bits), control constant P (7 bits), motor (1 bit)

command byte = 192 | (motor << 1) | current limit MSB

data byte 1 = 7 lower bits of current limit

data byte 2 = 7-bit control constant P (MSB always zero)