I am using direct port manipulation on an Arduino Due, and would like to change the system clock from 84 MHz to a lower frequency. Refer to the http://www.atmel.com/Images/doc11057.pdf para 220.127.116.11. I was able to do it via Atmel Studio by modifying file conf_clock.h as follows:
// ===== System Clock (MCK) Prescaler Options (Fmck = Fsys / (SYSCLK_PRES)) #define CONFIG_SYSCLK_PRES SYSCLK_PRES_1 //#define CONFIG_SYSCLK_PRES SYSCLK_PRES_2 // [deleted commented out code for clarity in forum post] // ===== PLL0 (A) Options (Fpll = (Fclk * PLL_mul) / PLL_div) // Use mul and div effective values here. #define CONFIG_PLL0_SOURCE PLL_SRC_MAINCK_XTAL #define CONFIG_PLL0_MUL 25 #define CONFIG_PLL0_DIV 3 // [deletedcode for clarity in forum post] // - XTAL frequency: 12MHz // - System clock source: PLLA // - System clock prescaler: 2 (divided by 2) 1 2 // - PLLA source: XTAL // - PLLA output: XTAL * 14 / 1 20/3 25/3 // - System clock is: 12 * 14 / 1 /2 = 84MHz 80 50
I would like to do the same thing in the Arduino development environment, so I can take advantage of the libraries there. A similar file exists called system_sam3xa.c, where I made the following modifications, but they have no effect.
/*= The PLLA Clock frequency is the PLLA input frequency multiplied by MULA + 1*/ /* Clock settings (84MHz) */ Prescaler: 2 Mul:14 MULA:0xd DIVA:1 /* Clock settings (80MHz) */ Prescaler: 1 Mul:20 MULA:0x13 DIVA:3 /* Clock settings (50MHz) */ Prescaler: 2 Mul:25 MULA:0x18 DIVA:3 #define SYS_BOARD_OSCOUNT (CKGR_MOR_MOSCXTST(0x8)) #define SYS_BOARD_PLLAR (CKGR_PLLAR_ONE \ | CKGR_PLLAR_MULA(0x18UL) \ | CKGR_PLLAR_PLLACOUNT(0x3fUL) \ | CKGR_PLLAR_DIVA(0x3UL)) #define SYS_BOARD_MCKR (PMC_MCKR_PRES_CLK_2 | PMC_MCKR_CSS_PLLA_CLK)
This appears to have no effect on the clock rate. I tried deleting the object file system_sam3xa.o with no luck. I assume that the changes were not compiled into the arduino.a library, and the next step is to research that. Other approaches might be to changing the PLL after the board initializes, but that is rather difficult. Does anyone have other suggestions?