Ejemplo n.º 1
0
void control_init() {
  //// laser control
  // Setup Timer0 for a 488.28125Hz "phase correct PWM" wave (assuming a 16Mhz clock)
  // Timer0 can pwm either PD5 (OC0B) or PD6 (OC0A), we use PD6
  // TCCR0A and TCCR0B are the registers to setup Timer0
  // see chapter "8-bit Timer/Counter0 with PWM" in Atmga328 specs
  // OCR0A sets the duty cycle 0-255 corresponding to 0-100%
  // also see: http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM
  DDRD |= (1 << DDD6);      // set PD6 as an output
  OCR0A = 0;              // set PWM to a 0% duty cycle
  TCCR0A = _BV(COM0A1) | _BV(WGM00);   // phase correct PWM mode
  // TCCR0A = _BV(COM0A1) | _BV(WGM01) | _BV(WGM00);  // fast PWM mode
  // prescaler: PWMfreq = 16000/(2*256*prescaler)
  // TCCR0B = _BV(CS00);                // 1 => 31.3kHz
  // TCCR0B = _BV(CS01);                // 8 => 3.9kHz
  TCCR0B = _BV(CS01) | _BV(CS00);    // 64 => 489Hz
  // TCCR0B = _BV(CS02);                // 256 => 122Hz
  // TCCR0B = _BV(CS02) | _BV(CS00);    // 1024 => 31Hz
  // NOTES:
  // PPI = PWMfreq/(feedrate/25.4/60)

  //// air and aux assist control
  ASSIST_DDR |= (1 << AIR_ASSIST_BIT);   // set as output pin
  ASSIST_DDR |= (1 << AUX1_ASSIST_BIT);  // set as output pin
  control_air_assist(false);
  control_aux1_assist(false);
  #ifdef DRIVEBOARD
    ASSIST_DDR |= (1 << AUX2_ASSIST_BIT);  // set as output pin
    control_aux2_assist(false);
  #else  
    //// limits overwrite control
    LIMITS_OVERWRITE_DDR |= 1<<LIMITS_OVERWRITE_BIT; // define as output pin
    control_limits_overwrite(true); // do not use hardware logic to stop steppers 
  #endif  
}
Ejemplo n.º 2
0
void control_init() {
  //// laser control
  // Setup Timer0 for a 31.25kH "phase correct PWM" wave (assuming a 16Mhz clock)
  // Timer0 can pwm either PD5 (OC0B) or PD6 (OC0A), we use PD6
  // TCCR0A and TCCR0B are the registers to setup Timer0
  // see chapter "8-bit Timer/Counter0 with PWM" in Atmga328 specs
  // OCR0A sets the duty cycle 0-255 corresponding to 0-100%
  DDRD |= (1 << DDD6);      // set PD6 as an output
  OCR0A = 0;              // set PWM to a 0% duty cycle
  TCCR0A |= (1 << COM0A1);  // set non-inverting mode on OC0A, PD6, Arduino pin 6
  TCCR0A |= (1 << WGM00);   // set phase correct PWM mode, has half the freq of fast PWM
  TCCR0B |= (1 << CS00);    // prescaler to 1, PWMfreq = 16000/(2*256*1) = 31.25kH
  
  //// air and gas assist control
  AIRGAS_DDR |= (1 << AIR_BIT);  // set as output pin
  AIRGAS_DDR |= (1 << GAS_BIT);  // set as output pin
  control_air(false);
  control_gas(false);
  
  //// limits overwrite control
  LIMITS_OVERWRITE_DDR |= 1<<LIMITS_OVERWRITE_BIT;  // define as output pin
  control_limits_overwrite(true);  // do not use hardware logic to stop steppers    
}