Pages: [1]   Go Down
Author Topic: Serial communication with motor controller suffers from noise  (Read 876 times)
0 Members and 1 Guest are viewing this topic.
Northern California (by San Francisco)
Offline Offline
Sr. Member
****
Karma: 3
Posts: 258
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My Arduino is connected to a Pololu simple motor controller, which drives a windshield wiper motor. Everything is connected with a breadboard for now. It used to work fine, but now the motor controller stops every minute or two due to a serial error, which the motor controller says is due to "noise."

My code uses the NewSoftSerial library. Output pin 4 of the Arduino Duecimilanova is connected to the RX pin of the motor controller. Code is below:

Code:
#include <NewSoftSerial.h> 
#define rxPin 3  // pin 3 connects to SMC TX  (not used in this example)
#define txPin 4  // pin 4 connects to SMC RX 
NewSoftSerial mySerial =  NewSoftSerial(rxPin, txPin); 

int motorSpeed;
     
// required to allow motors to move 
// must be called when controller restarts and after any error 
void exitSafeStart() 

  mySerial.print(0x83, BYTE); 

   
// speed should be a number from -3200 to 3200 
void setMotorSpeed(int speed) 

  if (speed < 0) 
  { 
    mySerial.print(0x86, BYTE);  // motor reverse command 
    speed = -speed;  // make speed positive 
  } 
  else
  { 
    mySerial.print(0x85, BYTE);  // motor forward command 
  } 
  mySerial.print((unsigned char)(speed & 0x1F), BYTE); 
  mySerial.print((unsigned char)(speed >> 5), BYTE); 

   
void setup()   
{
  Serial.begin(9600);

  // initialize software serial object with baud rate of 38.4 kbps
  mySerial.begin(38400);
 
  // the Simple Motor Controller must be running for at least 1 ms
  // before we try to send serial data, so we delay here for 5 ms
  delay(5);
   
  // if the Simple Motor Controller has automatic baud detection
  // enabled, we first need to send it the byte 0xAA (170 in decimal)
  // so that it can learn the baud rate
  mySerial.print(0xAA, BYTE);  // send baud-indicator byte
 
  // next we need to send the Exit Safe Start command, which
  // clears the safe-start violation and lets the motor run
  exitSafeStart();  // clear the safe-start violation and let the motor run
  setMotorSpeed(700);
  motorSpeed = 700;

   
void loop() 
{
  int target, range = 50, potValue, delt = 25;

  potValue = analogRead(0);
  Serial.print("Pot Value: ");
  Serial.print(potValue);
  Serial.print("\n");

  if (potValue <= 100) {
    motorSpeed = 700;
  } else {
    if (potValue >= 923) {
      motorSpeed = -700;
    }
  }
  setMotorSpeed(motorSpeed);
  delay (100);
}

Anything I can do to eliminate these serial communication errors? I've tried to make sure all pins and wires are firmly connected, and looked for possible shorts and the like. I can't see any wiring problems.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 611
Posts: 49092
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A windshield wiper motor does not typically get controlled by a motor controller via an Arduino. So, if it is electrically noisy, it does not matter. When controlled by a motor controller via an Arduino, it DOES matter.

Try some small capacitors across the motor connections, as close to the motor as possible.
Logged

Northern California (by San Francisco)
Offline Offline
Sr. Member
****
Karma: 3
Posts: 258
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the suggestion of the capacitors. I'll get some and try them.

I know that the motor is noisy. But I did not know that it would affect the motor controller serial receiver. The Arduino should be okay -- it's powered by my laptop through the USB cable.

The motor controller comes with a big capacitor. But Pololu suggests that people might want to use a bigger capacitor in some cases. Would that help here?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 611
Posts: 49092
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
But Pololu suggests that people might want to use a bigger capacitor in some cases. Would that help here?
Certainly couldn't hurt, and capacitors are cheap.
Logged

Northern California (by San Francisco)
Offline Offline
Sr. Member
****
Karma: 3
Posts: 258
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try some small capacitors across the motor connections, as close to the motor as possible.

Any recommendation on type, size and number of these capacitors? Perhaps two ceramic, one around 0.1uF and one around 220uF? As I understand it, that is typical in this type of case.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 611
Posts: 49092
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Grumpy Mike is the expert on this subject. Fortunately, he's gotten tired of answering the same questions over and over, so he's put stuff on his website.

http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html
Logged

Northern California (by San Francisco)
Offline Offline
Sr. Member
****
Karma: 3
Posts: 258
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the reference to Grumpy Mike's website.

Ironically, I had read that webpage before, and was planning on building decoupling into my design. But it never dawned on me that it was needed here, and needed now. I thought since I had two separate power supplies there was no problem. Not realizing, of course, that the power supplies were not, in fact, really separate, and so the motor's power line needed to be filtered.

Thanks for waking me up to that fact. I'll try soldering a 0.0uF ceramic capacitor and a 47uF or 220uF electrolytic capacitor across the motor terminals, and see if that gets rid of the noise.
Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9560
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It used to work fine, but now the motor controller stops every minute or two due to a serial error, which the motor controller says is due to "noise."

That is a smart motor controller to self diagnose noise issues. So what did you change between the time the controller worked ok and it doesn't work ok?
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Northern California (by San Francisco)
Offline Offline
Sr. Member
****
Karma: 3
Posts: 258
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That is a smart motor controller to self diagnose noise issues.

Pololu has some software it calls the Simple Motor Controller Center that gives you a display to control the controller. On that display, it shows an error when the motor stops. In my case, whenever the motor stops, it shows a "serial error," which it says is caused by "noise."

Quote
So what did you change between the time the controller worked ok and it doesn't work ok?

Nothing. The code I wrote just cycles the motor from one limit to the other. When I first start the code it works fine for about 2 minutes. Then it gets a serial error. Although the errors are sporadic, the code only runs about 20 seconds on average before an error occurs.

If I turn everything off and let it sit for a while, then I can again get it to run for about 2 minutes without error.  
Logged

Northern California (by San Francisco)
Offline Offline
Sr. Member
****
Karma: 3
Posts: 258
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just an update. I soldered a 0.1uF capacitor across the motor terminals. That did not help. In fact, it seems to have made things worse.

I'm going to add a larger capacitor -- probably a 220uF -- while keeping the 0.1uF. See if that helps.
Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9560
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Capacitors to cure "noise" is often "snake oil" solution that doesn't fix anything. There maybe electrical motor noise after the motor warms up due to issues with the motor, but there may actually be other issues. The motor control chip may consider any inappropriate control input to be "noise".
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just thinking loud: Is it noise or is it jitter? Maybe try the hardware serial port?
Logged

Northern California (by San Francisco)
Offline Offline
Sr. Member
****
Karma: 3
Posts: 258
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Now I've gone and done something stupid. After having put a ceramic capacitor across the motor terminals, I decided to add an electrolytic capacitor. But I did not think about the fact that the motor changes direction, which is done by reversing current flow. So I had current going the wrong way through the electrolytic capacitor.

Now my motor controller does not seem to work right. And apparently unrelated but coincidentally, I ruined my potentiometer. So now I've had to order new parts and wait to try again. Expensive lesson.

And as some people have pointed out, motor noise may not be the problem anyway. Just have to wait and see.

Thanks for all the suggestions and information. It was interesting.
Logged

Pages: [1]   Go Up
Jump to: