

REG_TC4_CTRLA |= prescale | TC_CTRLA_WAVEGEN_MFRQ | TC_CTRLA_ENABLE // Enable TC4 REG_TC4_INTENSET = TC_INTENSET_OVF // Enable TC4 interruptsĬase 1: prescale=TC_CTRLA_PRESCALER(0) break Ĭase 2: prescale=TC_CTRLA_PRESCALER(1) break Ĭase 4: prescale=TC_CTRLA_PRESCALER(2) break Ĭase 8: prescale=TC_CTRLA_PRESCALER(3) break Ĭase 16: prescale=TC_CTRLA_PRESCALER(4) break Ĭase 64: prescale=TC_CTRLA_PRESCALER(5) break Ĭase 256: prescale=TC_CTRLA_PRESCALER(6) break Ĭase 1024: prescale=TC_CTRLA_PRESCALER(7) break REG_TC4_INTFLAG |= TC_INTFLAG_OVF // Clear the interrupt flags NVIC_EnableIRQ(TC4_IRQn) // Connect TC4 to Nested Vector Interrupt Controller (NVIC) NVIC_SetPriority(TC4_IRQn, 0) // Set the Nested Vector Interrupt Controller (NVIC) priority for TC4 to 0 (highest) REG_TC4_COUNT8_CC0 = count_ // Set the TC4 CC0 register to some arbitary value While (TC4->) // Wait for synchronization REG_TC4_CTRLA |= TC_CTRLA_MODE_COUNT8 // Set the counter to 8-bit mode GCLK_CLKCTRL_ID_TC4_TC5 // Feed the GCLK4 to TC4 and TC5 REG_GCLK_CLKCTRL = GCLK_CLKCTRL_CLKEN | // Enable GCLK4 to TC4 and TC5 GCLK_GENCTRL_SRC_DFLL48M | // Set the 48MHz clock source REG_GCLK_GENCTRL = GCLK_GENCTRL_IDC | // Set the duty cycle to 50/50 HIGH/LOW

While (GCLK->) // Wait for synchronization GCLK_GENDIV_ID(4) // Select Generic Clock (GCLK) 4 REG_GCLK_GENDIV = GCLK_GENDIV_DIV(1) | // Divide the 48MHz clock source by divisor 1: 48MHz/1=48MHz Set up the generic clock (GCLK4) used to clock timers I'm using the following code to set the interrupt to run at given frequency on MKR: void setup_timer4(uint16_t clk_div_, uint8_t count_) Setting up timer interrupts on MKR is more difficult than AVR.
