<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -29,11 +29,10 @@
 
 //these defines are for using rotary encoders on the extruder
 #define EXTRUDER_ENCODER_STEPS 1024		//number of steps per revolution
-#define EXTRUDER_ENCODER_A_PIN 2		//quadrature a pin
-#define EXTRUDER_ENCODER_B_PIN 3		//quadrature b pin
 #define EXTRUDER_MIN_SPEED 50			//minimum PWM speed to use
 #define EXTRUDER_MAX_SPEED 255			//maximum PWM speed to use
-#define EXTRUDER_ERROR_MARGIN 2			//our error margin (to prevent constant seeking)
+#define EXTRUDER_ERROR_MARGIN 10		//our error margin (to prevent constant seeking)
+#define INVERT_QUADRATURE			0 // 1 = inverted, 0 = not inverted
 
 /****************************************************************************************
 * digital i/o pin assignment
@@ -61,9 +60,11 @@
 #define Z_ENABLE_PIN 18
 
 //extruder pins
+#define EXTRUDER_ENCODER_A_PIN 2		//quadrature a pin
+#define EXTRUDER_ENCODER_B_PIN 3		//quadrature b pin
 #define EXTRUDER_MOTOR_DIR_PIN     4
 #define EXTRUDER_MOTOR_SPEED_PIN   5
 #define EXTRUDER_HEATER_PIN        6
 #define EXTRUDER_FAN_PIN           11
-#define EXTRUDER_THERMISTOR_PIN    6  //a -1 disables thermistor readings
+#define EXTRUDER_THERMISTOR_PIN    5  //a -1 disables thermistor readings
 #define EXTRUDER_THERMOCOUPLE_PIN  -1 //a -1 disables thermocouple readings</diff>
      <filename>GCode_Interpreter_Experimental/_init.pde</filename>
    </modified>
    <modified>
      <diff>@@ -59,26 +59,88 @@ int last_extruder_error = 0;
 int last_extruder_delta = 0;
 int last_extruder_speed = 0;
 
-void extruder_read_quadrature()
-{
-	// found a low-to-high on channel A
-	if (digitalRead(EXTRUDER_ENCODER_A_PIN) == HIGH)
-	{   
-		// check channel B to see which way
-		if (digitalRead(EXTRUDER_ENCODER_B_PIN) == LOW)
-			extruder_error--; // CCW
-		else
-			extruder_error++; //CW
-	}
-	// found a high-to-low on channel A
-	else
-	{
-		// check channel B to see which way
-		if (digitalRead(EXTRUDER_ENCODER_B_PIN) == LOW)
-			extruder_error++; //CW
-		else
-			extruder_error--; //CCW
-	}
+void extruder_read_quadrature_a()
+{  
+  // found a low-to-high on channel A
+  if (digitalRead(EXTRUDER_ENCODER_A_PIN) == HIGH)
+  {   
+    // check channel B to see which way
+    if (digitalRead(EXTRUDER_ENCODER_B_PIN) == LOW)
+    {
+      if (INVERT_QUADRATURE)
+        extruder_error--; 
+      else
+        extruder_error++;
+    }
+    else
+    {
+      if (INVERT_QUADRATURE)
+        extruder_error++;
+      else
+        extruder_error--;
+    }  
+  }
+  // found a high-to-low on channel A
+  else                                        
+  {
+    // check channel B to see which way
+    if (digitalRead(EXTRUDER_ENCODER_B_PIN) == LOW)
+    {
+      if (INVERT_QUADRATURE)
+        extruder_error++;
+      else
+        extruder_error--;
+    }
+    else
+    {
+      if (INVERT_QUADRATURE)
+        extruder_error--;
+      else
+        extruder_error++;
+    }  
+  }
+}
+
+void extruder_read_quadrature_b()
+{  
+  // found a low-to-high on channel A
+  if (digitalRead(EXTRUDER_ENCODER_B_PIN) == HIGH)
+  {   
+    // check channel B to see which way
+    if (digitalRead(EXTRUDER_ENCODER_A_PIN) == LOW)
+    {
+      if (INVERT_QUADRATURE)
+        extruder_error; 
+      else
+        extruder_error++;
+    }
+    else
+    {
+      if (INVERT_QUADRATURE)
+        extruder_error++;
+      else
+        extruder_error--;
+    }  
+  }
+  // found a high-to-low on channel A
+  else                                        
+  {
+    // check channel B to see which way
+    if (digitalRead(EXTRUDER_ENCODER_A_PIN) == LOW)
+    {
+      if (INVERT_QUADRATURE)
+        extruder_error--;
+      else
+        extruder_error++;
+    }
+    else
+    {
+      if (INVERT_QUADRATURE)
+        extruder_error++;
+      else
+        extruder_error--;
+    }  
+  }
 }
 
 void init_extruder()
@@ -108,8 +170,8 @@ void init_extruder()
 	digitalWrite(EXTRUDER_ENCODER_A_PIN, HIGH);
 	
 	//attach our interrupt handlers
-	attachInterrupt(0, extruder_read_quadrature, CHANGE);
-	attachInterrupt(1, extruder_read_quadrature, CHANGE);
+	attachInterrupt(0, extruder_read_quadrature_a, CHANGE);
+	attachInterrupt(1, extruder_read_quadrature_b, CHANGE);
 
 	//setup our timer interrupt stuff
 	setupTimer1Interrupt();
@@ -206,27 +268,36 @@ int extruder_sample_temperature(byte pin)
 void extruder_manage_speed()
 {
 	//is our speed changing?
-	int extruder_error_delta = last_extruder_error - extruder_error;
+	int extruder_error_delta = abs(last_extruder_error) - abs(extruder_error);
 	int extruder_delta_delta = last_extruder_delta - extruder_error_delta;
-	int extruder_error_factor = abs(extruder_error) / 4;
+	int extruder_error_factor = abs(extruder_error) / 2;
 	
 	//calculate our speed.
-	int speed = last_extruder_speed; 
-	speed += extruder_error_delta;
-	speed += extruder_delta_delta;
+	int speed = 0;
 	speed += extruder_error_factor;
-	
+        speed += last_extruder_speed / 2;
+	speed += extruder_error_delta * 2;
+	speed += extruder_delta_delta * 2;
+       
+        //why not average speeds?
+        speed = (speed + last_extruder_speed) / 2;
+
 	//do some bounds checking.
 	speed = max(speed, EXTRUDER_MIN_SPEED);
 	speed = min(speed, EXTRUDER_MAX_SPEED);
 
 	//temporary debug stuff.
-/*
-	Serial.print(&quot;e:&quot;);
-	Serial.print(extruder_error, DEC);
-	Serial.print(&quot; s:&quot;);
-	Serial.println(speed);
-*/
+	if (false &amp;&amp; random(500) == 1)
+	{
+		Serial.print(&quot;e:&quot;);
+		Serial.print(extruder_error, DEC);
+		Serial.print(&quot; d:&quot;);
+		Serial.print(extruder_error_delta, DEC);
+		Serial.print(&quot; dd:&quot;);
+		Serial.print(extruder_delta_delta, DEC);
+		Serial.print(&quot; s:&quot;);
+		Serial.println(speed);
+	}
 
 	//figure out which direction to move the motor
 	if (extruder_error &gt; 0)</diff>
      <filename>GCode_Interpreter_Experimental/extruder.pde</filename>
    </modified>
    <modified>
      <diff>@@ -139,7 +139,7 @@ void setTimer1Ticks(unsigned long ticks)
 	// we also then calculate the timer ceiling required. (ie what the counter counts to)
 	// the result is the timer counts up to the appropriate time and then fires an interrupt.
 
-	disableTimer1Interrupt();
+	//disableTimer1Interrupt();
 	setTimer1Ceiling(getTimer1Ceiling(ticks));
 	setTimer1Resolution(getTimer1Resolution(ticks));
 }
@@ -167,4 +167,4 @@ void setupTimer1Interrupt()
 	//start off with a slow frequency.
 	setTimer1Resolution(4);
 	setTimer1Ceiling(65535);
-}
\ No newline at end of file
+}</diff>
      <filename>GCode_Interpreter_Experimental/interrupt_routines.pde</filename>
    </modified>
    <modified>
      <diff>@@ -14,7 +14,15 @@ these are the firmwares that you would actually upload to the Arduino itself.  e
 
 /gcode
 
-this folder contains some experimental software that implements GCode on the Arduino!  there are 2 different programs:  there is a GCode Interpreter which runs on the Arduino and a GCode host which reads the GCode commands and sends them to the firmware one at a time.
+this folder contains some experimental software that implements GCode on the Arduino!
+
+/gcode/GCode_Interpreter
+
+this firmware receives and parses GCode commands over serial.  pretty rad.
+
+/gcode/GCode_Interpreter_Experimental
+
+this is an experimental gcode based firmware with support for a rotary encoder on the extruder
 
 /snap/3Axis_SNAP
 
@@ -27,32 +35,3 @@ this is the firmware that controls a Thermoplastic Extruder.  this is the corres
 /snap/Single_Arduino_SNAP
 
 this is the firmware that controls both the Cartesian Bot (3 steppers + limit switches) as well as a Thermoplastic Extruder.  This is the firmware you use for a single Arduino setup.  its pretty much maxed out.
-
-
-/testers
-
-this folder contains generic testing firmware that allows you to test a whole bunch of different things with your setup.  i found this to be very helpful when assembling the electronics and various parts of the system, or to debug things when the *_SNAP firmwares are not working properly.
-
-these are all standalone firmware.  you simply upload them to the arduino, and watch the output on the serial monitor screen.
-
-pay attention to the pin assignments at the top of the files.  most of the 3Axis ones have the same pin assignments as the 3Axis_SNAP
-
-/testers/3Axis_DDA_Tester
-
-this tester will move your cartesian bot in DDA mode from point to point randomly.  its useful for testing your machine and to see it work.  very fun.
-
-/testers/3Axis_HomeReset_Tester
-
-this tester will test the home/reset functionality of your machine.  dont upload it unless you have opto endstops installed and working properly!!!
-
-/testers/3Axis_Sensor_Tester
-
-this tester will test the opto endstops of your cartesian bot.  this is handy for testing the sensors before you need to use them, such as when running the home/reset tester.
-
-/testers/3Axis_Seek_Tester
-
-this tester will simply run the cartesian bot from point to point in seek mode (each axis runs as fast as possible)  it simply tests that your stepper motors are working and that they can move your bot around.
-
-/testers/3Axis_Speed_Tester
-
-this tester will test the various speeds of your stepper motors.  it will run each motor for 5 seconds at each RPM.  it starts at 1 RPM and goes all the way up to 500 RPM.  chances are that your stepper motors will not be able to do much above 250 RPM.  YMMV.
\ No newline at end of file</diff>
      <filename>README</filename>
    </modified>
    <modified>
      <diff>@@ -12,13 +12,11 @@ mkdir -p &quot;$TO_DIR/gcode&quot;
 
 echo &quot;Exporting files...&quot;
 svn export Single_Arduino_SNAP &quot;$TO_DIR/snap/Single_Arduino_SNAP&quot;
-svn export Single_Arduino_SNAP &quot;$TO_DIR/testers/Single_Arduino_Sensor_Tester&quot;
-svn export Single_Arduino_SNAP &quot;$TO_DIR/testers/Single_Arduino_DDA_Tester&quot;
 svn export 3Axis_SNAP &quot;$TO_DIR/snap/3Axis_SNAP&quot;
 svn export Extruder_SNAP &quot;$TO_DIR/snap/Extruder_SNAP&quot;
+svn export ../library &quot;$TO_DIR/library&quot;
 svn export GCode_Interpreter &quot;$TO_DIR/gcode/GCode_Interpreter&quot;
 svn export GCode_Interpreter_Experimental &quot;$TO_DIR/gcode/GCode_Interpreter_Experimental&quot;
-svn export ../library &quot;$TO_DIR/library&quot;
 
 cp README &quot;$TO_DIR/&quot;
 cp LICENSE &quot;$TO_DIR/&quot;</diff>
      <filename>package_release</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>ef98e60c5a93dc52eaf6c7ed5abb01ace17af51d</id>
    </parent>
  </parents>
  <author>
    <name>hoekstar</name>
    <email>hoekstar@cb376a5e-1013-0410-a455-b6b1f9ac8223</email>
  </author>
  <url>http://github.com/alx/reprap-arduino-firmware/commit/1611963088645fcde3490b14bc5750bb08e9a7d1</url>
  <id>1611963088645fcde3490b14bc5750bb08e9a7d1</id>
  <committed-date>2008-05-27T11:20:43-07:00</committed-date>
  <authored-date>2008-05-25T18:00:10-07:00</authored-date>
  <message>the encoder stuff works great!

git-svn-id: https://reprap.svn.sourceforge.net/svnroot/reprap/trunk/reprap/firmware/Arduino@1605 cb376a5e-1013-0410-a455-b6b1f9ac8223</message>
  <tree>a8a1db2222b6e368387d040d9693022bad3bb9c4</tree>
  <committer>
    <name>Alexandre Girard</name>
    <email>alx.girard@gmail.com</email>
  </committer>
</commit>
