diff --git a/sense_control.c b/sense_control.c new file mode 100644 index 000000000..d85f9511d --- /dev/null +++ b/sense_control.c @@ -0,0 +1,97 @@ +/* + io_control.h - controlling sensors and actuators + Part of LasaurGrbl + + Copyright (c) 2011 Stefan Hechenberger + + LasaurGrbl is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LasaurGrbl is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +*/ + +#include +#include +#include +#include +#include "io_control.h" +#include "stepper.h" +#include "planner.h" + + + +void sense_init() { + //// power, chiller, door + SENSE_DDR &= ~(SENSE_MASK); // set as input pins + // LIMIT_PORT |= LIMIT_MASK; //activate pull-up resistors + + //// x1_lmit, x2_limit, y1_limit, y2_limit + LIMIT_DDR &= ~(LIMIT_MASK); // set as input pins + LIMIT_PORT |= LIMIT_MASK; //activate pull-up resistors +} + + +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< + + +void sense_init(); +#define SENSE_POWER ((SENSE_PORT >> POWER_BIT) & 1) +#define SENSE_CHILLER ((SENSE_PORT >> CHILLER_BIT) & 1) +#define SENSE_DOOR ((SENSE_PORT >> DOOR_BIT) & 1) +#define SENSE_X1_LIMIT ((SENSE_PORT >> X1_LIMIT_BIT) & 1) +#define SENSE_X2_LIMIT ((SENSE_PORT >> X2_LIMIT_BIT) & 1) +#define SENSE_Y1_LIMIT ((SENSE_PORT >> Y1_LIMIT_BIT) & 1) +#define SENSE_Y2_LIMIT (SENSE_PORT >> Y2_LIMIT_BIT) & 1 +#define SENSE_LIMITS ((LIMIT_PORT & LIMIT_MASK) > 0) +#define SENSE_ANY (((LIMIT_PORT & LIMIT_MASK) > 0) && ((SENSE_PORT & SENSE_MASK) > 0)) + + +void control_init(); + +void control_laser_intensity(uint8_t intensity); //0-255 is 0-100% + +void control_air(bool enable); +void control_gas(bool enable); + +// dis/enable if steppers can still +// move when a limit switch is triggering +void control_limits_overwrite(bool enable); + + +#endif