Skip to main content

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๋ฐฐ ๊ธธ์–ด์ง‘๋‹ˆ๋‹ค.


#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) {
/* Insert application code here, after the board has been initialized. */

// F_CPU / 1,000,000 -> interval
SysTick_Config(F_CPU / 1000000UL);

for(;;) {}

ISR(SysTick_Handler) {
if(count_for_ms == 1000) {
count_for_ms = 0;