Changing the PWM frequency of Arduino Due

Hi guys,

I am using Arduino Due and I would like to set the switching frequency of all digital PWM ports (i.e. digital pin 3 to digital pin 13) to 32 KHz for 8-bit resolution? Any idea?

e.g. In Arduino Mega every PWM port is controlled by a special timer e.g. timer 0 controls pin 13 and 4, timer 1 controls pin 11 and 12 and so on. But I have no idea about which timer controls which PWM pin in Arduino Due.

Please help.

Thank you

Hi there @AmerAlGhafri,

Have a look to pwm_lib available at: https://github.com/antodom/pwm_lib

This library is specific for the Arduino DUE, and abstracts the 8 PWM channels available in Arduino DUE's ATSAM3X8E microcontroller. Using pwm_lib You can generate easily a PWM signal with a changing frequency.

To start with have a look to the examples that comes with the library, and ask me if you have any doubt.

I hope it helps.

antodom: Hi there @AmerAlGhafri,

Have a look to pwm_lib available at: https://github.com/antodom/pwm_lib

This library is specific for the Arduino DUE, and abstracts the 8 PWM channels available in Arduino DUE's ATSAM3X8E microcontroller. Using pwm_lib You can generate easily a PWM signal with a changing frequency.

To start with have a look to the examples that comes with the library, and ask me if you have any doubt.

I hope it helps.

So if i'm trying to get a 200KHz frequency on one of the pins, what would the code to do that be?

Hi there @tcorkum,

Have a look to pwm_lib's example changing_period_test (https://github.com/antodom/pwm_lib/blob/master/examples/changing_period_test/changing_period_test.ino).

I hope it is clear enough.

Best.

Hallo, which version of Arduino IDE is suitable for this test (High frequency test for Arduino Due)?

Hi there @mshiravi,

You can use the last one. In any case, you have more info in: GitHub - antodom/pwm_lib: This is a C++ library to abstract the use of the eight hardware PWM channels available on Arduino DUE's Atmel ATSAM3X8E microcontroller.

Best.

Hallo, 2776 after compiling the code this error massage is shown:

Error compiling for Board Arduino board (|Programming Port).

can I have your help?

mshiravi:
Hallo, 2776
after compiling the code this error massage is shown:

Error compiling for Board Arduino board (|Programming Port).

can I have your help?

Please do this:

  • When you encounter an error, you’ll see a button on the right side of the orange bar “Copy error messages” in the Arduino IDE (or the icon that looks like two pieces of paper at the top right corner of the black console window in the Arduino Web Editor). Click that button…
  • In a forum reply here, click on the reply field.
  • Click the </> button on the forum toolbar. This will add the forum’s code tags markup to your reply.
  • Press “Ctrl + V”. This will paste the error between the code tags.
  • Move the cursor outside of the code tags before you add any additional text to your reply.

If the text exceeds the forum’s 9000 character limit, save it to a .txt file and post it as an attachment. If you click the “Reply” button here, you will see an “Attachments and other settings” link that will allow you to make the attachment.