How many arduino timers are dedicated to electric motor control

Hello everyone!

I'm working on a project, which my main goal at the moment is to control 4 dc electric motors. I am using arduino uno, but then I realized it only had 2 timers, so I was only capable to control 2 motors (timer 0 is not advised for motor control).. My question is: Arduino mega2560 has - Digital I/O Pins 54 (of which 15 provide PWM output) and 5 timers. But of these 5 timers, could you tell me how many can I use, or are recommended to control motors (if I'm thinking correctly I will need 4 timers for the 4 motors) ?

Fortunately the code I made to control the speed of the dc motor with arduino uno will not be completely thrown away.. the logic doesn't seem to change. As far as I'm concerned the only difference is in the number of timers, pins and memory.

Thanks!

If by motor control you mean PWM then all three timers are used to give you 6 pins capable of PWM.

I don't know why you want timers to control a motor over and above its use as PWM.

Thanks Grumpy_Mike Yes, the motor control was made trough PWM. I only said I could use 2 timers of arduino uno (instead of the 3), because I read timer0 was not recommended for this purpose. However, it wasn't explained the reason why it was only advised to use timer1 and timer2.. But with 3 timers I can't control four 24V motors.

I don't know why you want timers to control a motor over and above its use as PWM.

That's because the driver I'm using requires a standard frequency of 16KHz. So, I need to use them to have more than the 500Hz. Sorry, for not having been more clear in my previous comment.

Do you recommend arduino mega2560? I hope I can use at least 4 of the 5 timers available to control the 4 dc motors.. By the way, I didn't mention arduino due, because it has an operating voltage = 3.3V. But if used a Logic Level Converter I think there wouldn't be a problem

The Mega has 14 PWM pins. You have:- Peripheral Features – Two 8-bit Timer/Counters with Separate Prescaler and Compare Mode – Four 16-bit Timer/Counter with Separate Prescaler, Compare- and Capture Mode – Real Time Counter with Separate Oscillator – Four 8-bit PWM Channels – Six/Twelve PWM Channels with Programmable Resolution from 2 to 16 Bits according to the data sheet.

But with 3 timers I can't control four 24V motors.

Why not. Each timer supports two PWM pins so using timers 1 and 2 will give you what you want.

Sorry, for not having been more clear in my previous comment.

Yes you should have.

Why not. Each timer supports two PWM pins so using timers 1 and 2 will give you what you want.

  • The motor goes Clockwise and Counter-clockwise. For instance, if I want to move the motor at a certain speed in one direction I use pin3 of timer2, and to move in another direction I will need pin11. So, I'm using the 2 pins available of timer 2, just to move one motor in both directions. That's why I'm saying I think I will need 4 timers to control 4 motors.
  • The driver itself asks for 2 pins, 1 for Left PWM Input and the other pin for Right PWM Input.

The Mega has 14 PWM pins.

Yes, it has even more than arduino due, and the operating voltage is 5V, so I wouldn't have to spend any money on a Logic Level Converter :)

I'm still not sure if I would be able to use the same pwm mode ( fast pwm mode 3) to control the 4 motors, just with arduino mega2560..

So, I’m using the 2 pins available of timer 2, just to move one motor in both directions.

So you are doing it wrong.
You only need one PWM pin to control the speed of one motor.
If you have a H-bridge chip then there is often a direction pin and an enable pin. Wire the enable pin to the PWM for speed control, the direction pin does not have to be PWM capable.

If you do not have an enable pin on your H-bridge then simply make one pin PWM and the other not. The only down side to this will be that the PWM value for clockwise and anti clockwise motion for the same speed will be inverted. But you can simply take care of that in software.