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.
- The reading is very jumpy - nothing like the multimeter i have connected.
- 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.
- Is there a way to run closer to 20kHz or can i just use 32kHz?
- 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);
}