Go Down

Topic: Assigning timers to pwm pins (Read 540 times) previous topic - next topic

kaanyilmaz

Apr 05, 2017, 02:42 pm Last Edit: Apr 05, 2017, 05:16 pm by kaanyilmaz
Hi everybody,

Forgive me if this was discussed earlier, I couldn't find anything about it. I am planning to use DUE to drive 4 pololu dc motors via VNH5019 motor driver. Pololu has a library to drive the motors however it needs to be edited because maximum 2 motors can be driven with the library since a timer cannot be used with more than 2 pwms.

The below code section assigns the 1st timer to pins 11,12 or 13. For Arduino Due, how should the below code be in order to assign a timer to a specific pwm pin?

Code: [Select]

  if(_PWM1 == 11 || _PWM1 == 12 || _PWM1 == 13 ||
     _PWM2 == 11 || _PWM2 == 12 || _PWM2 == 13)
  {
    //timer1
    TCCR1A = 0;
    if(_PWM1 == 11)      { TCCR1A |= _BV(COM1A1); _PWM1_REG = &OCR1A; }
    else if(_PWM1 == 12) { TCCR1A |= _BV(COM1B1); _PWM1_REG = &OCR1B; }
    else if(_PWM1 == 13) { TCCR1A |= _BV(COM1C1); _PWM1_REG = &OCR1C; }


Thank you,
Mr. Kaan Yilmaz

Go Up