Go Down

### Topic: The motor runs at half the speed (Read 5085 times)previous topic - next topic

#### rva1945

##### May 10, 2014, 04:00 am
Hi:

I read the pulse (1 to 2 ms) and map it to a -255,255 range. Then I analogWrite the absolute value (abs()) in the pin that goes to the enable pin in a L293. But the motor barely run at half the speed. The battery is well charged because if I connect the motor directly to it it will run at the right speed.

What am I doing wrong?

Thanks

#### raschemmel

#1
##### May 10, 2014, 04:17 am
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

#### jremington

#2
##### May 10, 2014, 04:20 am
You need to provide information about the power supply and the motor voltage and current requirements. A circuit diagram would help. The L293 needs protective diodes and is limited in the amount of motor current that it can handle.

#### rva1945

#3
##### May 10, 2014, 04:23 am

Code: [Select]
`chThr = pulseIn(pinchThr, HIGH) // READ RC PULSE FROM PIN pinchThr;.// MAP IT FROM 1000,2000 TO -255,255 (1000,2000 MAY VARY AFTER CALIBRATION)pwm_M1 = map(chThr,minPulseWidthThr,maxPulseWidthThr,-minMaxPWM,minMaxPWM);`
.
//  SEND PULSE TO ENABLE PIN IN A L293B
analogWrite(pinpwm_M1,abs(pwm_M1))

#### rva1945

#4
##### May 10, 2014, 04:30 am

You need to provide information about the power supply and the motor voltage and current requirements. A circuit diagram would help. The L293 needs protective diodes and is limited in the amount of motor current that it can handle.

The motors are FF-050 from CD-ROM, very stable and quiet motors, not even capacitors are needed with these ones. At stall, they draw less than 400mA, and the L293B is capable of handling 1 amp per motor.

#### raschemmel

#5
##### May 10, 2014, 04:35 amLast Edit: May 10, 2014, 04:39 am by raschemmel Reason: 1
Your problem is you don't understand the difference between a servo signal (RC pulse) and PWM . The servo signal has a center frequency of 1500uS and only varies */- 500 uS.. You can't send negative PWM values .
Code: [Select]
`  // MAP IT FROM 1000,2000 TO -255,255 (1000,2000 MAY VARY AFTER CALIBRATION)pwm_M1 = map(chThr,minPulseWidthThr,maxPulseWidthThr,-minMaxPWM,minMaxPWM); `

Your PWM range must be 0 to 255. It doesn't accept negative values.

Quote
In other words, with Arduino's PWM frequency at about 500Hz, the green lines would measure 2 milliseconds each. A call to analogWrite() is on a scale of 0 - 255, such that analogWrite(255) requests a 100% duty cycle (always on), and analogWrite(127) is a 50% duty cycle (on half the time) for example.

http://arduino.cc/en/Tutorial/PWM
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

#### rva1945

#6
##### May 10, 2014, 04:40 am

Your problem is you don't understand the difference between a servo signal (RC pulse) and PWM . The servo signal has a center frequency of 1500uS and only varies */- 500 uS.. You can't send negative PWM values .
Code: [Select]
`  // MAP IT FROM 1000,2000 TO -255,255 (1000,2000 MAY VARY AFTER CALIBRATION)pwm_M1 = map(chThr,minPulseWidthThr,maxPulseWidthThr,-minMaxPWM,minMaxPWM); `

Your PWM range must be 0 to 255. It doesn't accept negative values.

Well, according to this: http://arduino.cc/en/Reference/Map

"The function also handles negative numbers well, so that this example
y = map(x, 1, 50, 50, -100);
is also valid and works well."

#### raschemmel

#7
##### May 10, 2014, 05:11 amLast Edit: May 10, 2014, 05:39 am by raschemmel Reason: 1
I didn't say the Map function could not use negative numbers. I said the AnalogWrite (and motor control Enable pins that accept PWM)
do not take negative numbers. .If you want the motor to turn the opposite direction you need to change the state of the direction pin. .You did not post your entire code so we don't know what "pwm_M1" mean other than what the name says it means, which is a PWM input to a motor control that only accepts PWM. We don't know what you are doing with this pwm_M1 AFTER the Map function because you didn't post your entire code. We can only assume that you are using it as the argument for an analogWrite statement, because there is no other way to get a PWM signal (short of bit banging) from the arduino to a motor control. If you post your ENTIRE code then maybe we can figure out what is going wrong. I am simply saying that although the Map function has no problem at all with negative numbers, they are not valid for analogWrite statements. (which of course, without your code, we don't know if that is what you are using the pwm_M1 for).
(which is another way of saying there is no such thing as a negative TTL PWM signal.)
I just saw this , which confirms the above:
Quote
//  SEND PULSE TO ENABLE PIN IN A L293B
analogWrite(pinpwm_M1,abs(pwm_M1))

Quote
Example

/* Map an analog value to 8 bits (0 to 255) */
void setup() {}

void loop()
{
val = map(val, 0, 1023, 0, 255);
analogWrite(9, val);
}

Do you see any negative values for the analogWrite() statement ?
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

#### rva1945

#8
##### May 10, 2014, 03:23 pm
As you can see, I am not using negative values for the analogWrite function. I'm using abs() to take the absolute value (which is always equal or greater than zero). And when the value es negative, I enable the pin that makes the motor turn in the opposirte direction. All of that is working, the motor turn proportionally from zero (RC stick in the middle) to maximum in both directions.

The problem is that it will never run at max speed. I took the example from here:
https://www.sparkfun.com/tutorials/348

He is doing basically the same, though he uses the -500,500 range:
Code: [Select]
`Serial.println(map(ch2, 1000,2000,-500,500)); // center at 0`

(just printing the values, he is not driving a motor here, but it's the same idea.)

I tried with -500,500 to worse results.

Blaming it to the L293B driver, I swapped the pin (HIGH or LOW, no PWM here)  that goes to the input (direction) to the enable pin in the L293B and the motor ran at full speed.

Besides that, LEDS (and resistor) are wired in parallel with the outputs to monitor the activity: 2 LEDS wired to the Arduino OUTPUT PINS that go to the L293B INPUTS for direction, and 1 LED from the Arduino OUTPUT PIN that goes to the ENABLE PINS in the L293B, these ones the PWM for speed control.

Is there something else about analogWrite() I don't know?

#### rva1945

#9
##### May 10, 2014, 03:34 pm
Ok, I didn't want to bother you adding all my code, but when I trid it says that it exceeds the allowed length (9500 characters)..

But later I found that someone uses constrain() after map():

turn = map(ch1,1000,2000,-500,500);
turn = constrain(turn, -255, 255);

I will try it later.

#### TomGeorge

#10
##### May 10, 2014, 03:52 pmLast Edit: May 10, 2014, 03:55 pm by TomGeorge Reason: 1
Hi, you can post your sketch as an attachment.
Have to checked that 255 written directly to the PWM pin will produce full speed.
Let make sure its not hardware thats the problem, a simple code change will check it.

Have you written all this program at once or did you create it section by section testing it as you build?
Just write a program that controls the motor and see if that works, then build from there.

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

#### rva1945

#11
##### May 10, 2014, 04:45 pm
How do I post the sketch as an attachment? I don't see a button for that purpose. Or should  send you a message with the attachment?

#### MarkT

#12
##### May 10, 2014, 05:29 pm

Hi:

I read the pulse (1 to 2 ms) and map it to a -255,255 range. Then I analogWrite the absolute value (abs()) in the pin that goes to the enable pin in a L293. But the motor barely run at half the speed. The battery is well charged because if I connect the motor directly to it it will run at the right speed.

What am I doing wrong?

Thanks

Using an L293.

This chip has darlington output drivers, which waste 1.0 to 1.5V each (top
and bottom) when carrying significant current, so yout motor will see about 2.5V
less than the battery/supply voltage.  You either have to allow for that by using
a higher supply voltage or change to using a better driver chip such as a MOSFET
H-bridge.  (I assume you have about 6V supply and 6V motor?)

And if its the L293B (as opposed to L293D) its essential to use 4 free-wheel
diodes as shown in the datasheet or you can damage/destroy the driver.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

#### rva1945

#13
##### May 10, 2014, 05:32 pm
Now I understand the output drop after cascading in the darlington scheme, I know what you are talking about.

Yes a MOSFET H bridge would give me (almost?) 100% of power.

I'm not using the diodes as these motors are really "weak" and don't spike, but I will consider it.

Thanks

#### rva1945

#14
##### May 10, 2014, 05:37 pm
Anyway the LEDS connected to the out pins (PWM)  bright dimly as compared to the leds connected to the pins (HIGH/LOW) that control the motors direction.

So before reaching the L239 I can see that the pulses don't seem to be 100% high of the duty cycle. But I do see that the pulse sent to the motors is 255 at full speed.

Go Up