/* Sets the period value used by a PWM channel. This function writes directly to the CPRD register if the channel is disabled; otherwise, it uses the update register CUPD.  */
void PWMC_SetPeriod(unsigned char channel, unsigned short period)
/* Sets the period value used by a PWM channel. This function writes directly to the CPRD register if the channel is disabled; otherwise, it uses the update register CUPD.  */
void PWMC_SetPeriod(unsigned char channel, unsigned short period)
{
    if ((AT91C_BASE_PWMC->PWMC_SR & (1 << channel)) == 0) {
        AT91C_BASE_PWMC->PWMC_CH[channel].PWMC_CPRDR = period;
    }
    else {
        AT91C_BASE_PWMC->PWMC_CH[channel].PWMC_CMR |= AT91C_PWMC_CPD;
        AT91C_BASE_PWMC->PWMC_CH[channel].PWMC_CUPDR = period;
    }
}