Beispiel #1
0
/* Start heartbeat timer */
void start_heartbeat(void) {
    TC_OC(TC_HEARTBEAT);
    SET_OC_ACTION(TC_HEARTBEAT,OC_OFF);
    
    TC(TC_HEARTBEAT) = TCNT + HEARTBEAT;    // Preset OC channel
    TC_INT_ENABLE(TC_HEARTBEAT);            // Enable timer channel interrupt
}
Beispiel #2
0
/* to count in milisecond increments */
void msleep(word ms) {
    word i;
    
    // Enable timer module if not already enabled
    if(!(TSCR1 & TSCR1_TEN_MASK)) EnableTimer;
    
    TC(TC_SLEEP) = TCNT + OC_DELTA_1MS; // Preset channel register
    TC_OC(TC_SLEEP);                    // Enable channel as output compare
    
    for(i=0; i < ms; i++) {
        while(!(TFLG1 & (1 << TC_SLEEP)));  // Wait for event
        TC(TC_SLEEP) += OC_DELTA_1MS;       // Rearm channel register, clearing TFLG as well
    }
}
/* Initialize stepper motor control */
void stepper_init(void) {
    
    // Set initial delay time and step type
    stepper_delay = STEPPER_DELAY_INIT;
    stepper_step_type = STEPPER_STEP_INIT;
    
    // Enable timer module if not already enabled
    if(!(TSCR1 & TSCR1_TEN_MASK)) EnableTimer;
    
    TC_OC(TC_STEPPER);  // Channel set to output compare
    SET_OC_ACTION(TC_STEPPER,OC_OFF);   // Do not change output line after output compare triggered, this is controlled manually
    
    TC(TC_STEPPER) = TCNT + TIMER_DELTA(stepper_delay); // Preset OC channel
    TC_INT_ENABLE(TC_STEPPER);  // Enable timer channel interrupts
    
    SET_BITS(STEPPER_PORT_DDR,STEPPER_COIL_BITS);   // Set stepper coil lines as outputs
    SET_BITS(STEPPER_LIMIT_INPUT_EN,STEPPER_LIMIT_INPUT_EN_MASK);   // Set limit switch ports as inputs
}