2
\$\begingroup\$

I have a board with the ATSAM3S2BA-AU, which is a Cortex M3 uC. I need to use 2 PWM channel , here how I've done it :

 PIO_Configure(pPins, PIO_LISTSIZE(pPins));  //Pin mapping

/* Enable PWMC peripheral clock */
PMC_EnablePeripheral(ID_PWM);
PWMC_ConfigureClocks(EXCITATION_PWM_FREQUENCY * MAX_PWM_DUTY_CYCLE*2,
                     EXCITATION_PWM_FREQUENCY * MAX_PWM_DUTY_CYCLE,
                     BOARD_MCK);
/* Configure PWMC channel for 1  */
PWMC_ConfigureChannel( PWM,
               PWM_CHANNEL2,        /* channel */
                       PWM_CMR_CPRE_CKA,    /* prescaler */
                       0,                   /* alignment */
                       0);      /* polarity */

PWMC_SetPeriod(PWM, PWM_CHANNEL2, MAX_PWM_DUTY_CYCLE);
PWMC_SetDutyCycle(PWM, PWM_CHANNEL2, HALF_PWM_DUTY_CYCLE);
PWMC_EnableChannel(PWM, PWM_CHANNEL2);


/* Configure PWMC channel for 2  */
PWMC_ConfigureChannel( PWM,
               PWM_CHANNEL0,        /* channel */
                       PWM_CMR_CPRE_CKA,    /* prescaler */
                       0,                   /* alignment */
                       PWM_CMR_CPOL);       /* polarity */

PWMC_SetPeriod(PWM, PWM_CHANNEL0, MAX_PWM_DUTY_CYCLE);
PWMC_SetDutyCycle(PWM, PWM_CHANNEL0, HALF_PWM_DUTY_CYCLE);
PWMC_EnableChannel(PWM, PWM_CHANNEL0); 

this works fine, but when I change the order of the configuration, meaning setting channel0 first than the channel 2 , only the second still works, so the question is why ? I'Ve tried to figured it out reading the datasheet but it didn't help !

\$\endgroup\$
  • 2
    \$\begingroup\$ Error is in code not shown. \$\endgroup\$ – Turbo J Jan 17 '17 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.