Code to drive a CNC machine via a PC LPT port lookalike 25 pin 'D', experiment in 'PC/Mach3' replacement. Designed to compile and run on mbed LPC1768, Freescale KL25Z and Freescale KL46Z. Proved on LPC1768 and KL25Z, problem with serial port on KL46Z. Reads subset of 'G Codes' through usb/serial port and drives 3 stepper/servo drives for X, Y and Z, also similar Step/Dir outputs for spindle motor control. Emulates PC LPT, outputs 'charge pump', proved driving Seig KX3 CNC mill

Dependencies:   MODSERIAL mbed

Thu Feb 06 08:45:02 2014 +0000
Currently creates 3 sets of Step and Dir signals for stepper motor drivers.  Accepts via putty etc, as yet minimal set of 'G Codes' for CNC - G0, G1, G2 and G3.  Still wip.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JonFreeman 1:66ee619f206b 1 const double TWO_PI = 8.0 * atan(1.0);
JonFreeman 1:66ee619f206b 2 const double epsilon = 1e-5;
JonFreeman 1:66ee619f206b 3 struct pirbufgrain {
JonFreeman 1:66ee619f206b 4 double x,
JonFreeman 1:66ee619f206b 5 y,
JonFreeman 1:66ee619f206b 6 z,
JonFreeman 1:66ee619f206b 7 c,
JonFreeman 1:66ee619f206b 8 f_rate;
JonFreeman 1:66ee619f206b 9 } ;
JonFreeman 0:5d0f270bfc87 10
JonFreeman 0:5d0f270bfc87 11 struct singleGparam { // Place to put all we know about 'x' or 'j' etc parameter from G Code line
JonFreeman 0:5d0f270bfc87 12 double dbl;
JonFreeman 0:5d0f270bfc87 13 unsigned long ul;
JonFreeman 0:5d0f270bfc87 14 int i, c;
JonFreeman 0:5d0f270bfc87 15 bool changed; // Flagged true when new value for this axis found in Gcode line, false otherwise
JonFreeman 0:5d0f270bfc87 16 } ;
JonFreeman 0:5d0f270bfc87 17
JonFreeman 0:5d0f270bfc87 18 struct Gparams { // Where possibly messy G code line gets ordered and sorted into
JonFreeman 0:5d0f270bfc87 19 struct singleGparam x, y, z, i, j, r, a, b, c, d; // After sorting, know where to find any X, Y etc values !
JonFreeman 0:5d0f270bfc87 20 } ;
JonFreeman 0:5d0f270bfc87 21
JonFreeman 1:66ee619f206b 22 struct digital_readouts { // DROs keep count of 'Step' positive edges detected in interrupt handler
JonFreeman 1:66ee619f206b 23 signed long x, y, z; // Could easily expand up to six or more dros
JonFreeman 0:5d0f270bfc87 24 bool dro_output; // To enabe / disable output to terminal
JonFreeman 0:5d0f270bfc87 25 } ;
JonFreeman 0:5d0f270bfc87 26
JonFreeman 0:5d0f270bfc87 27 extern const double n_for_onemmpermin, feed_rate_max, feed_rate_min, spindle_min, spindle_max;
JonFreeman 1:66ee619f206b 28 //extern const long pulses_per_mm, max_mm_per_min, interrupt_period_us;
JonFreeman 1:66ee619f206b 29 extern const double pulses_per_mm, max_mm_per_min, interrupt_period_us;