
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
arith.cpp
- Committer:
- JonFreeman
- Date:
- 2014-02-20
- Revision:
- 2:b3c668ec43ac
- Parent:
- 1:66ee619f206b
File content as of revision 2:b3c668ec43ac:
#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); }