I have been working on a project where I have to control many DRV8871s from Adafruit (motor drivers). These drivers have 2 PWM inputs and I need to control 6 of them, so I need 12 PWM outputs on the Arduino. To avoid audible noise created by PWM, I need frequencies above 17.5khz.
I thought I could use the timers of an Arduino Mega for that purpose, but because it has "only" 6 timers I didn't find a way to run all of the PWM independently at the required frequency.
A PCA9685 or similar would be an option, but the top frequency is 1.6khz as far as I know.
I tried a 74HC595 shift register and a library called ShiftRegister PWM from Timo Denk, but the max frequency with a decent resolution doesn't reach that high values.
I ran out of ideas, maybe someone of you has a solution to this problem. Thank you very much!
Looking at the ESP32 pinout there are more than 12 GPIO's available on PortA.
The LED API for the ESP32 LED Control - ESP32 - — ESP-IDF Programming Guide latest documentation can be driven up to 40Mhz.
You can also see, in the ESP32 API docs, that the MCPWM API is able to drive up to 40Mhz as well.
Thank you Idahowalker, I will take a look to the ESP32 for that purpose.
I didn't find a way to run all of the PWM independently at the required frequency
The important requirement is to control the Duty Cycle of each PWM output independently. They can all have the same frequency, they do not need independent frequencies.
Most timers on Mega control 2 or 3 pins. So you need 5 timers to exceed 17.5KHz to give you 12 PWM pins with high enough frequencies on Mega.
TCCR1B = TCCR1B & B11111000 | B00000001;
TCCR2B = TCCR2B & B11111000 | B00000001;
TCCR3B = TCCR3B & B11111000 | B00000001;
TCCR4B = TCCR4B & B11111000 | B00000001;
TCCR5B = TCCR5B & B11111000 | B00000001;
should give you 31KHz on pins 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 44, 45, 46