Example #1
0
void Posixino::setupTimerIntervals() {

    interruptCounter[0] = -1;
    interruptCounter[1] = -1;
    interruptCounter[2] = -1;

# ifdef TIMER0
    do {
        if ((TCCR0A == -1) || (TCCR0B == -1)) fatal("timer0 not set",2);
        setupTimerInterrupt(0,TIMER0,TCCR0A,TCCR0B);
    } while (false);
# endif

# ifdef TIMER1
    do {
        if ((TCCR1A == -1) || (TCCR1B == -1)) fatal("timer1 not set",2);
        setupTimerInterrupt(1,TIMER1,TCCR1A,TCCR1B);
    } while (false);
# endif

# ifdef TIMER2
    do {
        if ((TCCR2A == -1) || (TCCR2B == -1)) fatal("timer2 not set",2);
        setupTimerInterrupt(2,TIMER2,TCCR2A,TCCR2B);
    } while (false);
# endif

} // setupTimerIntervals()
Example #2
0
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();
}