Currently hating the currentsensing on MegaMoto Plus

HI someone.

I have a problem i cant get rid of. I am trying to sense the current going through my dc motor, in order to control the Torque with a closed loop. The thing is that i cant seem to get the sensing working for me - i thought it was straight forward…

The MegaMoto Plus board (motorcontroller) has a build in 634Ohm resistor so the Arduino can read the voltage drop and thereby calculate the current running through the motor.

Manual for the motorboard: http://www.robotpower.com/downloads/MegaMoto-user-manual.pdf

it will return 3V at 40Amps
i have connected a multimeter in series so i can check if the Arduino is calculating the correct current.

  1. The reading is very jumpy - nothing like the multimeter i have connected.
  2. the calculated current is way too low.

When i first connected the motor, it started to “scream” when i was applying low PWM values. I got it to stop by changing the frequency to 32kHz - in the manual for the board it says the the maximum frequency for the board is 20kHz - i guess it will be switching at 20kHz even though the Arduino is running 32kHz? In the following script i have changed it to 7800Hz but that does not get rid of all the “screaming” but most of it.

  1. Is there a way to run closer to 20kHz or can i just use 32kHz?
  2. last question. I found that when running the motor at fairly high speeds but with no load, the MOSFETS got very hot - am i doing something wrong when switching???

Thanks a bunch for your help

//****************Define variables*************
const int pinPWMA = 6;
const int pinPWMB = 5;
const int pinENABLE = 8;
const int pinTRANSDUCER = 2;        // analog input (for now a POT)
 int pinCURRENT = A5;

int Setpoint;
int Output;


float currentRAW;
float currentVOLTS;
float currentAMP;

//*************dfefine constanta*************
float volt_per_amp = 0.075;


void setup()
{
  //TCCR0A = 0x01;                        // Timer 2: PWM 3 & 11 @ 32 kHz
 TCCR0B = _BV(CS01);                    // timer 0: PWM 6 & 5 @ 7812.5Hz

  pinMode(pinPWMA, OUTPUT);        //Defining my outputs/inputs
  pinMode(pinPWMB, OUTPUT);
  pinMode(pinENABLE, OUTPUT);
  pinMode(pinTRANSDUCER, INPUT);
  pinMode(Setpoint, INPUT);
  pinMode(pinCURRENT, INPUT);
  
  
 
  
  Serial.begin(9600);

  digitalWrite(pinENABLE, HIGH);
  delay(500);
  digitalWrite(pinENABLE, LOW);// Reset overcurrent or overtemp fault.  May need to let the MegaMoto cool.
  delay(500);
  digitalWrite(pinENABLE, HIGH);
  
}

void loop()
{
  
  
  Setpoint = analogRead(pinTRANSDUCER);
  Setpoint = map(Setpoint, 0, 1023, -1000, 1000);    //Converting value
  

  
  if (Setpoint >= 0) {
    Setpoint = abs(Setpoint);
    if (Setpoint < 20) {        // Dont do anything if value of setpoint is too low
      Setpoint = 0;
    }
    
    Output = Setpoint /3.92;     //converts to 0-255 (PWM)
    digitalWrite(pinPWMB, LOW);
    analogWrite(pinPWMA, Output); 
    Serial.write("You are now going right");
    Serial.println();   
  }
  
 else {
   Setpoint = abs(Setpoint);
   if (Setpoint < 120)  {                 
   Setpoint = 0;
   }
  
   Output = Setpoint/3.92;
   digitalWrite(pinPWMA, LOW);
   analogWrite(pinPWMB, Output); 
   Serial.write("You are now going left"); 
   Serial.println();   
 }
    
    
  currentRAW = analogRead(pinCURRENT);
  currentVOLTS = currentRAW *(3.0/1024.0);
  currentAMP = currentVOLTS/volt_per_amp;
   
    Serial.println(currentAMP);
    delay(10);
     

}

Here is the deal. The current sense voltage on that board is not a pure analog voltage representing the average current flow through the motor. Rather it will be in the form of a PWM signal switching between +5vdc and ground with the duty cycle representing the current flow amount. Your analog read on a arduino will just be randomly reading max and min values as it samples that point. Even you DMM will give you a false representation of the signal and cannot be trusted to display a valid number. You need to wire a simple low pass filter (series resistor from voltage point to capacitor wired to ground with the sample point taken from the cap/resistor junction. Try a 5K ohm resistor and a 10ufd cap.

Lefty

Thanks for the reply

Okay, after reading a bit about these low-pass filters i calculated the following:

Using a 10ufd capacitor and a 5kohm resistor i will get V_max= 3V Hz=20k

Xc=0.796 =>
V_out=0.024V ripple

Is that correct?
What does that leave me? Can i say anything about the sensitivity of the measurement?

Thanks again.

One more question.....

How will a signal from a hall-sensor be - do you know? Will it also need to be filtered or is it maybe better to feed it a more stable V_in?

Thanks again.

OKAY - after wiring up the filter i connected it to the motor shield (very excited)… and now now i was able to get a more stable reading, but there has shown to be 2 issues.

  1. The motor seems to be drawing more current running one direction then the other - how is that possible?
  2. The Amps drawn from the motor goes up rapidly in the beginning but then stabilizes somewhere just below 1 amp if i dont touch the pot - but if i continue to crank up the PWM the AMPS goes down to about 0.12A !!! THAT i dont understand!

MrBear:
OKAY - after wiring up the filter i connected it to the motor shield (very excited)...... and now now i was able to get a more stable reading, but there has shown to be 2 issues.

  1. The motor seems to be drawing more current running one direction then the other - how is that possible?

Maybe the timing of the commutator/brushes on the motor give it asymmetrical preference to rotation?

  1. The Amps drawn from the motor goes up rapidly in the beginning but then stabilizes somewhere just below 1 amp if i dont touch the pot - but if i continue to crank up the PWM the AMPS goes down to about 0.12A !!! THAT i dont understand!

That sounds normal. Motor will draw larger current at standstill until it's rotation starts to develop counter EMF to offset applied voltage and settle into a normal current draw per RPM and load conditon.
Lefty

Hi Lefty

Thanks for the response.

Regarding the brushes i doubt that they will cause that but i will try to bring my tachometer tomorrow so i can measure the RPM simultaneously - the thing is that it is a printed motor (aka. pancake motor) and they are extremely simple and have a very linear speed/torque characteristics. Could i be doing something wrong in my code? I am keeping one mosfet low and the other gets the PWM, it was my understanding that how it was done!

I may have been lost in translation regarding the second issue, sorry. What i meant is that if i turn the pot 2/3 of the way and wait, the Amps drawn (measurement generated from the code) shows a bit less than 1A - after it has settled. if i then start to turn the pot again, instead of drawing more amps, it starts to draw less!!!!! This can of cause not be true, because i can hear the motor increasing in speed........ And yes, i am turning the pot in the same direction ;-).
Have i got a ghost haunting me or am i too stupid to see the obvious?

Best Regards

Several points:

  1. The PWM frequency will be whatever you are feeding it, i.e. 32kHz. The higher the PWM frequency, the greater the switching losses in the mosfets (and the hotter they get). The 20KHz limit for that board is probably based on mosfet heating.

  2. You can get whatever PWM frequency you want, but on the Uno this is at the expense of giving up some PWM pins. For example, if you want variable-frequency PWM on pin 5, then you can't use pin 6 for PWM.

  3. Eddy current losses in the motor will also increase with PWM frequency. You can reduce them by connecting a power inductor in series with the motor.

  4. If you use a Hall current sensor in series with the motor, then the current it reads will be somewhat smoothed by the inductance of the motor (plus any series inductance you added).

  5. It is possible to synchronize the current sense reading with the PWM, if you need to. However, the low-pass filter should be sufficient.

  6. Can you confirm that you are only providing a PWM signal to one of the two inputs at a time, and holding the other input LOW?