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
Diff: arith.cpp
- Revision:
- 3:7aaf0072cc22
- Parent:
- 2:b3c668ec43ac
--- a/arith.cpp Thu Feb 20 09:27:18 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -#include "mbed.h" -#include "cnc.h" -using namespace std; - -const double ball_screw_pitch_mm = 4.0, // KX3 has 4mm ball screws - motor_step_per_rev = 200.0, // KX3 has 200 step per rev steppers - micro_steps = 10.0, // Arc Eurotrade choice 2,4,5,8,10,16,20,25,32,40,50,64,100,125,128 - pulses_per_mm = micro_steps * motor_step_per_rev / ball_screw_pitch_mm, - - interrupt_period_us = 32.0,//24.0, //16 is possible with Mbed LPC1768 - interrupt_freq_Hz = 1000000.0 / interrupt_period_us, // Serious limit when doing all in software, no real limit with FPGA - max_pulse_freq_Hz = interrupt_freq_Hz / 3.25, // strictly 2.0, but allow a good margin - max_mm_per_min = 60.0 * max_pulse_freq_Hz / pulses_per_mm, -// n_for_onemmpermin = pulses_per_mm * interrupt_period_us * pow(2.0,32) / 60000000.0, // n pir to produce 1mm/min travel - n_for_onemmpermin = pulses_per_mm * interrupt_period_us * pow(2.0,31) / 60000000.0, // n pir to produce 1mm/min travel - // note power reduced from 32to 31 as interrupt handler now issued step pulse on both edges - feed_rate_max = max_mm_per_min, - spindle_factor = interrupt_period_us * 4280, - spindle_max = 5000.0; -//The output frequency F<sub>out</sub> = 'Kernel Speed (Hz)' * n / (2 to the power of 32) - -struct Gparams last_position; -void grain_clr (struct singleGparam & g) { - g.dbl = 0.0; - g.ul = 0L; - g.i = g.c = 0; - g.changed = false; -} -void pirs_clr2 (struct Gparams & p) { - grain_clr (p.x); grain_clr (p.y); grain_clr (p.z); grain_clr (p.i); grain_clr (p.j); - grain_clr (p.r); grain_clr (p.a); grain_clr (p.b); grain_clr (p.c); grain_clr (p.d); -} -void more_setup () { - pirs_clr2 (last_position); -} - -