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 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

	GPIOPinTypeGPIOOutput(LASER_EN_PORT, LASER_EN_MASK);
	GPIOPinWrite(LASER_EN_PORT, LASER_EN_MASK, LASER_EN_INVERT);

	// Configure timer
	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
	TimerConfigure(LASER_TIMER, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM|TIMER_CFG_B_ONE_SHOT);
	TimerControlLevel(LASER_TIMER, TIMER_A, 1);

	// PPI = PWMfreq/(feedrate/MM_PER_INCH/60)

	// Set PPI Pulse timer
	ppi_cycles = SysCtlClockGet() / 1000 * CONFIG_LASER_PPI_PULSE_MS;
	ppi_divider = ppi_cycles >> 16;
	ppi_cycles /= (ppi_divider + 1);
	TimerPrescaleSet(LASER_TIMER, TIMER_B, ppi_divider);
	TimerLoadSet(LASER_TIMER, TIMER_B, ppi_cycles);

	// Setup ISR
	TimerIntRegister(LASER_TIMER, TIMER_B, laser_isr);
	TimerIntEnable(LASER_TIMER, TIMER_TIMB_TIMEOUT);
    IntPrioritySet(INT_TIMER0B, CONFIG_LASER_PRIORITY);

	// Set PWM refresh rate
	laser_cycles = SysCtlClockGet() / CONFIG_LASER_PWM_FREQ; /*Hz*/
	laser_divider = laser_cycles >> 16;
	laser_cycles /= (laser_divider + 1);

	// Setup Laser PWM Timer
	TimerPrescaleSet(LASER_TIMER, TIMER_A, laser_divider);
	TimerLoadSet(LASER_TIMER, TIMER_A, laser_cycles);
	TimerPrescaleMatchSet(LASER_TIMER, TIMER_A, laser_divider);
	laser_intensity = 0;

	// Set default value
	control_laser_intensity(0);
	control_laser(0, 0);

	TimerEnable(LASER_TIMER, TIMER_A);

	// ToDo: Map the timer ccp pin sensibly
	GPIOPinConfigure(GPIO_PB6_T0CCP0);
	GPIOPinTypeTimer(LASER_PORT, (1 << LASER_BIT));

	//// air and aux assist control
	GPIOPinTypeGPIOOutput(ASSIST_PORT, ASSIST_MASK);
	control_air_assist(false);
	control_aux1_assist(false);
}