Go Down

Topic: Changing the PWM frequency of Arduino Due (Read 1 time) previous topic - next topic

AmerAlGhafri

Feb 15, 2017, 09:25 pm Last Edit: Feb 15, 2017, 10:23 pm by AmerAlGhafri
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

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.
------------
antodom

tcorkum

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?

antodom

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.
------------
antodom

Go Up