How to get more PWM Pins on the Arduino Mega?

I want to be able to control 6 NEMA17 Stepper motors and 15 digital servo motors but my Arduino Mega only has 12 PWM pins. I am using an Arduino Mega 2560 and I am using TB6600 Stepper motor drivers to control the stepper motors. Each stepper motor requires 3 PWM pins (ENA pin, DIR pin, and PUL pin), and each of the servo motors also require 1 PWM pin. How can I control 6 stepper motors and 15 servo motors together with an Arduino Mega?

Neither steppers or servos need PWM pins.

Where did you get the idea that those motors need PWM pins?

Welcome to the forum

What makes you say that ?

Controlling a servo does not require a PWM pin

How will they be controlled by the Arduino if they don't use PWM?

In the case of servos by the servo library.

For stepping motors then a stepping motor driver is often used. This a hardware board.

I'm using TB600 Stepper motor drivers but they still need 3 PWM pins. I used these drivers with 2 stepper motors, powered them with 12v, 10 amps, and wired the 3 PWM pins and they worked fine.

Stepper motor basics.

Simple stepper motor control code.

Libraries for steppers with step/dir type drivers (like the DRV8825).
AccelStepper (powerful, some learning curve)

MobaTools stepper (easier to learn)

TB6600 driver do not need PWM pins. Please tell us where you got the notion that they do. The step, dir and enable are digital (on-off) signals. Any GPIO pin can be used for those signals (including the analog inputs)

I searched on YouTube how to wire a TB6600 stepper motor to Arduino. They showed how to wire coil A and B of the stepper to the driver and connect the Pul -, Ena -, and Dir-, to ground. Then it says to take the positives of those pins and connect it to PWM pins on the Arduino.

A link to the Youtube video, please.

Anyway that is not right. You can wire step, dir and en to any GPIO pin. The you tell the library what pins and off you go.

Ok, ill go look for the video. He just used PWM pins for the video so I'm not sure if you need to use PWM pins.

Does the associated code do anything but use them as digital pins ?

I just set integers for each of the three pins and then set them to outputs.

Are you trying to tell me that I can use any pin on the board as the DIR pin, ENA pin, and PUL pin?

In the video the pins used are 10, 11 and 12

Pin 12 is not actually a PWM pin in any case

Yes, even the A* pins used in digital mode

Oh, so since I'm using an Arduino Mega can I use any of the digital pins 13 - 50 as the DIR, ENA, and PUL pins?

Yes, any digital pin or an A* pin used as a digital pin

Ok, Thank You. I'll try using the digital pins instead.

Or 2 through 12 as well.