I2C Safe Start

I’m running a G2 24V12 (item 1365) motor controller using I2C and a Pololu 25D brushed DC motor (item 4843). The board is configured the control with the software. This works very nicely. The sample code works very well to set motor power and to read variables from the control. By using a PID loop values are sent to the control very quickly (about every 20ms). Most of the time it works but occasionally there is “safe start” error. The Error Status Code (ID=0) only is a value of 1, Meaning Save start violation. Status (ID=3) also return a 1, indicating only Safe-Start violation.

If “Disable safe start” is checked the motor does not fault out, although on a speed sweep you will occasionally hear a glitch in the noise during a smooth speed.

After implementing the cyclic redundancy check (CRC) I think that these may be trapped but now it must be creating an error on the CRC error unless the “Ignore ERR line high” box is also checked.

No point in turning off all error checking. Any idea on what could be causing the error and what to do to correct it?

Note: The I2C bus has pull-up 6.8K resistors to the Mega’s 5V pin. I only have SDL/SCL and GND connected (other than motor supply and A&B).

Thanks,

-ErikR

Hello, ErikR.

It should be fine to have the “Ignore ERR line high” option enabled since you are not using the controller’s ERR line as an input. It sounds like you probably have some noise problems with your I2C lines. Could you post some pictures of your system that show all of your connections? Also, could you connect your controller to the Simple Motor Control Center G2 and monitor the “Errors” box in the “Status” tab while the system is running to see which errors are occurring?

Brandon

Brandon,

Here is my setup: The orange wires are SDA and the yellow are SCL. The Robogaia encoder board is using SPI. If I remove the board I get the same errors so don’t think the issue is the board.


The motor cable is as long as it is because the motor that eventually needs to be used will be farther away than in the test setup.

With the Safe Start and ERR disabled the following errors happen:
05-SafeStartDisabled

With Safe Start and ERR enabled the following errors happen:

Example code that would cause the error is:

for(int i=400; i<3100; i+=1)
    {
      myMotor.setMotorSpeedCRC(i);
    }

With the motor class code being pretty much taken from the manual:

const unsigned char CRC7_POLY = 0x91;
unsigned char getCRC(unsigned char message[], unsigned char length)
{
  unsigned char i, j, crc = 0;
  for (i = 0; i < length; i++)
  {
    crc ^= message[i];
    for (j = 0; j < 8; j++)
    {
      if (crc & 1)
      crc ^= CRC7_POLY;
      crc >>= 1;
    }
  }
  return crc;
}

void Motor1365::setMotorSpeedCRC(int16_t speed)
{
  uint8_t cmd = 0x85;  // Motor forward
  delay(2); // This is just here to not send messages too quickly
  if (speed < 0)
  {
    cmd = 0x86;  // Motor reverse
    speed = -speed;
  }
  unsigned char message[4] = {cmd, 0x00, 0x00, 0x00};
  message[1] = speed & 0x1F;
  message[2] = speed >> 5 & 0x7F;
  message[3] = getCRC(message, 3);
  Wire.beginTransmission(smcDeviceNumber);
  Wire.write(message[0]);
  Wire.write(message[1]);
  Wire.write(message[2]);
  Wire.write(message[3]);
  Wire.endTransmission();

// send this message to the Simple Motor Controller
}

I plan to put a scope on the I2C signal and see what I can determine.

The board seems like it has tremendous application, much more than the 2995’s that I have used before (with great success).

-ErikR

Here’s a closeup of the wiring and the boards.

Here are the results from the scope:
SCL


SDA

And the Encoding

I typically don’t look at these so not sure if they look good are not. My thought is there may be a long RC time constant but the clock is getting up to 5V.

-ErikR

Thank you for the additional information. It might be possible that you are introducing some noise to your Arduino from coupling your encoder wires tightly with your motor wires. As a quick test, could you try disconnecting the encoder shield from your Arduino, then disconnecting the encoders from the shield to see if that makes the CRC errors stop?

Brandon

@BrandonM, I tested with the encoder board removed completely and got the same result. i normally would agree to keep the encoder wires away from the motor wires but the standard Pololu motor has the wires from the motor all together. The encoder and motor wires are nowhere near the I2C wires and I think the error being generated.

The Serial Error count is sometimes higher than the CRC count. I have also noted a few “Format” errors.
Error-Count

I have been testing on the main motor (a 24V larger DC motor) and am experiencing the same problems so no finger pointing at the Pololu motor.

Overall the board works well with the exception of instantaneous glitches in speed.on the errors.

Regarding the I2C traces, this is the normal trace: Look at the yellow clock trace. Nice and even, with a good 0V.

This or a variant of this happens occasionally. Notice the small step in the clock signal. This one shows three little steps. Some have one or two. Also note the duration increased. Any thoughts?

I do not see anything else obvious that would cause corrupted serial data. Any time there is a motor in the system there can be some risk of noise. I agree that your setup looks separated enough, but since you are still having some kind of interference, could you try disconnecting the motor completely and running your system without it to definitively rule it out?

How quickly does the occurrence count of the CRC error increase? Is there any predictability or noticeable pattern to the frequency it’s happening?

Brandon

@BrandonM, With the motor disconnected and sending a 0 speed command every 20ms:

  • with an I2C bus of 40KHz I saw 14 serial errors and 11 CRC errors in one minute

  • with an I2C bus of 300KHz I saw 8 serial errors and 6 CRC errors in one minute

  • with an I2C bus of 200KHz I saw 3 serial errors and 2 CRC errors in one minute

  • with an I2C bus of 100KHz I am not seeing the errors in one minute

Long term test at 100KHz (for 30 minutes)

  • with an I2C bus of 100HKz I am not seeing the errors, even with the motor running.

I guess we chalk it up to I2C bus speed. Is it safe to assume a maximum I2C bus speed of 100KHz?
I though most devices could handle 400KHz and seeing this note on the specs sheet made me assume I could even go to 500KHz

Autodetects baud rates between 1200 and 500,000 bps, or can be set to any fixed baud rate in this range.

What is the max safe I2C bus speed for the 1365?

-ErikR

I did not expect there to be a problem with I2C at 400 kHz, but we did not thoroughly test its limits in various setups. You might try using more aggressive pull-up resistors to see if that helps reduce the errors at higher speeds.

Brandon