Doing PWM on multiple (> 3) motors

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Many AVR devices have nice PWM timer modes, which I found out about using after generating servo pulses the harder way. I've seen servo control projects where PWM wasn't available controlling 8 or more servos, implementing a list of servo set positions and toggling the output based on those set positions to make each pulse the correct width, all controlled by one timer.

Now I'm thinking about motor control. If I was doing PWM control of < 3 motors on an AVR with 3 PWM timers it would be easy. What about more motors? Can the following approach work?

- use byte array to hold fan states
- fill array with initial states, i.e. 0 = off, 4 = full speed for a four-speed system
- Decide on frequency of PWM to suit motors
- Use timer to produce interrupts giving required granularity of control (e.g. 100Hz PWM with four speed levels requires 400Hz, four interrupts per cycle)
- all motors start in off state
- on each interrupt, increment a static interrupt count. When it reaches the number of levels, i.e. 4, reset it to 0. When the count is 0 set each motor with a non-zero value in the array on, when the count exceeds the value for a motor in the array turn it off.

Is there a better way? I'd really like constructive criticism or to hear how others have done it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think the simplest approach would be to dedicate a port for PWM-output. Each bit in the port represents a PWM channel so you can have 8 outputs max. The output-state for each cycle is defined in a byte. b0=motor0, b1=motor1 etc. This will cost you 4 bytes for a 4-level granularity.
The interrupt-idea is fine. In my case, the IRQroutine should only output the next byte to the assigned port.
After sending byte 0-3, the cycle is restarted.

Speed can be adjusted by modifying the contents of the data written to the PWM-port.

regards,
Leo