Hi all,
I am newbie in arduino due and recently when I am trying to get due to generate pwm, I found a behavior that I cannot explain.
I called it on pin 7, and the default frequency is 1 kHz and it uses signal from PWM clock A, no problem.
Then, I went to change register PWM clock register value and try to get it higher. According to the due cpu datasheet, when I set PREA and DIVA value so that clock A has the same frequency as MCK, I was expecting something close to 84 MHz but instead, I got a square wave of 329 kHz (still 50% duty cycle), which is clearly 84 MHz / 255.
I don't see anywhere else on the PWM section of the datasheet that one can divide the MCK frequency. So I am really confused on where is this 255 coming from. If I can make use of this extra divider, it will be really helpful.
Here is my code:
#include <SPI.h>
#define PWM_WPCR (*(volatile unsigned long int *) 0x400940E4) //datasheet 1053
#define PWM_CLK (*(volatile unsigned long int *) 0x40094000) // datasheet 1020
void setup() {
analogWrite(7, 127);
PWM_WPCR = 0x50574D3C; // disable write protection for PWM
PWM_CLK = 0x00000001; // clk A to MCK, disable clk B
}
I have also looked into channel mode register, but if it uses clk A or clk B, then there is only one option without any divider. Please find the link to datasheet here: http://www.atmel.com/Images/doc11057.pdf
Thanks for your time. Any help is appreciated.
F33d