Go Down

Topic: DUE PWM Frequency (Read 79874 times) previous topic - next topic


Hi all,
I'm trying to low the pwm freqeuncy of an arduino due using timer registers. I used an instruction like this

TCCR0B = TCCR0B & 0b11111000 | 0x1024

I would low the frequency using a prescaler equal to 1024. Arduino IDE tells me that "TCCR0B was not declared". How can I solve this problem?
Please help me
Thank you all.


Dear antodom,

thanks for library, Unfortunately, I have the following error when I've tried to compile the PWM test on my Due

thanks in advance

error:Arduino: 1.8.1 (Windows 10), Board: "Arduino Due (Programming Port)"

C:\Users\odaya\Downloads\pwm_ard\pwm_lib-aeec48f08c719beb9fa890b7d126095c809b8051\examples\basic_test\basic_test.ino:35:21: fatal error: pwm_lib.h: No such file or directory

 #include "pwm_lib.h"


compilation terminated.

exit status 1
Error compiling for board Arduino Due (Programming Port).


Hi there @odayali1975,

Have you installed the library in the right place? It should be in the subdirectory libraries in the directory where you have your projects. Just check the preferences you have in your Arduino IDE.

I hope it helps.


Jan 17, 2017, 03:10 pm Last Edit: Jan 17, 2017, 04:50 pm by tokapi
Hello everyone,

I have read this entire thread since for a work project I (urgently) need to be able to port arduino Mega code to arduino Due.

The goal is to use analogWriteResolution(12) and analogWrite() to command the duty cycle of a 20kHz PWM with 12bits precision (instead of 8bits on Mega).

But I'm stuck on changing the PWM frequency... According to the first posts I should find the variant.h file in order to change it, but I cannot find it at all on my Windows Arduino 1.8.1 installation ?

Can somebody help me please ?

EDIT : ok, found it, it was in C:\Users\YourName.YourName-PC\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\variants\arduino_due_x


I have a question, I also asked in a stackoverflow thread here:

but I am trying here as well.

I have the following questions:

Pin 7 seems not to be working good, it outputs 11.1 khz whatever seems to be the value of PWM_FREQUENCY and TC_FREQUENCY. Any ideas why is this happening?

I am trying to do the following in my main function, but it does not seem to be working:


But the result is still a 1khz PWM frequency. It changes only if I change the definitions in the variant.h. Any ideas how should I make this work from my main function?



There are numerous example sketches to select properly the correct PWM frequency and duty cycle, or use pwm library from antodom

Go Up