How to reset Arduino DUE PWM?

Hi guys,

For several day I am trying to figure out how to reset Due PWM signal (to re-sync it with another signal).

This is my code:

    pmc_enable_periph_clk( PWM_INTERFACE_ID );


    // SETUP PWM FOR pin
    PIO_Configure( g_APinDescription[_txPin].pPort,  g_APinDescription[_txPin].ulPinType,  g_APinDescription[_txPin].ulPin,  g_APinDescription[_txPin].ulPinConfiguration);
    PWMC_ConfigureChannel(PWM_INTERFACE, g_APinDescription[_txPin].ulPWMChannel, PWM_CMR_CPRE_CLKA, 0, 0);
    PWMC_SetPeriod(PWM_INTERFACE, g_APinDescription[_txPin].ulPWMChannel, _periodPWM/HIGH_LEVEL_LENGTH);
    PWMC_SetDutyCycle(PWM_INTERFACE, g_APinDescription[_txPin].ulPWMChannel, 1);  
        PWMC_EnableChannel(PWM_INTERFACE, g_APinDescription[_txPin].ulPWMChannel);

Following custom interrupt, I need PWM signal to restart it's cycle.

I tried resetting the PWM_CCNT counter to zero manually, but discovered it is read only.

I also tried to call


Any ideas?

Many thanks Meir Tseitlin

according to the ATMEL SAM3X8E datasheet (page 1050) you can re-enable the channel in order to reset the counter. I wrote this code to send one pulse on a channel. (for OneShot ESC on quadcopter) Please note, channel is only disabled at the end of its period after you call PWMC_DisableChannel().

void pwm_OneShot(uint32_t ch, uint32_t value){
  PWMC_SetDutyCycle(PWM, ch, value);
  PWMC_EnableChannel(PWM, ch);          //counter is reset here, pulse starts right now
  PWMC_SetDutyCycle(PWM, ch, 0);       //this stops pulsing until this function is called again (this gets written in the update register and does not affect the current pulse)
  PWMC_DisableChannel(PWM, CH);         //channel is disabled at the end of current period