Johhny Firmware sync

This commit is contained in:
michalprusa 2017-06-17 15:42:48 +02:00
parent 1224705edc
commit c83b1833bc
7 changed files with 102 additions and 15 deletions

View File

@ -1316,6 +1316,8 @@ void loop()
manage_inactivity(); manage_inactivity();
checkHitEndstops(); checkHitEndstops();
lcd_update(); lcd_update();
tmc2130_check_overtemp();
} }
void get_command() void get_command()

View File

@ -294,7 +294,7 @@ bool SdBaseFile::getFilename(char* name) {
return true; return true;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void SdBaseFile::getpos(fpos_t* pos) { void SdBaseFile::getpos(filepos_t* pos) {
pos->position = curPosition_; pos->position = curPosition_;
pos->cluster = curCluster_; pos->cluster = curCluster_;
} }
@ -925,7 +925,7 @@ bool SdBaseFile::openRoot(SdVolume* vol) {
* \return The byte if no error and not at eof else -1; * \return The byte if no error and not at eof else -1;
*/ */
int SdBaseFile::peek() { int SdBaseFile::peek() {
fpos_t pos; filepos_t pos;
getpos(&pos); getpos(&pos);
int c = read(); int c = read();
if (c >= 0) setpos(&pos); if (c >= 0) setpos(&pos);
@ -1492,7 +1492,7 @@ bool SdBaseFile::seekSet(uint32_t pos) {
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void SdBaseFile::setpos(fpos_t* pos) { void SdBaseFile::setpos(filepos_t* pos) {
curPosition_ = pos->position; curPosition_ = pos->position;
curCluster_ = pos->cluster; curCluster_ = pos->cluster;
} }

View File

@ -35,12 +35,12 @@
* \brief internal type for istream * \brief internal type for istream
* do not use in user apps * do not use in user apps
*/ */
struct fpos_t { struct filepos_t {
/** stream position */ /** stream position */
uint32_t position; uint32_t position;
/** cluster for position */ /** cluster for position */
uint32_t cluster; uint32_t cluster;
fpos_t() : position(0), cluster(0) {} filepos_t() : position(0), cluster(0) {}
}; };
// use the gnu style oflag in open() // use the gnu style oflag in open()
@ -196,11 +196,11 @@ class SdBaseFile {
/** get position for streams /** get position for streams
* \param[out] pos struct to receive position * \param[out] pos struct to receive position
*/ */
void getpos(fpos_t* pos); void getpos(filepos_t* pos);
/** set position for streams /** set position for streams
* \param[out] pos struct with value for new position * \param[out] pos struct with value for new position
*/ */
void setpos(fpos_t* pos); void setpos(filepos_t* pos);
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool close(); bool close();
bool contiguousRange(uint32_t* bgnBlock, uint32_t* endBlock); bool contiguousRange(uint32_t* bgnBlock, uint32_t* endBlock);

View File

@ -385,10 +385,6 @@
#define MOTOR_CURRENT_PWM_XY_PIN 46 #define MOTOR_CURRENT_PWM_XY_PIN 46
#define MOTOR_CURRENT_PWM_Z_PIN 45 #define MOTOR_CURRENT_PWM_Z_PIN 45
#define MOTOR_CURRENT_PWM_E_PIN 44 #define MOTOR_CURRENT_PWM_E_PIN 44
//Motor current PWM conversion, PWM value = MotorCurrentSetting * 255 / range
#define MOTOR_CURRENT_PWM_RANGE 2000
#define DEFAULT_PWM_MOTOR_CURRENT {1300, 1300, 1300}
//#define DEFAULT_PWM_MOTOR_CURRENT {1100, 1100, 1300}
#define SDPOWER -1 #define SDPOWER -1
#define SDSS 53 #define SDSS 53
#define LED_PIN 13 #define LED_PIN 13

View File

@ -633,6 +633,61 @@ ISR(TIMER1_COMPA_vect)
} }
} }
#ifdef HAVE_TMC2130_DRIVERS #ifdef HAVE_TMC2130_DRIVERS
uint32_t tmc2130_read(uint8_t chipselect, uint8_t address)
{
uint32_t val32;
uint8_t val0;
uint8_t val1;
uint8_t val2;
uint8_t val3;
uint8_t val4;
//datagram1 - read request (address + dummy write)
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE3));
digitalWrite(chipselect,LOW);
SPI.transfer(address);
SPI.transfer(0);
SPI.transfer(0);
SPI.transfer(0);
SPI.transfer(0);
digitalWrite(chipselect, HIGH);
SPI.endTransaction();
//datagram2 - response
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE3));
digitalWrite(chipselect,LOW);
val0 = SPI.transfer(0);
val1 = SPI.transfer(0);
val2 = SPI.transfer(0);
val3 = SPI.transfer(0);
val4 = SPI.transfer(0);
digitalWrite(chipselect, HIGH);
SPI.endTransaction();
#ifdef TMC_DBG_READS
MYSERIAL.print("SPIRead 0x");
MYSERIAL.print(address,HEX);
MYSERIAL.print(" Status:");
MYSERIAL.print(val0 & 0b00000111,BIN);
MYSERIAL.print(" ");
MYSERIAL.print(val1,BIN);
MYSERIAL.print(" ");
MYSERIAL.print(val2,BIN);
MYSERIAL.print(" ");
MYSERIAL.print(val3,BIN);
MYSERIAL.print(" ");
MYSERIAL.print(val4,BIN);
#endif
val32 = (uint32_t)val1<<24 | (uint32_t)val2<<16 | (uint32_t)val3<<8 | (uint32_t)val4;
#ifdef TMC_DBG_READS
MYSERIAL.print(" 0x");
MYSERIAL.println(val32,HEX);
#endif
return val32;
}
void tmc2130_write(uint8_t chipselect, uint8_t address,uint8_t wval1,uint8_t wval2,uint8_t wval3,uint8_t wval4) void tmc2130_write(uint8_t chipselect, uint8_t address,uint8_t wval1,uint8_t wval2,uint8_t wval3,uint8_t wval4)
{ {
uint32_t val32; uint32_t val32;
@ -739,6 +794,36 @@ ISR(TIMER1_COMPA_vect)
tmc2130_write(cs,0x13,0x00,0x00,0x00,0x00); // TMC LJ -> Adds possibility to swtich from stealthChop to spreadCycle automatically tmc2130_write(cs,0x13,0x00,0x00,0x00,0x00); // TMC LJ -> Adds possibility to swtich from stealthChop to spreadCycle automatically
} }
void tmc2130_disable_motor(uint8_t driver)
{
uint8_t cs[4] = { X_TMC2130_CS, Y_TMC2130_CS, Z_TMC2130_CS, E0_TMC2130_CS };
tmc2130_write(cs[driver],0x6C,0,01,0,0);
}
void tmc2130_check_overtemp()
{
const static char TMC_OVERTEMP_MSG[] PROGMEM = "TMC DRIVER OVERTEMP ";
uint8_t cs[4] = { X_TMC2130_CS, Y_TMC2130_CS, Z_TMC2130_CS, E0_TMC2130_CS };
static uint32_t checktime = 0;
//drivers_disabled[0] = 1; //TEST
if( millis() - checktime > 1000 ) {
for(int i=0;i<4;i++) {
uint32_t drv_status = tmc2130_read(cs[i], 0x6F); //0x6F DRV_STATUS
if(drv_status & ((uint32_t)1<<26)) { // BIT 26 - over temp prewarning ~120C (+-20C)
SERIAL_ERRORRPGM(TMC_OVERTEMP_MSG);
SERIAL_ECHOLN(i);
for(int x=0; x<4;x++) tmc2130_disable_motor(x);
kill(TMC_OVERTEMP_MSG);
}
}
checktime = millis();
}
}
#endif //HAVE_TMC2130_DRIVERS #endif //HAVE_TMC2130_DRIVERS
void tmc2130_init() void tmc2130_init()

View File

@ -88,6 +88,10 @@ void digipot_current(uint8_t driver, int current);
void microstep_init(); void microstep_init();
void microstep_readings(); void microstep_readings();
#ifdef HAVE_TMC2130_DRIVERS
void tmc2130_check_overtemp();
#endif
#ifdef BABYSTEPPING #ifdef BABYSTEPPING
void babystep(const uint8_t axis,const bool direction); // perform a short step with a single stepper motor, outside of any convention void babystep(const uint8_t axis,const bool direction); // perform a short step with a single stepper motor, outside of any convention
#endif #endif

View File

@ -24,7 +24,7 @@
*------------------------------------*/ *------------------------------------*/
// Steps per unit {X,Y,Z,E} // Steps per unit {X,Y,Z,E}
#define DEFAULT_AXIS_STEPS_PER_UNIT {100,100,3200/8,161.3*16} #define DEFAULT_AXIS_STEPS_PER_UNIT {100,100,3200/8,161.3}
// Endstop inverting // Endstop inverting
const bool X_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic of the endstop. const bool X_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic of the endstop.
@ -186,8 +186,8 @@ const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic o
// Motor Current settings for RAMBo mini PWM value = MotorCurrentSetting * 255 / range // Motor Current settings for RAMBo mini PWM value = MotorCurrentSetting * 255 / range
#if MOTHERBOARD == 102 || MOTHERBOARD == 302 || MOTHERBOARD == 300 #if MOTHERBOARD == 102 || MOTHERBOARD == 302 || MOTHERBOARD == 300
#define MOTOR_CURRENT_PWM_RANGE 2000 #define MOTOR_CURRENT_PWM_RANGE 2000
#define DEFAULT_PWM_MOTOR_CURRENT {270, 830, 450} // {XY,Z,E} #define DEFAULT_PWM_MOTOR_CURRENT {650, 750, 750} // {XY,Z,E}
#define DEFAULT_PWM_MOTOR_CURRENT_LOUD {540, 830, 500} // {XY,Z,E} #define DEFAULT_PWM_MOTOR_CURRENT_LOUD {650, 750, 750} // {XY,Z,E}
#endif #endif
/*------------------------------------ /*------------------------------------