void startup(void) { SET_PHASE_STATE_5_MOT2(); TCC0.CNT = 0; while (TCC0.CNT < 65535) {} /* TCF0.CCBBUF = startupPwms[0]; SET_PHASE_STATE_0_MOT2(); TCC0.CNT = 0; while (TCC0.CNT < startupDelays[0]) {} TCF0.CCBBUF = startupPwms[1]; SET_PHASE_STATE_1_MOT2(); TCC0.CNT = 0; while (TCC0.CNT < startupDelays[1]) {} TCF0.CCBBUF = startupPwms[2]; SET_PHASE_STATE_2_MOT2(); TCC0.CNT = 0; while (TCC0.CNT < startupDelays[2]) {} TCF0.CCBBUF = startupPwms[3]; SET_PHASE_STATE_3_MOT2(); TCC0.CNT = 0; while (TCC0.CNT < startupDelays[3]) {} TCF0.CCBBUF = startupPwms[4]; SET_PHASE_STATE_4_MOT2(); TCC0.CNT = 0; while (TCC0.CNT < startupDelays[4]) {} */ TCF0.CCBBUF = startupPwms[5]; TCE0.CCBBUF = startupPwms[5]/2; TC_SetPeriod( &TCD1, 65535 ); //~ xxx TC1_ConfigClockSource( &TCD1, TC_CLKSEL_DIV64_gc ); TC1_ConfigClockSource( &TCD1, TC_CLKSEL_DIV4_gc ); //TC1_ConfigClockSource( &TCD1, TC_CLKSEL_DIV64_gc); TC1_SetOverflowIntLevel (&TCD1, TC_OVFINTLVL_LO_gc); missedCommFlag = 1; SET_PHASE_STATE_0_MOT2(); motor2State = 0; //~ while (TCC0.CNT < startupDelays[5]) {} //~ while (1); }
/** \brief Initializes the library timer 0 or 1 based on given timer parameter. * * Sets up the given timer for use with this library. This involves setting the * clock prescaler and mode, but the period and overflow interrupt enable are * left to the SM_move() and ISR for the corresponding timer. * * This function also handles mapping the appropriate speed ramp to the * * \param[in] motor The motor to initialize the timer for * \param[in] timer The timer to initialize (TIMER0 or TIMER1) */ static void SM_timer_init(SM_t *motor, SM_timer_t timer) { /* 32M/256 == 125K Hz*/ if (timer == SM_TIMER_NEEDLE) { TC0_ConfigWGM(&TIMER_NEEDLE, TC_WGMODE_NORMAL_gc); TC0_ConfigClockSource(&TIMER_NEEDLE, TC_CLKSEL_DIV256_gc); needle_motor = motor; } else { TC1_ConfigWGM(&TIMER_RING, TC_WGMODE_NORMAL_gc); TC1_ConfigClockSource(&TIMER_RING, TC_CLKSEL_DIV256_gc); ring_motor = motor; } motor->timer = timer; }
void setup_Timer2(){ //1 min TC1_ConfigClockSource( &TCC1, TC_CLKSEL_DIV1024_gc ); TC_SetPeriod( &TCC1, 0x8000 ); //Es el periodo o TOP Value para que se active la interrupciĆ³n. (Equivale a 1030ms) }