PWM on Pin D17 & D21 (Arduino Due)

Hello,

Please help me to change this PWM Arduino Due code !
I want to use Pin 17 (PWML1) & 21 (PWMH1)

Thanks - Gerald - gelit.ch

void PWM_Init() {

  PMC->PMC_PCER1 |= PMC_PCER1_PID36;                  // Enable PWM (Power On)

  PIOC->PIO_PDR |= PIO_PDR_P3 | PIO_PDR_P2;           // DUE Pin 34-35 to PWM Peripheral
  PIOC->PIO_ABSR |= PIO_ABSR_P3 | PIO_ABSR_P2;        // Setting pins to Peripheral B

  PWM->PWM_CLK = PWM_CLK_PREA(0) | PWM_CLK_DIVA(84);  // Set PWM clock = 1MHz (84MHz/84)
  PWM->PWM_CH_NUM[0].PWM_CMR = PWM_CMR_CPRE_CLKA;     // Period is left aligned, clock source is CLKA on Channel 0

  PWM->PWM_SCM |= PWM_SCM_SYNC0;                      // Synchronizing of Channels 0
  PWM->PWM_SCM |= PWM_SCM_UPDM_MODE1;                 // Manual Write of duty-cycle automatic trigger of the update

  NVIC_SetPriority(PWM_IRQn,0);                       // Set the Nested Vector Interrupt Controller (NVIC) priority for the PWM controller to 0 (highest)
  NVIC_EnableIRQ(PWM_IRQn);                           // Connect PWM Controller to Nested Vector Interrupt Controller (NVIC)

  PWM->PWM_IER1 = PWM_IER1_CHID0;                     // Enable interrupt on PWM channel 0 triggered at end of PWM period

  PWM->PWM_CH_NUM[0].PWM_CPRD = 208;                  // Channel 0 Period f = 1MHz/(2*CPRD) --> T=208 micros
  PWM->PWM_CH_NUM[0].PWM_CDTY = 0;                    // Channel 0 duty-cycle at 0%

  PWM->PWM_ENA = PWM_ENA_CHID0;                       // Enable synchronous PWM on Channel 0
  PWM->PWM_SCUC = PWM_SCUC_UPDULOCK;      // Set the update unlock bit to trigger an update at the end of the next PWM period  IMPORTANT
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.