 |
| Author |
Message |
|
|
Posted: Jul 12, 2012 - 02:20 AM |
|

Joined: Oct 03, 2005
Posts: 40
|
|
Hi,
I am having some confusion using the ASF... have a lot of things working (TWI/SPI etc), but a fundamental thing is not working... correct clock timing.
I am using delay_ms(x), but the duration is wrong, a 5 second delay taking around 12.3 seconds.
I am configuring the clock using the conf_clock.h file and am setting:
Code:
#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_PLLACK
#define CONFIG_SYSCLK_PRES SYSCLK_PRES_2
#define CONFIG_PLL0_SOURCE PLL_SRC_MAINCK_XTAL
#define CONFIG_PLL0_MUL 32
#define CONFIG_PLL0_DIV 3
I am using an external 12MHz crystal. Confirmed the freq with a scope.
I am calling sysclk_init(); from main.
What is super odd to me is that all these appear to basically macro out into hard compiled numbers. And you have to Build ALL from AS6 to make the compiler notice any changes to these.
My confusion comes 2 fold... why the delays are wrong, but equally, there appears to be a completely different function SystemInit(); that also seems to setup the clocks, and it has a variable SystemCoreClock, which it appears might be more dynamic, but the delay_ms functions don't use that.
There doesn't appear to be good docs on which to use.
So... a post becomes 2 questions:
1) Why is delay_ms wrong
2) Should I be using sysclk_init() or SystemInit() or both?
Thanks! |
Last edited by realwarder on Jul 12, 2012 - 03:12 AM; edited 1 time in total
|
| |
|
|
|
|
|
Posted: Jul 12, 2012 - 02:53 AM |
|

Joined: Oct 03, 2005
Posts: 40
|
|
Oh yes, I also have these lines in user_board.h.
Code:
#define BOARD_FREQ_SLCK_XTAL 32768
#define BOARD_FREQ_SLCK_BYPASS BOARD_FREQ_SLCK_XTAL
#define BOARD_FREQ_MAINCK_XTAL 12000000
#define BOARD_FREQ_MAINCK_BYPASS BOARD_FREQ_MAINCK_XTAL
And the CPU is ATSAM3S4CA-CU, supposedly at 64MHz given those PLL scalers.
Update: Using an independent SysTick_Handler/SysTick_Config millisecond counter, I get good timing. So it is specific to the delay_ms functions. |
|
|
| |
|
|
|
|
|
|
|