PWM Module

Hi there,

hope someone who knows well the PWM module of the Arduino Due could seed some light....

I´m setting up 3 Synchronous channels (0,2 and 3) working in update mode 1.

My problem is when trying to set the update mode 1 on register PWM_SCM_UPDM=1 I am getting following error: PWM_SCM_UPDM' was not declared in this scope

Code look like this

void setup() {

// PWM set-up on pins D41-40 Channel 3 (PC9-PC8), D38-39 Channel 2(PC7-PC6) and D34-35 Channel 0 (PC3-PC2).

REG_PIOC_ABSR |= PIO_ABSR_P9 | PIO_ABSR_P8 | PIO_ABSR_P7 | PIO_ABSR_P6| PIO_ABSR_P3 | PIO_ABSR_P2; // Set the port C PWM pins to peripheral type B, page 973.

REG_PIOC_PDR |= PIO_PDR_P9 | PIO_PDR_P8 | PIO_PDR_P7 | PIO_PDR_P6 | PIO_PDR_P3 | PIO_PDR_P2; // Set the port C PWM pins to outputs

REG_PWM_WPSR = 0X0; // Reset Protect SW and HW enabled.

REG_PWM_SCM |= PWM_SCM_SYNC3 | PWM_SCM_SYNC2 | PWM_SCM_SYNC0 ; //Synchronous Channels
REG_PWM_SCM = PWM_SCM_UPDM(0x1); // PWM_SCM UPDM=1 for update mode 1

REG_PWM_ENA = PWM_ENA_CHID0; // Enable the PWM channels, only Channel 0 as they are Synchronous.

//****Clock and Dead-times

REG_PWM_CLK = PWM_CLK_PREA(0) | PWM_CLK_DIVA(4); // Set the PWM clock A rate to n=1 module 84MHz (84MHz/1)
//CLKA 84MHz/4= 21MHz 95ns resolution

PWM->PWM_CH_NUM[0].PWM_CMR = PWM_CMR_CPRE_CLKA | PWM_CMR_DTE | PWM_CMR_CALG ; // Center aligned, set the clock source as CLKA, dead time enable
PWM->PWM_CH_NUM[0].PWM_CPRD = 525 ; // Set the PWM period register CPRD2DIVA/MCK;
PWM->PWM_CH_NUM[0].PWM_DT= PWM_DT_DTL(10) | PWM_DT_DTH(10); // Set Dead Time DTL(DTH) * DIV/MCK = 10* 1/clock(21MHz)= 470ns



I would be very grateful for any help.
Thanks guys!!

Hi hughpe,

The update mode can be set for synchronous channels 0, 2 and 3 as follows:

PWM->PWM_SCM |= PWM_SCM_UPDM_MODE1 |                              // Automatically update the duty-cycle register each timer cycle                    
                PWM_SCM_SYNC3 | PWM_SCM_SYNC2 | PWM_SCM_SYNC0;    // Set the PWM channels as synchronous

Hi MartinL,

I no longer get any error, will check my whole code wit my oscilloscope!
thank so much for that I am quite new with this as you can see. :slight_smile: