Changing arduino Due PWM frequency for DC motor control

Note that there's a slight anomoly with the TC timers, in that it's not possible set the output to 0V by setting the respective TC_RA and TC_RB registers to zero. There's always a tiny slither of a pulse at the start of the timer cycle, (similar to fast PWM mode on the Uno or Mega).

The workaround is to set the timer to clear at the start to of the cycle with the line for D5:

TC2->TC_CHANNEL[0].TC_CMR &= ~TC_CMR_ACPC_Msk;     // Clear the ACPC bitfield
TC2->TC_CHANNEL[0].TC_CMR |= TC_CMR_ACPC_CLEAR;    // Clear D5 output

and for D10:

TC2->TC_CHANNEL[1].TC_CMR &= ~TC_CMR_BCPC_Msk;     // Clear the BCPC bitfield
TC2->TC_CHANNEL[1].TC_CMR |= TC_CMR_BCPC_CLEAR;    // Clear D10 output

Reinstate the PWM output oncemore with the respective TC_CMR_ACPC_SET or TC_CMR_BCPC_SET bitfields.