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).
경고
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;
}
}