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

Revision:
2:b3c668ec43ac
Parent:
1:66ee619f206b
Child:
3:7aaf0072cc22
diff -r 66ee619f206b -r b3c668ec43ac lissajous.cpp
--- a/lissajous.cpp	Thu Feb 06 08:45:02 2014 +0000
+++ b/lissajous.cpp	Thu Feb 20 09:27:18 2014 +0000
@@ -1,8 +1,10 @@
 #include "mbed.h"
-#include "rtos.h"
+//#include "rtos.h"
+#include "MODSERIAL.h"
 #include "cnc.h"
-extern  Serial pc;
-extern  void    mover   (struct pirbufgrain & ins)   ;
+extern  MODSERIAL pc;
+//extern  Serial pc;
+extern  void    move_to_XYZ   (struct pirbufgrain & ins)   ;
 /*
 This file contains one function:
 void    lissajous   ()  ;
@@ -12,17 +14,16 @@
 
 Thus far we have proved only that both finish at the same point (give or take a few microns)
 */
-bool    liss_active = false;    //  global flag used to prevent running more than once at a time
+//bool    liss_active = false;    //  global flag used to prevent running more than once at a time
 
-void    lissajous   (void const * arg_string)  {
+void    lissajous   (double feed_rate)  {
     const double    PI          = 4.0 * atan(1.0),  //3.142ish but more accurate
                     Deg2Rad     = PI / 180.0, //  degrees to radian conversion factor
-                    MaxX            = 6.40,     // Plot size X to move +/- MaxX
-                    MaxY            = 6.4,   //3.20,     // Plot size Y to move +/- MaxY
+                    MaxX            = 40.0,     // Plot size X to move +/- MaxX
+                    MaxY            = 25.0,     // Plot size Y to move +/- MaxY
                     StartAngDegX    = 0.0,
-                    StartAngDegY    = 0.0,  //10.0,
-                    FreqRatio       = 1.0,  //0.254,
-                    FeedRate        = 500.0;    // In mm per minute
+                    StartAngDegY    = 10.0,
+                    FreqRatio       = 0.255;
     const int       StepsPerRevX    = 100,
                     NumofXCycles    = 16;
     const double    AngleStepX  = (2.0 * PI / StepsPerRevX),
@@ -33,17 +34,22 @@
     double  AngleX = StartAngDegX * Deg2Rad,
             AngleY = StartAngDegY * Deg2Rad;
             
-    pc.printf("In lissajous func, Loading Lissajous\r\n");
-    while   (1) {
-        while   (!liss_active)  //  Other code to activate
-            osThreadYield();
+//    pc.printf("In lissajous func, Loading Lissajous\r\n");
+//    while   (1) {
+//        while   (!liss_active)  //  Other code to activate
+//            osThreadYield();
     //    liss_active = true;   //  this hapens in activating code
         pc.printf("In lissajous func, Starting Lissajous, has been activated\r\n");
+        Coords.x = 0.0;
+        Coords.y = 0.0;
+        Coords.z = 12.7;
+        Coords.f_rate = feed_rate;
+        move_to_XYZ (Coords);
         Coords.x = MaxX * cos(AngleX);  //  Coordinates of start position
         Coords.y = MaxY * sin(AngleY);  //  assembled into packet for motion controller
+        move_to_XYZ (Coords);
         Coords.z = 0.0;
-        Coords.f_rate = FeedRate;
-        mover(Coords);
+        move_to_XYZ (Coords);
     
         for (int i = 0; i < NumofXCycles; i++)   {      // Outer loop 'NumofXCycles' times
             for (int j = 0; j < StepsPerRevX; j++)   {  // Inner loop 'StepsPerRevX' times
@@ -51,16 +57,22 @@
                 AngleY += AngleStepY;
                 Coords.x = MaxX * cos(AngleX);
                 Coords.y = MaxY * sin(AngleY);
-                mover(Coords);
-                osThreadYield();
+                move_to_XYZ (Coords);
+//                osThreadYield();
             }
+            pc.printf("liss cyc %d\r\n", i);
         }
+        Coords.z = 100.0;
+        move_to_XYZ (Coords);
+        Coords.x = 0.0;
+        Coords.y = 0.0;
+        move_to_XYZ (Coords);
         
         pc.printf("Lissajous finish point X%f, Y%f\r\n", Coords.x, Coords.y);
-        liss_active = false;
+//        liss_active = false;
         pc.printf("Leaving liss\r\n");
-        osThreadYield();    //  terminate would be better here
-    }   //  end of while(1)
+//        osThreadYield();    //  terminate would be better here
+//    }   //  end of while(1)
 }
 
 /*