/** \brief Disables OVF interrupts on the given timer. * * As this library is interrupt driven, this effectively stops the motor. When * stopped, the stepper motor will go into its holding torque phase, unless the * motor driver is disabled. * * \param[in] timer the timer to stop. */ static void SM_timer_stop(SM_timer_t timer) { if (timer == SM_TIMER_NEEDLE) { TC0_SetOverflowIntLevel(&TIMER_NEEDLE, TC_OVFINTLVL_OFF_gc); } else { TC1_SetOverflowIntLevel(&TIMER_RING, TC_OVFINTLVL_OFF_gc); } }
/** \brief Enables OVF interrupts on the given timer. * * As this library is interrupt driven, enabling these interrupts essentially * enables the given SM_move() command to be carried out by the motor. * * \param[in] timer the timer to start */ static void SM_timer_start(SM_timer_t timer) { if (timer == SM_TIMER_NEEDLE) { TC0_SetOverflowIntLevel(&TIMER_NEEDLE, TC_OVFINTLVL_HI_gc); } else { TC1_SetOverflowIntLevel(&TIMER_RING, TC_OVFINTLVL_HI_gc); } /* enable hi level interrupts */ PMIC.CTRL |= PMIC_HILVLEN_bm; }
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); }