SAM4S2A Time

ASF Wizard

  • Delay routines (service): Loop based delay routines. Provides microseconds, milliseconds and second delays. Common API for SAM, UC3 and XMEGA.
  • WDT - Watchdog Timer (driver): The Watchdog Timer can be used to prevent system lock-up if the software becomes trapped in a deadlock. It features a 12-bit down counter that allows a watchdog period of up to 16 seconds (slow clock at 32.768 kHz).
warning

SysTick์— ์˜ํ•œ ์ธํ„ฐ๋ŸฝํŠธ๊ฐ€ ๋„ˆ๋ฌด ๋งŽ์ด ๋ฐœ์ƒํ•˜๋ฉด Delay routines์˜ ํ•จ์ˆ˜๊ฐ€ ์˜ํ–ฅ์„ ๋ฐ›์•„ ์˜๋„ํ•œ ๊ฒƒ๋ณด๋‹ค ๊ธธ๊ฒŒ ๋”œ๋ ˆ์ด ๋ฉ๋‹ˆ๋‹ค. SAM4S2A 120MHz์—์„œ us๋ฅผ ๋งŒ๋“ค๊ธฐ ์œ„ํ•œ ์„ค์ •์„ ํ•˜๋ฉด ๋”œ๋ ˆ์ด๋Š” ์„ค์ • ๊ฐ’๋ณด๋‹ค ์•ฝ 1.5 ~ 1.6๋ฐฐ ๊ธธ์–ด์ง‘๋‹ˆ๋‹ค.

Examples

#include <asf.h>
volatile uint32_t us_tick = 0;
volatile uint16_t count_for_ms = 0;
volatile uint32_t ms_tick = 0;
static inline uint32_t micros(void) { return us_tick; }
static inline uint32_t millis(void) { return ms_tick; }
int main(void) {
sysclk_init();
board_init();
/* Insert application code here, after the board has been initialized. */
wdt_disable(WDT);
// F_CPU / 1,000,000 -> interval
SysTick_Config(F_CPU / 1000000UL);
delay_init(F_CPU);
for(;;) {}
}
ISR(SysTick_Handler) {
++us_tick;
++count_for_ms;
if(count_for_ms == 1000) {
count_for_ms = 0;
++ms_tick;
}
}
Last updated on