I'm not sure if I should put this in the programming or electronic section, as it depends on the solution.
I have 4 dc motors and an UNO REV 3, I have one pin to an "input A" and one pin to "input B" on a L298N style driver, 1 for each of 2 pairs of motors.
The only way to control speed my drivers are to use PWM or hardwire in some sort of voltage control.
However, I also need to control speed when reversing. This means as far as I can tell I need 8 pins with PWM. As I send PWM signals to A for forward, and B for reverse. (with LOW or 0 for the opposing pin of course)
Is it possible to control speed of a motor with only 1 PWM pin with this setup? I feel like I am missing something.
However, I also need to control speed when reversing. This means as far as I can tell I need 8 pins with PWM. As I send PWM signals to A for forward, and B for reverse. (with LOW or 0 for the opposing pin of course)
You would, if your car had two gas pedals - one for forward and one for reverse.
Of course it doesn't. And, yet you can manage to go forward at varying speeds and go backwards at varying speeds. It all depends on what position the direction pin is in. Oh, wait, I meant shift lever.
The direction pin controls forward or backwards. The speed pin controls the speed, regardless of which direction you are going.
Oh, I never realized they had one pin for speed and one for direction when you only had 2. I thought they were defining direction by reversing polarity (thus HIGH/LOW vs LOW/HIGH for forwards vs reverse).
But then how does setting it to Low/High work? Wouldn't that be zero speed, in reverse direction? Yet it works.
Unlike your car, the speed controller doesn't have a Park setting or a neutral setting. It only has forward and reverse. HIGH means one direction. LOW means the other direction.
You stop be setting the speed to 0. Doesn't matter whether you are not moving forwards or not moving backwards. Stopped is stopped.
An L298 has 3 inputs IN1 IN2 and ENA for each motor. You can use the IN1 and IN2 pins for direction control and supply PWM to the ENA pin - so you only need 1 PWM output per motor.
PaulS:
You stop be setting the speed to 0. Doesn't matter whether you are not moving forwards or not moving backwards. Stopped is stopped.
I'm sorry, could you rephrase this? I'm afraid not quite following.
At High/Low the motor goes forwards, at Low/High it goes backwards. However, it also goes backwards at I.E analog output of 100/High. Doesn't low equal 0? Then how can it go backwards if the first pin is speed and set to 0?
Robin2:
An L298 has 3 inputs IN1 IN2 and ENA for each motor. You can use the IN1 and IN2 pins for direction control and supply PWM to the ENA pin - so you only need 1 PWM output per motor.
...R
I'm not using the standard setup, I'm using a miniaturized variant with only 2 inputs, like these: 1.5a Mini Dual Channel DC Motor Driver Module Beyond L298n PWM Speed Control for sale online | eBay
They seem to support PWM signals to both pins, but I cannot quite grasp how it logically handles both speeds and direction through the same pins, since multiple methods I've used so far works. I mean, I guess that not really a "problem", but I'd still like to understand it.
Graylord:
I'm not using the standard setup, I'm using a miniaturized variant with only 2 inputs,
Then you need two PWM signals per motor or some external circuitry that can steer a single PWM pulse to the appropriate pin depending on the selected direction.
Robin2:
Then you need two PWM signals per motor or some external circuitry that can steer a single PWM pulse to the appropriate pin depending on the selected direction.
I'm sorry, could you rephrase this? I'm afraid not quite following.
Go get in your car. Put it in reverse. Do NOT start the engine. How fast are you going?
Shift into drive. How fast are you going?
If you determined that you were going at a speed other than 0 in drive or reverse, you need to get your car fixed.
If you are backing down the driving, with the engine running, and lift off the gas pedal (PWM value is 0) don't you coast to a stop? If you shift into drive, without touching the gas pedal, does your car move? The PWM value is still 0, but the direction changed. You should still be stopped.
You appear to be missing the point, I'm telling you with the input to "a" at 255 and "b" at High, the motor literally IS going backwards. It ALSO IS going backwards at "a" at Low and "b" at high.
I'm not saying anything about the logistics of how it should be, I'm saying what the motor literally does.
Pin a which supposedly should be speed, seems to give a max speed at low with b at high, even though low equals 0. I can mix and match, but I cannot get it to make sense.
The motor shields I am familiar have ONE direction pin and ONE speed pin, for each motor that they control. I do not understand why yours appears to have so many pins to control one motor's speed and direction.
PaulS:
The motor shields I am familiar have ONE direction pin and ONE speed pin, for each motor that they control.
You have had a very limited experience then.
Quite a few of them have two equal inputs such that when A is HIGH and B is LOW the motor rotates one way and when A is LOW and B is HIGH it rotates the other way. For example the Pololu DRV8833 and the Infineon TLC 5206. With those sorts of drivers you need two PWM signals for bi-directional control.
I believe the OP's board also behaves like that, although the more usual L298 boards do behave a bit like you suggest - except that they separate pins for the two directions.
I think I'm starting the get a grasp of the logistics of it. It just seems to be versatile in the sense that you can both use PWM signal values or just high low, but also mix them and it will make it work. If you only have power applied to the reverse signal, it will assume you want to run it, and just simply make the motor go with no regard to speed. But you can set a specific also for speed by sending a specific PWM signal to the opposing pin. The inputs work as both speed and depeding on the combination of inputs.
Graylord:
But you can also for speed by sending a specific PWM signal to the opposing pin.
I think you are over complicating it.
If it goes in reverse with a HIGH on one pin and a LOW on the other, then for speed control just apply the PWM to the pin that you have HIGH. HIGH is exactly the same as analogWrite(255) and LOW is the same as analaogWrite(0)
Unless i want it to reverse at a specific speed it seems.
(Without using a PWM pin for both, I forgot to mention that I only got a PWM pin to A, otherwise I'd use 8 PWM pins, now I only need 4, and it seems to work, I just need to do reverse with power to both pins.
Graylord:
However, I do not have PWM signals to the second input.
But the driver allows me instead to do:
When you have B2 HIGH and apply analogWrite() to B1 it will work "upside down" in the sense that the power will be cut when the PWM signal is HIGH so that analogWrite(10) should result in fast movement and analogWrite(200) should result in slow movement.
If that works OK then it seems you have a solution. However I suggest you read the driver datasheet very carefully because some drivers treat HIGH on both pins differently from LOW on both pins.