Go Down

Topic: PWM with Arduino Due (Read 2671 times) previous topic - next topic


Jan 26, 2014, 09:02 pm Last Edit: Jan 26, 2014, 09:52 pm by wuliuxiansheng Reason: 1
Does anyone know how to generate PWM signals with different frequencies with Arduino Due platform? Or how to directly use registers in the micro controller to generate PWM signals? If using analogWrite, I cannot change the frequency.

Here is my code but it's not working.
void setup() {
  // put your setup code here, to run once:

  pmc_enable_periph_clk (ID_PWM);
  PWM->PWM_WPCR= 0x50574DFC;
  PWM->PWM_DIS=  0x000000FF;
  PWM->PWM_CLK=  0x00000001;
  PWM->PWM_CH_NUM[5].PWM_CMR= 0x00010000;  // period 84KHz
  PWM->PWM_CH_NUM[5].PWM_CPRD=0x00000C00;  // 1024 resolution
  PWM->PWM_CH_NUM[5].PWM_CDTY=0x00000600;  // start duty cycle is 0
  PWM->PWM_CH_NUM[5].PWM_DT  =0x00000000;  // dead time 5 (58ns)
  PWM->PWM_SCM  =0x00020020;  // synchronous mode 2 channel 5
  PWM->PWM_SCUP =0x00000000;  // minimum update period
  PWM->PWM_ENA  =0x00000020;

void loop() {
  // put your main code here, to run repeatedly:


You'll have to first realize that some Due pins are connected to the PWM peripheral,
some to one of the TC peripherals.  The code for analogWrite handles these two
cases (as well as the DAC outputs), and this is good place to start.   Its a fairly
complex chip so it might be easier to wait and see if someone else has already written
this as a library or something.

Also the variant.cpp file is the place to see how each pin is handled, IIRC.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]


    I find generating PWM signals with timers easy. I have generated for my project varying frequencies with varying duty ratios. Due also has 11 physical output pins form which signals can be obtained. Libraries are available  now ... and if you want you can write yourself one directly with  timer control registers.


Does anyone know how to generate PWM signals with different frequencies with Arduino Due platform?

If you want unique frequencies up to 40khz, this library is your answer:


Good luck.

Go Up