Go Down

### Topic: How to increase the dc motor's speed(andFrequency)value more than255(and64KHZ)? (Read 6457 times)previous topic - next topic

#### MEKACI

" How to increase the dc motor's speed value more than 255 ? and the frequency value more than MOTOR12_64KH at adafruit motor shield ? thanks "

Hi all,
I have some questions for you :

At my tank project, I am using 4 dc motors ,and 1 dc motor uses 9V-12V, with adafruit motor shield now. The weightness of my tank project is 6kg ;so I felt like these 4 ,9V-12V, dc motors' speed is not enough for a good acceletarion with this (0, 255) speed value at MOTOR12_64KH while we are writing our code at adafruit motor shield.

Thus, how to increase the dc motor's speed value more than 255 ? and the frequency value more than MOTOR12_64KH ? thanks.
If I put a better dc motor which uses more than 12V this speed of 255 speed value will be more efficient, that is to say, I will be able to observe more speed with a better dc motor with same coding ?

And, for a good acceleration to a 6kg tank's to move what kind of dc motor I should use ? I will be glad if you give me some advices ;and answer my above questions, thanks.

Not :

#### Grumpy_Mike

The 255 is just  when the motor is full on, you can not get it better than that.
The frequency of PWM does not effect the speed of the motor.
Faster or more powerfully motors is what you need.

#### TomGeorge

#2
##### Apr 16, 2014, 09:57 amLast Edit: Apr 16, 2014, 09:58 am by TomGeorge Reason: 1
Hi, what is your project, what are you doing with the motors?
Increasing the 64kHz will not increase the speed of the motors, and as Mike has said, 255 is full power to them.
A picture of your project and a picture or CAD of your circuit in PDF, jpg or png would be help full.
At the moment you know how your project works and what you want it to do, the forum members don't, so you need to give us as much information, including pictures, so we can help you.

Tom......
Everything runs on smoke, let the smoke out, it stops running....

#### MEKACI

#3
##### Apr 16, 2014, 12:31 pmLast Edit: Apr 16, 2014, 12:33 pm by MEKACI Reason: 1
This is one of my dc motor that I am using at my tank project for the movement of tank.

I am using 4 above picture dc motors for the movement at my tank project ;and there will be 1 more dc motor again ;and 4-6 servo motors ( total : 5 dc motors + 4-6 servo motors )

This is the small video to show you what I have encountered about speed :

Is this less speed happening because I am getting power with usb cable from my computer ( but when I connect it to 9V battery directly the speed is increasing visibly ? If so, I have some techical questions to you again :

I want to use 2 seperated DC power supply for the Arduino and the motors. I plan to use a 9V battery and connect it to arduino's dc jack; then I plan to use a parallel connected 9V batteries ( but I don't know how many I should need to control 4 dc motors for the movement of the tank ,and other extra one more dc motor for the firing system ;and as I mentioned there will be 4-6 servo motors too  ). When I connect 2 different power supplies to my arduino and motor shieldİ my arduino might be affected from the motor shield's power supply ? I don'T know how these seperated power supplies are working at arduino.

I have read somewhere that was saying that " take off the ' JUMPER ' if you want to use ". What is the meaning of " JUMPER " at Arduino ?

These are the some of the questions I wanted to ask and learn;but  there are more actually. Please someone helps me to understand these ;then I want to ask you guys more. Thank you very much really^^.

Not :
Adafruit motor shield can handle the voltages between 6V and 25V while arduino can handle maximum 18V so far I know ;but I don't know how much ampers they can handle both ( if I have written here something false , please adjust my mistake at this sentence ;or at any sentences ).

I am using " Adafruit motor shield + mega sensor shield on my  arduino mega 2560 R3.

My one dc motor wanted ideal voltage is 9V or 12V.

#### Grumpy_Mike

#4
##### Apr 16, 2014, 08:42 pmLast Edit: Apr 16, 2014, 08:46 pm by Grumpy_Mike Reason: 1
Quote
I plan to use a 9V battery

Small rectangular battery? Bad idea, they have very limited capacity and are expensive.

Quote
then I plan to use a parallel connected 9V batteries

No never connects batteries directly in parallel, they charge / discharge each other. If you must then use a seriese diode on each battery, but you loose voltage like this.
Better get a clip of 8 AA batteries.

Quote
When I connect 2 different power supplies to my arduino and motor shield? my arduino might be affected from the motor shield's power supply ?

No they won't affect anything. You must make sure that the -ve terminals are connected together.

Quote
I have read somewhere that was saying that " take off the ' JUMPER ' if you want to use ". What is the meaning of " JUMPER " at Arduino ?

On the very early Arduinos there was  jumper link that selected where the power is coming from. These days this switch is automatically done by the electronics. See attached pictures of jumpers.

#### polymorph

The motor shield may have a jumper that connects the motor driver chip to the Arduino's 5V.

If you do not remove this jumper and you connect 9 or 12V to the Motor Power Input, you'll be applying this directly to the Arduino's 5V buss and fry it. If you have not removed the jumper and haven't fried your Arduino, it is probably because a small rectangular 9V battery can't supply much power.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8

#### MEKACI

#6
##### Apr 16, 2014, 10:49 pmLast Edit: Apr 16, 2014, 10:51 pm by MEKACI Reason: 1
I want to ask some more questions again to you now to clarify my mind ( thank you every much for answering my questions here patiently all the time ) :

When I take of this jumper ( at the above screenshot that is on my motor shield ) I can put 1 power supply to power shield and 1 power supply to my arduino at the same time without any problem, right ? thanks.

///////////////////////////////////////////////////////////////////////////////

Grumpy_Mike, what do you mean by " the -ve terminals should be connected together " , it will be like above picture ? if not, would you be more clear please ? thanks.

//////////////////////////////////////////////////////////////////////////////

One " 8 AA battery " is enough to move my 4 of above dc motor smoothly with a good acceleration that motor wants 9-12V ) ? I am asking because my tank weightness is 6 kg total, thanks.

//////////////////////////////////////////////////////////////////////////////

How much voltage and amper Arduino and motor shield solo itself handle ? thanks.

/////////////////////////////////////////////////////////////////////////////

Do you have any suggestions about what kind of dc motor I should use with how much rpm I need to move and accelerate my 6 kg tank ( for my tank project ) ? thanks.

#### Grumpy_Mike

Quote
Grumpy_Mike, what do you mean by " the -ve terminals should be connected together " , it will be like above picture ?

Yes.
Quote
How much voltage and amper Arduino and motor shield solo itself handle ?

No idea, have you a web site link it will say there.
Also the data sheet for the shield should answer the other question.

Quote
what kind of dc motor I should use with how much rpm I need

Not sure what you are asking. Recommending any one motor is a bit useless unless it is accessible for you. The RPM is not a parameter that affects the torque so I don't know what that has to do with it.

#### polymorph

Quote
When I take of this jumper ( at the above screenshot that is on my motor shield ) I can put 1 power supply to power shield and 1 power supply to my arduino at the same time without any problem, right ? thanks.

Yes, that is the jumper I thought you were talking about. Take that off and you can power the motors with their own supply.

The grounds will be connected together through the motor shield, as long as you connect both leads to the Ext_Pwr pins.

As for the current, the two outer ICs are the motor driver chips; read the numbers and Google for the datasheets. I think that might be the same motor shield that I have, it has two L293D chips on it. They are rated at 600mA max, 1.2A peak.

However, without a heatsink, they may get quite hot at 600mA.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8

#### polymorph

Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8

#### MEKACI

#10
##### Apr 17, 2014, 04:16 pmLast Edit: Apr 17, 2014, 10:09 pm by MEKACI Reason: 1
Friends, I have another problem now at my project. I have built a miniature testing robot  to make easier to observe my coding results. I was writing some part of codes for movement and rotation with button control ;however I am living with some problems.

This is the miniature testing robot :

The problems I am living is that :
" When I click the button it takes time to respond to move motors and light the leds too ,while I continue to push the button, it stops moving  then the motors moves again then stops again ". I don't know how to fix this problem. " Debounce " might help to fix this problem but I don't know how to apply successfully. When you are newbie and when you don2t know what to do ( which is right or not ) It is really hard to solve the problem ;and it is happening to me right now. You friends might help me please ? thanks.

This is a small video that shows my problem visually :

This the code I have written ( this is only the movement version )  :
Code: [Select]
`#include <AFMotor.h> AF_DCMotor motor1(1, MOTOR12_64KHZ); // create motor #2, 64KHz pwmAF_DCMotor motor2(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwmAF_DCMotor motor3(3, MOTOR12_64KHZ);   // create motor #2, 64KHz pwmAF_DCMotor motor4(4, MOTOR12_64KHZ);   // create motor #1, 64KHz pwmconst int buttonPin1 = 18;     // the number of the pushbutton pin for tank movement  backwardconst int buttonPin2 = 19;     // the number of the pushbutton pin for tank movement  forwardconst int buttonPin3 = 20;     // the number of the pushbutton pin for tank body rotation  turn around // const int buttonPin4 = 21;     // the number of the pushbutton pin for tank firing mechanism motor  at BB firingconst int ledPin1 =  14;      // the number of the LED pin to check if the button works properly for tank movement  backwardconst int ledPin2 =  15;      // the number of the LED pin to check if the button works properly for tank movement  forwardconst int ledPin3 =  16;      // the number of the LED pin to check if the button works properly for tank body rotation  turn around // const int ledPin4 =  17;      // the number of the LED pin to check if the button works properly for tank firing mechanism motor  at BB firing// variables will change:int buttonState1 = 0;         // variable for reading the pushbutton status for tank body movement  backwardint buttonState2 = 0;         // variable for reading the pushbutton status for tank body movement  forward int buttonState3 = 0;         // variable for reading the pushbutton status for tank body rotation  turn around // int buttonState4 = 0;         // variable for reading the pushbutton status for tank firing mechanism motor  at BB firingvoid setup() {    Serial.begin(9600);           // set up Serial library at 9600 bps      motor1.setSpeed(255);     // set the speed to 200/255          motor2.setSpeed(255);     // set the speed to 200/255          motor3.setSpeed(255);          motor4.setSpeed(255);                     pinMode(ledPin1, OUTPUT);        // initialize the LED1 pin as an output           pinMode(buttonPin1, INPUT);      // initialize the pushbutton pin as an input                     pinMode(ledPin2, OUTPUT);        // initialize the LED2 pin as an output:               pinMode(buttonPin2, INPUT);      // initialize the pushbutton pin as an input:             pinMode(ledPin3, OUTPUT);        // initialize the LED3 pin as an output:               pinMode(buttonPin3, INPUT);      // initialize the pushbutton pin as an input:           /*    pinMode(ledPin4, OUTPUT);        // initialize the LED4 pin as an output:      pinMode(buttonPin4, INPUT);      // initialize the pushbutton pin as an input: */}     void loop() {         // read the state of the pushbutton value:  buttonState1 = digitalRead(buttonPin1);       if (buttonState1 == LOW) {        // turn LED on:        digitalWrite(ledPin1, LOW);           motor1.run(RELEASE);      // stopped     motor2.run(RELEASE);      // stopped     motor3.run(RELEASE);      // stopped     motor4.run(RELEASE);      // stopped     delay(1000);      }  else {  digitalWrite(ledPin1, HIGH);         motor1.run(BACKWARD);      // turn it on going backward     motor1.setSpeed(255);     motor2.run(BACKWARD);      // turn it on going backward     motor2.setSpeed(255);     motor3.run(BACKWARD);      // turn it on going backward     motor3.setSpeed(225);     motor4.run(BACKWARD);      // turn it on going backward     motor4.setSpeed(255);                                   delay(1000);          }  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////    // read the state of the pushbutton value:  buttonState2 = digitalRead(buttonPin2);       if (buttonState2 == LOW) {        // turn LED on:        digitalWrite(ledPin2, LOW);           motor1.run(RELEASE);      // stopped     motor2.run(RELEASE);      // stopped     motor3.run(RELEASE);      // stopped     motor4.run(RELEASE);      // stopped     delay(1000);      }  else {  digitalWrite(ledPin2, HIGH);         motor1.run(FORWARD);      // turn it on going backward     motor1.setSpeed(255);     motor2.run(FORWARD);      // turn it on going backward     motor2.setSpeed(255);     motor3.run(FORWARD);      // turn it on going backward     motor3.setSpeed(225);     motor4.run(FORWARD);      // turn it on going backward     motor4.setSpeed(255);                                   delay(1000);          }///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  // read the state of the pushbutton value:  buttonState3 = digitalRead(buttonPin3);       if (buttonState3 == LOW) {        // turn LED on:        digitalWrite(ledPin3, LOW);           motor1.run(RELEASE);      // stopped     motor2.run(RELEASE);      // stopped     motor3.run(RELEASE);      // stopped     motor4.run(RELEASE);      // stopped     delay(1000);      }  else {  digitalWrite(ledPin3, HIGH);         motor1.run(FORWARD);      // turn it on going backward     motor1.setSpeed(255);     motor2.run(FORWARD);      // turn it on going backward     motor2.setSpeed(255);     motor3.run(BACKWARD);      // turn it on going backward     motor3.setSpeed(225);     motor4.run(BACKWARD);      // turn it on going backward     motor4.setSpeed(255);                                   delay(1000);  }}  `

I recorded this problem to video too : http://www.youtube.com/watch?v=HQpqamVdnIE&feature=youtu.be

Not :
Actually I wanted to use a potentiometer for movement and rotation but I didn't able to success ,while using adafruit  v1 motor shield library, and even I checked if there were any examples from internet  about dc motor control with a potentiometer with adafruit motor shield but there was nothing, only examples with dc motor + encoder or stepper motor + potentiometer/encoder )

#### Grumpy_Mike

OK- read the how to use this forum sticky post. Then go back and modify your post so that the it is posted correctly in code tags.

The software problem is caused by your use of the delay function. Do not use delay if you want to interrupt what is happening and make other things happen.
Look at the blink without delay for the technique and look at a finite state machine for further help.
This is a good place to start.
http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html

#### polymorph

Go, Grumpy_Mike.

This is why I'll continue to say that delay() is one of the worst things to teach a newbie as a first lesson. It has its uses.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8

#### MEKACI

This is the code I am using ;but it doesn't work properly. With 1 button control the dc motors as forward or whatever other movement rotations are working. However, when I want to use 2 or 3 buttons with debouncing method my miniature testing robot acts like really weird with below code.

Friends, would you show  me a 2 buttons control for my dc motors with debouncing please ? I am trying myself but need some help really( I am newbie ), thanks.

Code: [Select]
`#include <AFMotor.h>AF_DCMotor motor1(1, MOTOR12_64KHZ); // create motor #2, 64KHz pwmAF_DCMotor motor2(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwmAF_DCMotor motor3(3, MOTOR12_64KHZ);   // create motor #2, 64KHz pwmAF_DCMotor motor4(4, MOTOR12_64KHZ);   // create motor #1, 64KHz pwmconst int buttonPin1 = 18;     // the number of the pushbutton pin for tank movement  backwardconst int buttonPin2 = 19;     // the number of the pushbutton pin for tank movement  forwardconst int buttonPin3 = 20;     // the number of the pushbutton pin for tank body rotation  turn around // const int buttonPin4 = 21;     // the number of the pushbutton pin for tank firing mechanism motor  at BB firingconst int ledPin1 =  14;      // the number of the LED pin to check if the button works properly for tank movement  backwardconst int ledPin2 =  15;      // the number of the LED pin to check if the button works properly for tank movement  forwardconst int ledPin3 =  16;      // the number of the LED pin to check if the button works properly for tank body rotation  turn around // const int ledPin4 =  17;      // the number of the LED pin to check if the button works properly for tank firing mechanism motor  at BB firing// variables will change:int buttonState1 = 0;         // variable for reading the pushbutton status for tank body movement  backwardint buttonState2 = 0;         // variable for reading the pushbutton status for tank body movement  forward int buttonState3 = 0;         // variable for reading the pushbutton status for tank body rotation  turn around // int buttonState4 = 0;         // variable for reading the pushbutton status for tank firing mechanism motor  at BB firing// Variables will change:int ledState1 = LOW;         // the current state of the output pinint ledState2 = LOW;         // the current state of the output pinint ledState3 = LOW;         // the current state of the output pin// int ledState2 = LOW;         // the current state of the output pinint lastButtonState1 = LOW;   // the previous reading from the input pinint lastButtonState2 = LOW;   // the previous reading from the input pinint lastButtonState3 = LOW;   // the previous reading from the input pin// int lastButtonState4 = LOW;   // the previous reading from the input pinint lastReading1= LOW;int lastReading2= LOW;int lastReading3= LOW;// int lastReading4= LOW;// the following variables are long's because the time, measured in miliseconds,// will quickly become a bigger number than can be stored in an int.long lastDebounceTime1 = 0;  // the last time the output pin was toggledlong lastDebounceTime2 = 0;  // the last time the output pin was toggledlong lastDebounceTime3 = 0;  // the last time the output pin was toggled// long lastDebounceTime4 = 0;  // the last time the output pin was toggledlong debounceDelay1 = 50;    // the debounce time; increase if the output flickerslong debounceDelay2 = 50;    // the debounce time; increase if the output flickerslong debounceDelay3 = 50;    // the debounce time; increase if the output flickers// long debounceDelay4 = 50;    // the debounce time; increase if the output flickersvoid setup() {  pinMode(buttonPin1, INPUT);  pinMode(ledPin1, OUTPUT);    pinMode(buttonPin2, INPUT);  pinMode(ledPin2, OUTPUT);    pinMode(ledPin3, OUTPUT);        // initialize the LED3 pin as an output:      pinMode(buttonPin3, INPUT);      // initialize the pushbutton pin as an input:    /*    pinMode(ledPin4, OUTPUT);        // initialize the LED4 pin as an output:      pinMode(buttonPin4, INPUT);      // initialize the pushbutton pin as an input: */   motor1.setSpeed(255);     // set the speed to 200/255  motor2.setSpeed(255);     // set the speed to 200/255  motor3.setSpeed(255);  motor4.setSpeed(255);}void loop() {  // read the state of the switch into a local variable:  int reading1 = digitalRead(buttonPin1);  // check to see if you just pressed the button   // (i.e. the input went from LOW to HIGH),  and you've waited   // long enough since the last press to ignore any noise:    // If the switch changed, due to noise or pressing:  if (reading1 != lastReading1) {    // reset the debouncing timer    lastDebounceTime1 = millis();    // save the reading.  Next time through the loop,    // it'll be lastReading:    lastReading1 = reading1;  }     if ((millis() - lastDebounceTime1) > debounceDelay1) {    // whatever the reading is at, it's been there for longer    // than the debounce delay, so accept the button state change:      // toggle the LED if the state of the button changes from LOW to HIGH:    if (lastButtonState1 == LOW && reading1 == HIGH) {      if (ledState1 == HIGH) {        ledState1 = LOW;      } else {        ledState1 = HIGH;      }      digitalWrite(ledPin1, ledState1);    }    lastButtonState1 = reading1;        // read the state of the pushbutton value:     buttonState1 = digitalRead(buttonPin1);       if (buttonState1 == LOW) {         // turn LED on:        digitalWrite(ledPin1, LOW);           motor1.run(RELEASE);      // stopped     motor2.run(RELEASE);      // stopped     motor3.run(RELEASE);      // stopped     motor4.run(RELEASE);      // stopped     delay(1000);       }   else {   digitalWrite(ledPin1, HIGH);         motor1.run(BACKWARD);      // turn it on going backward     motor1.setSpeed(255);     motor2.run(BACKWARD);      // turn it on going backward     motor2.setSpeed(255);     motor3.run(BACKWARD);      // turn it on going backward     motor3.setSpeed(225);     motor4.run(BACKWARD);      // turn it on going backward     motor4.setSpeed(255);                                    delay(1000);          }  }    /////////////////////////////////////////////////////////////////////////////////    int reading2 = digitalRead(buttonPin2);  // check to see if you just pressed the button   // (i.e. the input went from LOW to HIGH),  and you've waited   // long enough since the last press to ignore any noise:    // If the switch changed, due to noise or pressing:  if (reading2 != lastReading2) {    // reset the debouncing timer    lastDebounceTime2 = millis();    // save the reading.  Next time through the loop,    // it'll be lastReading:    lastReading2 = reading2;  }     if ((millis() - lastDebounceTime2) > debounceDelay2) {    // whatever the reading is at, it's been there for longer    // than the debounce delay, so accept the button state change:      // toggle the LED if the state of the button changes from LOW to HIGH:    if (lastButtonState2 == LOW && reading2 == HIGH) {      if (ledState2 == HIGH) {        ledState2 = LOW;      } else {        ledState2 = HIGH;      }      digitalWrite(ledPin2, ledState2);    }    lastButtonState2 = reading2;    // read the state of the pushbutton value:  buttonState2 = digitalRead(buttonPin2);       if (buttonState2 == LOW) {         // turn LED on:        digitalWrite(ledPin2, LOW);           motor1.run(RELEASE);      // stopped     motor2.run(RELEASE);      // stopped     motor3.run(RELEASE);      // stopped     motor4.run(RELEASE);      // stopped     delay(1000);       }   else {   digitalWrite(ledPin2, HIGH);         motor1.run(FORWARD);      // turn it on going backward     motor1.setSpeed(255);     motor2.run(FORWARD);      // turn it on going backward     motor2.setSpeed(255);     motor3.run(FORWARD);      // turn it on going backward     motor3.setSpeed(225);     motor4.run(FORWARD);      // turn it on going backward     motor4.setSpeed(255);                                    delay(1000);          }      }`

#### polymorph

Read all the button states at the beginning of your code, then perform all tests.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8