// Yep, this is actually -*- c++ -*- // Sanguino G-code Interpreter // Arduino v1.0 by Mike Ellery - initial software (mellery@gmail.com) // v1.1 by Zach Hoeken - cleaned up and did lots of tweaks (hoeken@gmail.com) // v1.2 by Chris Meighan - cleanup / G2&G3 support (cmeighan@gmail.com) // v1.3 by Zach Hoeken - added thermocouple support and multi-sample temp readings. (hoeken@gmail.com) // Sanguino v1.4 by Adrian Bowyer - added the Sanguino; extensive mods... (a.bowyer@bath.ac.uk) // Sanguino v1.5 by Adrian Bowyer - implemented 4D Bressenham XYZ+ stepper control... (a.bowyer@bath.ac.uk) #include #include #include "WProgram.h" #include "parameters.h" #include "pins.h" #include "extruder.h" #include "vectors.h" #include "cartesian_dda.h" // Inline interrupt control functions inline void enableTimerInterrupt() { TIMSK1 |= (1<active()) cdda[tail]->dda_step(); else dQMove(); enableTimerInterrupt(); } //ERIK #ifdef MODIFIER_PIN double modifier = 500.0; double modifier_old = 1.0; #endif double modifier_speed = 512.0; //ERIK void setup() { disableTimerInterrupt(); // This screws with PWM :( setupTimerInterrupt(); debugstring[0] = 0; extruder_in_use = 0; ex[extruder_in_use] = &ex0; head = 0; tail = 0; cdda[0] = &cdda0; cdda[1] = &cdda1; cdda[2] = &cdda2; cdda[3] = &cdda3; setExtruder(); init_process_string(); where_i_am.x = 0.0; where_i_am.y = 0.0; where_i_am.z = 0.0; where_i_am.e = 0.0; where_i_am.f = SLOW_XY_FEEDRATE; Serial.begin(57600); Serial.println("start"); setTimer(DEFAULT_TICK); enableTimerInterrupt(); // ERIK: #ifdef MODIFIER_PIN pinMode(MODIFIER_PIN,INPUT); #endif } byte softPWMduty = 0; byte softPWMcount = 0; int PWMstate = HIGH; static void softPWM() { if(softPWMduty == softPWMcount) { PWMstate = LOW; } digitalWrite(12,PWMstate); if(softPWMcount<254) softPWMcount++; else { PWMstate = HIGH; softPWMcount=0; } } void loop() { manage_all_extruders(); get_and_do_command(); } //****************************************************************************************** // The move buffer inline bool qFull() { if(tail == 0) return head == (BUFFER_SIZE - 1); else return head == (tail - 1); } inline bool qEmpty() { return tail == head && !cdda[tail]->active(); } inline void qMove(FloatPoint p) { while(qFull()) delay(WAITING_DELAY); byte h = head; h++; if(h >= BUFFER_SIZE) h = 0; cdda[h]->set_target(p); head = h; } inline void dQMove() { if(qEmpty()) return; byte t = tail; t++; if(t >= BUFFER_SIZE) t = 0; cdda[t]->dda_start(); tail = t; } inline void setUnits(bool u) { for(byte i = 0; i < BUFFER_SIZE; i++) cdda[i]->set_units(u); } inline void setExtruder() { for(byte i = 0; i < BUFFER_SIZE; i++) cdda[i]->set_extruder(ex[extruder_in_use]); } inline void setPosition(FloatPoint p) { where_i_am = p; } //****************************************************************************************** // Interrupt functions void setupTimerInterrupt() { //clear the registers TCCR1A = 0; TCCR1B = 0; TCCR1C = 0; TIMSK1 = 0; //waveform generation = 0100 = CTC TCCR1B &= ~(1<