Permalink
Browse files

graycode stepper operation, distilled to one line in dda.c

Which includes a seperate file (graycode.c) with the defines and additional variable declaration.
I went with the "graycode" spelling, as there's about ten times as many hits for that as for "greycode" on google. I've read that both spellings are acceptable, but whatever.

Signed-off-by: Michael Moon <triffid.hunter@gmail.com>
  • Loading branch information...
1 parent 021ac75 commit fe034d5e3589607897f76c90f79f3b0fd9623900 @jgilmore jgilmore committed with Feb 2, 2011
Showing with 92 additions and 0 deletions.
  1. +1 −0 dda.c
  2. +91 −0 graycode.c
View
1 dda.c
@@ -12,6 +12,7 @@
#include "sersendf.h"
#include "pinio.h"
#include "config.h"
+//#include "graycode.c"
#ifdef DC_EXTRUDER
#include "heater.h"
View
@@ -0,0 +1,91 @@
+/*
+ This file contains defines that change the way the step/dir pins work, such
+ that they become interchangable graycode signaling pins. If your stepper
+ driver expects coil polarity signals instead of step/dir, this will allow
+ them to work with reprap.
+
+ By default, X Y and Z are graycode, while E remains step/dir. If this isn't what
+ you want, edit the lines just below.
+*/
+#define X_GREYCODE
+#define Y_GREYCODE
+#define Z_GREYCODE
+//#define E_GREYCODE
+
+
+/*
+ X Stepper
+*/
+#ifdef X_GREYCODE
+ #undef x_step
+ #undef _x_step
+ #undef x_direction
+ #define x_step() {\
+ x_greycode+=stored_x_direction;\
+ WRITE(X_STEP_PIN,(x_greycode>>1)&1);\
+ WRITE(X_DIR_PIN,((x_greycode>>1)^x_greycode)&1);\
+ }
+ #define _x_step(st)
+ #define x_direction(dir) stored_x_direction=(dir)?1:-1
+ int8_t stored_x_direction;
+ int8_t x_greycode;
+#endif
+
+/*
+ Y Stepper
+*/
+
+#ifdef Y_GREYCODE
+ #undef y_step
+ #undef _y_step
+ #undef y_direction
+ #define y_step() {\
+ y_greycode+=stored_y_direction;\
+ WRITE(Y_STEP_PIN,(y_greycode>>1)&1);\
+ WRITE(Y_DIR_PIN,((y_greycode>>1)^y_greycode)&1);\
+ }
+ #define _y_step(st)
+ #define y_direction(dir) stored_y_direction=(dir)?1:-1
+ int8_t stored_y_direction;
+ int8_t y_greycode;
+#endif
+
+/*
+ Z Stepper
+*/
+
+#ifdef Z_GREYCODE
+ #undef z_step
+ #undef _z_step
+ #undef z_direction
+ #define z_step() {\
+ z_greycode+=stored_z_direction;\
+ WRITE(Z_STEP_PIN,(z_greycode>>1)&1);\
+ WRITE(Z_DIR_PIN,((z_greycode>>1)^z_greycode)&1);\
+ }
+ #define _z_step(st)
+ #define z_direction(dir) stored_z_direction=(dir)?1:-1
+ int8_t stored_z_direction;
+ int8_t z_greycode;
+#endif
+
+/*
+ Extruder
+*/
+
+#ifdef E_GREYCODE
+ #undef e_step
+ #undef _e_step
+ #undef e_direction
+ #define e_step() {\
+ e_greycode+=stored_e_direction;\
+ WRITE(E_STEP_PIN,(e_greycode>>1)&1);\
+ WRITE(E_DIR_PIN,((e_greycode>>1)^e_greycode)&1);\
+ }
+ #define _e_step(st)
+ #define e_direction(dir) stored_e_direction=(dir)?1:-1
+ int8_t stored_e_direction;
+ int8_t e_greycode;
+#endif
+
+

0 comments on commit fe034d5

Please sign in to comment.