int main(void) { DDRB |= 1; /* make the LED pin an output */ DDRB &= 0xFD; /* make the switch pin an input */ PORTB &= 0xFD; /* make it tri-stated */ /* set up the timer */ BYTE timerHits = 0; while (1) { if ((PINB & 0x02) > 0) { /* if the button is pressed */ /* if the timer is running, keep going */ if (isTimerRunning()) { continue; } /* if the timer isn't running, start it */ else { enableTimerInterrupt(); startTimer(255, CLOCK_SCALE_1024); sei(); timerHits = 0; } } /* if the button is not pressed, stop and clear timer */ else { cli(); stopTimer(); disableTimerInterrupt(); timerHits = 0; clearTimerTripped(); } } return 0; /* never reached */ }
void extruder::setSpeed(float sp) { // DC motor? if(step_en_pin < 0) { e_speed = (byte)sp; if(e_speed > 0) waitForTemperature(); analogWrite(motor_speed_pin, e_speed); return; } // No - stepper disableTimerInterrupt(); if(sp <= 1.0e-4) { disableStep(); e_speed = 0; // Just use this as a flag return; } else { waitForTemperature(); enableStep(); e_speed = 1; } extrude_step_count = 0; float milliseconds_per_step = 60000.0/(E_STEPS_PER_MM*sp); long thousand_ticks_per_step = 4*(long)(milliseconds_per_step); setupTimerInterrupt(); setTimer(thousand_ticks_per_step); enableTimerInterrupt(); }
void setupTimerInterrupt(void) { disableTimerInterrupt(); sim_info("setupTimerInterrupt"); timer_initialised = true; }