Hi,
I am looking to migrate my project from Arduino MEGA2560 to MKR ZERO.
My sketch controls 3 motor driver ICs and does it via 3 separate pins per driver IC, and sets up the pins to 20KHz via timers, and then directly modify the duty cycle in the program to adjust the speed.
Right now i have this for my MEGA2560:
// Timer 4 (TCCR4) configuration controls pins 6, 7, and 8.
// PWM frequency calculation: [ 16MHz / 1 (prescaler) / 2 (phase-correct) / 400 (top) = 20kHz ]
int eightOnes = 255; // Equivalent to 11111111 in binary
TCCR3A &= ~eightOnes; // Set the eight bits in register to 0
TCCR3B &= ~eightOnes; // Set the eight bits in register to 0
ICR3 = (F_CPU/20000)/2; // Top = 400 = (16Mhz/20Khz)/2
TCCR3A = _BV(COM3A1) // pin 6 - non-inverted PWM output
| _BV(COM3B1) // pin 7 - non-inverted PWM output
| _BV(COM3C1) // pin 8 - non-inverted PWM output
| _BV(WGM31); // mode 10: phase correct PWM with ICR4 as Top
TCCR3B = _BV(WGM33)
| _BV(CS30); // Prescaler = 1
and control the duty cycle by updating OCR3A, OCR3B, OCR3C:
// speed = range between -400 to 400
OCR3A = speed
OCR3B = speed
Anyone could help with a solution or could point me the right direction? thanks!