This commit is contained in:
Anders Sandstrom
2022-01-17 17:13:38 +01:00
parent 952c0d4cf5
commit 4143351780
13 changed files with 99 additions and 85 deletions

4
.gitignore vendored
View File

@@ -3,5 +3,5 @@
*.elf
*.DS_Store
*.d
README.md
O.*
*.Makefile

4
build/.gitignore vendored
View File

@@ -1,4 +0,0 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

View File

@@ -20,7 +20,6 @@
#include "grbl.h"
void coolant_init()
{
printf("%s:%s:%d Not supported yet..\n",__FILE__,__FUNCTION__,__LINE__);

View File

@@ -28,7 +28,8 @@
// ecmc added
#include <stdlib.h>
#include <string.h>
#define EEPROM_DUMMY_FILE ./ecmc_grbl_eeprom.txt
#include <stdio.h>
#define EEPROM_DUMMY_FILE "./ecmc_grbl_eeprom.txt"
#define EEPROM_MEM_SIZE 512
char buffer[EEPROM_MEM_SIZE];
@@ -46,7 +47,7 @@ char buffer[EEPROM_MEM_SIZE];
/* Define to reduce code size. */
//#define EEPROM_IGNORE_SELFPROG //!< Remove SPM flag polling.
unsigned char ecmc_mem_to_file();
// Init file
void ecmc_init_file() {
printf("%s:%s:%d EEPROM simulated by file..\n",__FILE__,__FUNCTION__,__LINE__);
@@ -67,7 +68,7 @@ unsigned char ecmc_file_to_mem()
return 1;
}
unsigned char c = 0;
for (int i = 0, i < EEPROM_MEM_SIZE ; i++) {
for (int i = 0; i < EEPROM_MEM_SIZE ; i++) {
// Get the characters
buffer[i] = fgetc(fh);
}
@@ -77,7 +78,7 @@ unsigned char ecmc_file_to_mem()
}
// Write buffer[] to file
unsigned char void ecmc_mem_to_file()
unsigned char ecmc_mem_to_file()
{
printf("%s:%s:%d EEPROM simulated by file..\n",__FILE__,__FUNCTION__,__LINE__);
@@ -88,7 +89,7 @@ unsigned char void ecmc_mem_to_file()
printf("something went wrong and file could not be opened");
return 1;
}
for (int i = 0, i < EEPROM_MEM_SIZE ; i++) {
for (int i = 0; i < EEPROM_MEM_SIZE ; i++) {
// Get the characters
fputc (buffer[i], fh);
}

View File

@@ -37,6 +37,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
// Define the Grbl system include files. NOTE: Do not alter organization.
#include "config.h"

View File

@@ -20,7 +20,7 @@
*/
#include "grbl.h"
#include "ecmcMotion.h"
//#include "ecmcMotion.h"
// Homing axis search distance multiplier. Computed by this value times the cycle travel.
#ifndef HOMING_AXIS_SEARCH_SCALAR
@@ -413,7 +413,7 @@ void limits_go_home(uint8_t cycle_mask)
// }
// }
// sys.step_control = STEP_CONTROL_NORMAL_OP; // Return step control to normal operation.
//}
}
// Performs a soft limit check. Called from mc_line() only. Assumes the machine has been homed,

View File

@@ -21,7 +21,6 @@
#include "grbl.h"
// Execute linear motion in absolute millimeter coordinates. Feed rate given in millimeters/second
// unless invert_feed_rate is true. Then the feed_rate means that the motion should be completed in
// (1 minute)/feed_rate time.

View File

@@ -26,8 +26,6 @@
//added for ecmc
#include <time.h>
CLOCK_MONOTONIC
// Extracts a floating point value from a string. The following code is based loosely on
// the avr-libc strtod() function by Michael Stumpf and Dmitry Xmelkov and many freely
@@ -115,9 +113,13 @@ uint8_t read_float(char *line, uint8_t *char_counter, float *float_ptr)
// Non-blocking delay function used for general operation and suspend features.
void delay_sec(float seconds, uint8_t mode)
{
clock_nanosleep(CLOCK_MONOTONIC,0,1E9);
struct timespec deadline;
clock_gettime(CLOCK_MONOTONIC,&deadline);
deadline.tv_sec+=1*seconds;
clock_nanosleep(CLOCK_MONOTONIC,TIMER_ABSTIME, &deadline,NULL);
// NOTE!!!: mode not used!!!!
//uint16_t i = ceil(1000/DWELL_TIME_STEP*seconds);
//while (i-- > 0) {
// if (sys.abort) { return; }
@@ -137,7 +139,15 @@ void delay_sec(float seconds, uint8_t mode)
// which only accepts constants in future compiler releases.
void delay_ms(uint16_t ms)
{
clock_nanosleep(CLOCK_MONOTONIC,0,1E6);
struct timespec deadline;
clock_gettime(CLOCK_MONOTONIC,&deadline);
deadline.tv_nsec+=1E6*ms;
if(deadline.tv_nsec>=1E9) {
deadline.tv_nsec-=1E6;
deadline.tv_sec++;
}
clock_nanosleep(CLOCK_MONOTONIC,TIMER_ABSTIME, &deadline,NULL);
//while ( ms-- ) { _delay_ms(1); }
}
@@ -147,7 +157,15 @@ void delay_ms(uint16_t ms)
// efficiently with larger delays, as the counter adds parasitic time in each iteration.
void delay_us(uint32_t us)
{
clock_nanosleep(CLOCK_MONOTONIC,0,1E3);
struct timespec deadline;
clock_gettime(CLOCK_MONOTONIC,&deadline);
deadline.tv_nsec+=1E3*us;
if(deadline.tv_nsec>=1E9) {
deadline.tv_nsec-=1E6;
deadline.tv_sec++;
}
clock_nanosleep(CLOCK_MONOTONIC,TIMER_ABSTIME, &deadline,NULL);
//while (us) {
// if (us < 10) {

View File

@@ -42,6 +42,7 @@
#endif
// Conversions
#define F_CPU (16000000)
#define MM_PER_INCH (25.40)
#define INCH_PER_MM (0.0393701)
#define TICKS_PER_MICROSECOND (F_CPU/1000000)

View File

@@ -34,7 +34,7 @@ void printString(const char *s)
// Print a string stored in PGM-memory
void printPgmString(const char *s)
{
printf("%s:%s:%d: Not supported\n",__FILE__,__FUNCTION__,__LINE__,s);
printf("%s:%s:%d: %s\n",__FILE__,__FUNCTION__,__LINE__,s);
// char c;
// while ((c = pgm_read_byte_near(s++)))
// serial_write(c);
@@ -88,7 +88,7 @@ void print_uint8_base10(uint8_t n)
void print_uint8_base2_ndigit(uint8_t n, uint8_t digits) {
printf("%s:%s:%d:\n",__FILE__,__FUNCTION__,__LINE__,n);
printf("%s:%s:%d:%d\n",__FILE__,__FUNCTION__,__LINE__,n);
unsigned char buf[digits];
uint8_t i = 0;
@@ -130,7 +130,7 @@ void print_uint32_base10(uint32_t n)
void printInteger(long n)
{
printf("%s:%s:%d:%d\n",__FILE__,__FUNCTION__,__LINE__,n);
printf("%s:%s:%d:%ld\n",__FILE__,__FUNCTION__,__LINE__,n);
//if (n < 0) {
// serial_write('-');

View File

@@ -23,7 +23,7 @@
settings_t settings;
const __flash settings_t defaults = {\
const settings_t defaults = {\
.pulse_microseconds = DEFAULT_STEP_PULSE_MICROSECONDS,
.stepper_idle_lock_time = DEFAULT_STEPPER_IDLE_LOCK_TIME,
.step_invert_mask = DEFAULT_STEPPING_INVERT_MASK,

View File

@@ -21,7 +21,6 @@
#include "grbl.h"
#ifdef VARIABLE_SPINDLE
static float pwm_gradient; // Precalulated value to speed up rpm to PWM conversions.
#endif
@@ -149,9 +148,9 @@ void spindle_stop()
// } else {
// SPINDLE_TCCRA_REGISTER |= (1<<SPINDLE_COMB_BIT); // Ensure PWM output is enabled.
// }
// #endif
//
}
#endif
//#ifdef ENABLE_PIECEWISE_LINEAR_SPINDLE

View File

@@ -20,7 +20,8 @@
*/
#include "grbl.h"
#include <pthread.h>
#include <unistd.h>
// Some useful constants.
#define DT_SEGMENT (1.0/(ACCELERATION_TICKS_PER_SECOND*60.0)) // min/segment
@@ -223,28 +224,27 @@ static bool stepperInterruptEnable = 0;
void ecmc_grbl_main_thread();
pthread_t tid;
void ecmc_dummy_thread() {
void *ecmc_dummy_thread(void *ptr) {
while (stepperInterruptEnable) {
for(int i=0; i< 30;i++) {
ecmc_grbl_main_thread();
}
printf("%s:%s:%d Positions(x,y,x)=%lf,%lf,%lf..\n",__FILE__,__FUNCTION__,__LINE__,sys_position[X_AXIS], sys_position[Y_AXIS],sys_position[Z_AXIS] );
printf("%s:%s:%d Positions(x,y,x)=%d,%d,%d..\n",__FILE__,__FUNCTION__,__LINE__,sys_position[X_AXIS], sys_position[Y_AXIS],sys_position[Z_AXIS] );
sleep(0.001);
}
}
void ecmc_start_dummy_thread()
{
int i = 0;
int err;
err = pthread_create(&(tid), NULL, &ecmc_dummy_thread, NULL);
err = pthread_create(&(tid), NULL, *ecmc_dummy_thread, NULL);
if (err != 0)
printf("\ncan't create thread :[%s]", strerror(err));
else
printf("\n Thread created successfully\n");
i++;
return 0;
return;
}
// Stepper state initialization. Cycle should only start if the st.cycle_start flag is
@@ -252,22 +252,22 @@ void ecmc_start_dummy_thread()
void st_wake_up()
{
// Enable stepper drivers.
if (bit_istrue(settings.flags,BITFLAG_INVERT_ST_ENABLE)) { STEPPERS_DISABLE_PORT |= (1<<STEPPERS_DISABLE_BIT); }
else { STEPPERS_DISABLE_PORT &= ~(1<<STEPPERS_DISABLE_BIT); }
//if (bit_istrue(settings.flags,BITFLAG_INVERT_ST_ENABLE)) { STEPPERS_DISABLE_PORT |= (1<<STEPPERS_DISABLE_BIT); }
//else { STEPPERS_DISABLE_PORT &= ~(1<<STEPPERS_DISABLE_BIT); }
// Initialize stepper output bits to ensure first ISR call does not step.
st.step_outbits = step_port_invert_mask;
// Initialize step pulse timing from settings. Here to ensure updating after re-writing.
#ifdef STEP_PULSE_DELAY
// Set total step pulse time after direction pin set. Ad hoc computation from oscilloscope.
st.step_pulse_time = -(((settings.pulse_microseconds+STEP_PULSE_DELAY-2)*TICKS_PER_MICROSECOND) >> 3);
// Set delay between direction pin write and step command.
OCR0A = -(((settings.pulse_microseconds)*TICKS_PER_MICROSECOND) >> 3);
#else // Normal operation
// Set step pulse time. Ad hoc computation from oscilloscope. Uses two's complement.
st.step_pulse_time = -(((settings.pulse_microseconds-2)*TICKS_PER_MICROSECOND) >> 3);
#endif
// st.step_outbits = step_port_invert_mask;
//
// // Initialize step pulse timing from settings. Here to ensure updating after re-writing.
// #ifdef STEP_PULSE_DELAY
// // Set total step pulse time after direction pin set. Ad hoc computation from oscilloscope.
// st.step_pulse_time = -(((settings.pulse_microseconds+STEP_PULSE_DELAY-2)*TICKS_PER_MICROSECOND) >> 3);
// // Set delay between direction pin write and step command.
// //OCR0A = -(((settings.pulse_microseconds)*TICKS_PER_MICROSECOND) >> 3);
// #else // Normal operation
// // Set step pulse time. Ad hoc computation from oscilloscope. Uses two's complement.
// st.step_pulse_time = -(((settings.pulse_microseconds-2)*TICKS_PER_MICROSECOND) >> 3);
// #endif
// Enable Stepper Driver Interrupt
//TIMSK1 |= (1<<OCIE1A);
@@ -296,9 +296,9 @@ void st_go_idle()
delay_ms(settings.stepper_idle_lock_time);
pin_state = true; // Override. Disable steppers.
}
if (bit_istrue(settings.flags,BITFLAG_INVERT_ST_ENABLE)) { pin_state = !pin_state; } // Apply pin invert.
if (pin_state) { STEPPERS_DISABLE_PORT |= (1<<STEPPERS_DISABLE_BIT); }
else { STEPPERS_DISABLE_PORT &= ~(1<<STEPPERS_DISABLE_BIT); }
// if (bit_istrue(settings.flags,BITFLAG_INVERT_ST_ENABLE)) { pin_state = !pin_state; } // Apply pin invert.
// if (pin_state) { STEPPERS_DISABLE_PORT |= (1<<STEPPERS_DISABLE_BIT); }
// else { STEPPERS_DISABLE_PORT &= ~(1<<STEPPERS_DISABLE_BIT); }
}
@@ -358,23 +358,23 @@ void ecmc_grbl_main_thread()
if (busy) { return; } // The busy-flag is used to avoid reentering this interrupt
// Set the direction pins a couple of nanoseconds before we step the steppers
DIRECTION_PORT = (DIRECTION_PORT & ~DIRECTION_MASK) | (st.dir_outbits & DIRECTION_MASK);
#ifdef ENABLE_DUAL_AXIS
DIRECTION_PORT_DUAL = (DIRECTION_PORT_DUAL & ~DIRECTION_MASK_DUAL) | (st.dir_outbits_dual & DIRECTION_MASK_DUAL);
#endif
// Then pulse the stepping pins
#ifdef STEP_PULSE_DELAY
st.step_bits = (STEP_PORT & ~STEP_MASK) | st.step_outbits; // Store out_bits to prevent overwriting.
#ifdef ENABLE_DUAL_AXIS
st.step_bits_dual = (STEP_PORT_DUAL & ~STEP_MASK_DUAL) | st.step_outbits_dual;
#endif
#else // Normal operation
STEP_PORT = (STEP_PORT & ~STEP_MASK) | st.step_outbits;
#ifdef ENABLE_DUAL_AXIS
STEP_PORT_DUAL = (STEP_PORT_DUAL & ~STEP_MASK_DUAL) | st.step_outbits_dual;
#endif
#endif
//DIRECTION_PORT = (DIRECTION_PORT & ~DIRECTION_MASK) | (st.dir_outbits & DIRECTION_MASK);
//#ifdef ENABLE_DUAL_AXIS
// DIRECTION_PORT_DUAL = (DIRECTION_PORT_DUAL & ~DIRECTION_MASK_DUAL) | (st.dir_outbits_dual & DIRECTION_MASK_DUAL);
//#endif
//
//// Then pulse the stepping pins
//#ifdef STEP_PULSE_DELAY
// st.step_bits = (STEP_PORT & ~STEP_MASK) | st.step_outbits; // Store out_bits to prevent overwriting.
// #ifdef ENABLE_DUAL_AXIS
// st.step_bits_dual = (STEP_PORT_DUAL & ~STEP_MASK_DUAL) | st.step_outbits_dual;
// #endif
//#else // Normal operation
// STEP_PORT = (STEP_PORT & ~STEP_MASK) | st.step_outbits;
// #ifdef ENABLE_DUAL_AXIS
// STEP_PORT_DUAL = (STEP_PORT_DUAL & ~STEP_MASK_DUAL) | st.step_outbits_dual;
// #endif
//#endif
// Enable step pulse reset timer so that The Stepper Port Reset Interrupt can reset the signal after
// exactly settings.pulse_microseconds microseconds, independent of the main Timer1 prescaler.
@@ -588,14 +588,14 @@ void st_reset()
st.dir_outbits = dir_port_invert_mask; // Initialize direction bits to default.
// Initialize step and direction port pins.
STEP_PORT = (STEP_PORT & ~STEP_MASK) | step_port_invert_mask;
DIRECTION_PORT = (DIRECTION_PORT & ~DIRECTION_MASK) | dir_port_invert_mask;
#ifdef ENABLE_DUAL_AXIS
st.dir_outbits_dual = dir_port_invert_mask_dual;
STEP_PORT_DUAL = (STEP_PORT_DUAL & ~STEP_MASK_DUAL) | step_port_invert_mask_dual;
DIRECTION_PORT_DUAL = (DIRECTION_PORT_DUAL & ~DIRECTION_MASK_DUAL) | dir_port_invert_mask_dual;
#endif
//STEP_PORT = (STEP_PORT & ~STEP_MASK) | step_port_invert_mask;
//DIRECTION_PORT = (DIRECTION_PORT & ~DIRECTION_MASK) | dir_port_invert_mask;
//
//#ifdef ENABLE_DUAL_AXIS
// st.dir_outbits_dual = dir_port_invert_mask_dual;
// STEP_PORT_DUAL = (STEP_PORT_DUAL & ~STEP_MASK_DUAL) | step_port_invert_mask_dual;
// DIRECTION_PORT_DUAL = (DIRECTION_PORT_DUAL & ~DIRECTION_MASK_DUAL) | dir_port_invert_mask_dual;
//#endif
}
@@ -603,14 +603,14 @@ void st_reset()
void stepper_init()
{
// Configure step and direction interface pins
STEP_DDR |= STEP_MASK;
STEPPERS_DISABLE_DDR |= 1<<STEPPERS_DISABLE_BIT;
DIRECTION_DDR |= DIRECTION_MASK;
#ifdef ENABLE_DUAL_AXIS
STEP_DDR_DUAL |= STEP_MASK_DUAL;
DIRECTION_DDR_DUAL |= DIRECTION_MASK_DUAL;
#endif
// STEP_DDR |= STEP_MASK;
// STEPPERS_DISABLE_DDR |= 1<<STEPPERS_DISABLE_BIT;
// DIRECTION_DDR |= DIRECTION_MASK;
//
// #ifdef ENABLE_DUAL_AXIS
// STEP_DDR_DUAL |= STEP_MASK_DUAL;
// DIRECTION_DDR_DUAL |= DIRECTION_MASK_DUAL;
// #endif
//// Configure Timer 1: Stepper Driver Interrupt
//TCCR1B &= ~(1<<WGM13); // waveform generation = 0100 = CTC