Redirect PWM signal

Hi y'all!!

This is my first question here, with many more to come :slightly_smiling_face: . I am a student mechanical engineer with a fascination for building with motorized technic lego. The lego motor control units, such as IR recievers, mindstorm bricks etc, are expensive and can only control a few motors. Since my builds are getting bigger, I am trying to make a controller based on an arduino mega 2560.

I plan to use H bridge boards to control the motors. I want to control most of the motors with a PWM signal. Most of the available H bridges are controlled by a signal to turn left and a signal to turn right. If I were to control the bridges directly, i would need two PWM ports for each motor. Since there are not a lot of PWM ports on the mega (12 if im correct) but there are a lot of standard digital ports on it, is there a way to redirect the PWM signal from one port to another? So lets say I have a PWM signal on port 2, and I want to direct it to port 21 (turn right) or port 22 (turn left). how would I do that?

short: How to redirect a PWM signal to a non PWM port?

I am sorry if this has already been discussed, but I hope some of you can point me in the right direction, thankyou!

My limited experience of H bridges has been that for each channel there is control of direction using 2 inputs and speed using a single input to the enable pin. A PWM signal is only required on the single enable pin.

What is it that makes you believe that 2 PWM inputs are needed for each channel ?

In any case, the number of PWM outputs on the Mega is constrained by the available hardware and the internal PWM cannot be mapped to other pins. Even if it could then the total number of PWM outputs would still be limited by the available hardware of the chip

One PWM signal is sufficient for each motor. H-bridges have a separate digital direction pin. So a Mega can control 12 DC motors, and if you need feedback for controlled RPM this will be enough work for a single controller. For Servo motors see the Servo library.

thanks for the information! so with a L298N driver I should be set?

That's stone age technology. Consider using newer MOSFET H-bridges.

OK, so what is a better driver? I would prefer a low cost, compact one. what would you recommend?

What voltage, what current?
Chips or break out or...?

oh right sorry.

I think a breakout board is best. 12 volts and 2 amps.

Now you can start Google :slight_smile:

Hi
From your initial explanation, I will infer that they are small motors.
I use the L9110 chip in many projects, this chip is a small H-bridge.
It supports up to 12V and a current of 800mA.
He's very small.
ref:

PS: module with 2 L9110

thankyou, but I think 800 mA is not enough. The motors would not draw more than 800 mA in normal use, but when heavily used they consume more than that, sometimes around 2 Amps. source: LEGO 9V Technic Motors compared characteristics. so I need a heavier driver.

Hi
To run motors of up to 2A, the ideal would be a bridge H of twice the current.
This chip supports up to 5A.
I don't know how difficult it is to find it.
ref:

Thankyou, I think this is sufficient. I will keep you updated!

Even if there is no 'enable' pin you can still get speed and direction control with only one PWM pin:

const byte CWPin = 6; // PWM
const byte CCWPin = 7; // Non=PWM

void motor(bool dirtectionCW, byte speed)
{
  if (directionCW)
  {
    digitalWrite(CWPin, speed);
    digitalWrite(CCWPin, LOW);
  }
  else // CCW
  {
    digitalWrite(CWPin, 255 - speed);
    digitalWrite(CCWPin, HIGH);
  }
}