Go Down

Topic: L9110 H-Bridge Speed control (Read 4175 times) previous topic - next topic

rhj4

I ave read many articles on the L9110 H-Bridge. It has only two pins per motor: DIR and PWM. Code examples vary. Some say use digitalWrite(DIR, HIGH/LOW) and use an analogWrite(PWM, speed); I have even found some that say use analog writes for both, but that simply doesn't work. 

Here is my confusion. Controlling direction is easy: DIR == HIGH --> Forward, DIR == LOW --> Backward; However, setting the PWM pin to a speed value in the range 0..255 works for forward, but when I try backward, the motor starts for a second, then stops.

Here is the code:

Code: [Select]
void L9110_Motor::forward(unsigned int speed) {
_direction = Forward;
_speed = speed;
digitalWrite(_DIR, HIGH);
analogWrite(_PWM, (int)_speed);
}
[code]void L9110_Motor::backward(unsigned int speed) {
_direction = Backward;
_speed = speed;
digitalWrite(_DIR, LOW);
analogWrite(_PWM, _speed);
}

void L9110_Motor::setSpeed(unsigned int speed) {
int oldSpeed = getRealSpeed();  // analogRead(_PWM)

_speed = speed;
analogWrite(_PWM, (int)speed);
int newSpeed = getRealSpeed();
Serial.print(F("\nOLD: ")); Serial.print(oldSpeed);
Serial.print(F("\tNEW: ")); Serial.print(newSpeed);
Serial.print(F("\tDLTA: ")); Serial.println(newSpeed - oldSpeed);
}




[/code]

The setSpeed highlights this problem. No matter What values I use to set the speed, the  "real speed" as read by analogRead(_PWM) doesn't change. So I cannot go backwards and I cannot set the speed. 

What am I missing here?

sherzaad

I ave read many articles on the L9110 H-Bridge. It has only two pins per motor: DIR and PWM.

lookin the datasheet here I would say that that statement is incorrect

from what I could understand from the datasheet is that to be able to run the motor in either direction, IA and IB need to be opposites
ie IA = NOT(IB).

that would mean all you need to control the motor speed is to send analogWrite(_PWM, _speed) to 'IA' and the inverted PWM to 'IB' to run the motor one way.

to go the other way send analogWrite(_PWM, _speed) to 'IB' and the inverted PWM to 'IA'

hope that helps

rhj4

Would you please share the datasheet you are taking this from?

Thanks!

sherzaad

#3
May 13, 2018, 10:24 am Last Edit: May 13, 2018, 08:46 pm by sherzaad
Would you please share the datasheet you are taking this from?

Thanks!

postd the link. just click on 'here' in my previous post! :)

https://www.elecrow.com/download/datasheet-l9110.pdf

Have a look at the truth table, can you see why your code might not work?



one more thing; analogRead does not return the average voltage resulting from the PWM output but the instantaneous value ie either the HIGH or LOW value.

what you could try is something like this in a simple sketch with pre-set 'speed' values to see what happens:

Forward:
digitalWrite(IA, LOW);
analogWrite(IB, speed);

Reverse:
digitalWrite(IB, LOW);
analogWrite(IA, speed);

OR....
Forward:
digitalWrite(IA, LOW);
analogWrite(IB, speed);

Reverse:
digitalWrite(IA, HIGH);
analogWrite(IB, 255-speed); //can you guess why we subtract from 255? :)

apologies for the many re-writes of my post... brains working abit slow today! :)


Go Up