Keep "astyled" elements in stepper.*

This commit is contained in:
Scott Lahteine
2015-10-02 23:13:44 -07:00
parent 2c42dc5121
commit 38f626d7a2
2 changed files with 177 additions and 178 deletions

View File

@@ -37,7 +37,7 @@
//=========================================================================== //===========================================================================
//============================= public variables ============================ //============================= public variables ============================
//=========================================================================== //===========================================================================
block_t *current_block; // A pointer to the block currently being traced block_t* current_block; // A pointer to the block currently being traced
//=========================================================================== //===========================================================================
@@ -81,7 +81,7 @@ static volatile char endstop_hit_bits = 0; // use X_MIN, Y_MIN, Z_MIN and Z_MIN_
#else #else
static uint16_t static uint16_t
#endif #endif
old_endstop_bits = 0; // use X_MIN, X_MAX... Z_MAX, Z_MIN_PROBE, Z2_MIN, Z2_MAX old_endstop_bits = 0; // use X_MIN, X_MAX... Z_MAX, Z_MIN_PROBE, Z2_MIN, Z2_MAX
#if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
bool abort_on_endstop_hit = false; bool abort_on_endstop_hit = false;
@@ -163,24 +163,24 @@ volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1 };
// r27 to store the byte 1 of the 24 bit result // r27 to store the byte 1 of the 24 bit result
#define MultiU16X8toH16(intRes, charIn1, intIn2) \ #define MultiU16X8toH16(intRes, charIn1, intIn2) \
asm volatile ( \ asm volatile ( \
"clr r26 \n\t" \ "clr r26 \n\t" \
"mul %A1, %B2 \n\t" \ "mul %A1, %B2 \n\t" \
"movw %A0, r0 \n\t" \ "movw %A0, r0 \n\t" \
"mul %A1, %A2 \n\t" \ "mul %A1, %A2 \n\t" \
"add %A0, r1 \n\t" \ "add %A0, r1 \n\t" \
"adc %B0, r26 \n\t" \ "adc %B0, r26 \n\t" \
"lsr r0 \n\t" \ "lsr r0 \n\t" \
"adc %A0, r26 \n\t" \ "adc %A0, r26 \n\t" \
"adc %B0, r26 \n\t" \ "adc %B0, r26 \n\t" \
"clr r1 \n\t" \ "clr r1 \n\t" \
: \ : \
"=&r" (intRes) \ "=&r" (intRes) \
: \ : \
"d" (charIn1), \ "d" (charIn1), \
"d" (intIn2) \ "d" (intIn2) \
: \ : \
"r26" \ "r26" \
) )
// intRes = longIn1 * longIn2 >> 24 // intRes = longIn1 * longIn2 >> 24
// uses: // uses:
@@ -194,49 +194,49 @@ volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1 };
// //
#define MultiU24X32toH16(intRes, longIn1, longIn2) \ #define MultiU24X32toH16(intRes, longIn1, longIn2) \
asm volatile ( \ asm volatile ( \
"clr r26 \n\t" \ "clr r26 \n\t" \
"mul %A1, %B2 \n\t" \ "mul %A1, %B2 \n\t" \
"mov r27, r1 \n\t" \ "mov r27, r1 \n\t" \
"mul %B1, %C2 \n\t" \ "mul %B1, %C2 \n\t" \
"movw %A0, r0 \n\t" \ "movw %A0, r0 \n\t" \
"mul %C1, %C2 \n\t" \ "mul %C1, %C2 \n\t" \
"add %B0, r0 \n\t" \ "add %B0, r0 \n\t" \
"mul %C1, %B2 \n\t" \ "mul %C1, %B2 \n\t" \
"add %A0, r0 \n\t" \ "add %A0, r0 \n\t" \
"adc %B0, r1 \n\t" \ "adc %B0, r1 \n\t" \
"mul %A1, %C2 \n\t" \ "mul %A1, %C2 \n\t" \
"add r27, r0 \n\t" \ "add r27, r0 \n\t" \
"adc %A0, r1 \n\t" \ "adc %A0, r1 \n\t" \
"adc %B0, r26 \n\t" \ "adc %B0, r26 \n\t" \
"mul %B1, %B2 \n\t" \ "mul %B1, %B2 \n\t" \
"add r27, r0 \n\t" \ "add r27, r0 \n\t" \
"adc %A0, r1 \n\t" \ "adc %A0, r1 \n\t" \
"adc %B0, r26 \n\t" \ "adc %B0, r26 \n\t" \
"mul %C1, %A2 \n\t" \ "mul %C1, %A2 \n\t" \
"add r27, r0 \n\t" \ "add r27, r0 \n\t" \
"adc %A0, r1 \n\t" \ "adc %A0, r1 \n\t" \
"adc %B0, r26 \n\t" \ "adc %B0, r26 \n\t" \
"mul %B1, %A2 \n\t" \ "mul %B1, %A2 \n\t" \
"add r27, r1 \n\t" \ "add r27, r1 \n\t" \
"adc %A0, r26 \n\t" \ "adc %A0, r26 \n\t" \
"adc %B0, r26 \n\t" \ "adc %B0, r26 \n\t" \
"lsr r27 \n\t" \ "lsr r27 \n\t" \
"adc %A0, r26 \n\t" \ "adc %A0, r26 \n\t" \
"adc %B0, r26 \n\t" \ "adc %B0, r26 \n\t" \
"mul %D2, %A1 \n\t" \ "mul %D2, %A1 \n\t" \
"add %A0, r0 \n\t" \ "add %A0, r0 \n\t" \
"adc %B0, r1 \n\t" \ "adc %B0, r1 \n\t" \
"mul %D2, %B1 \n\t" \ "mul %D2, %B1 \n\t" \
"add %B0, r0 \n\t" \ "add %B0, r0 \n\t" \
"clr r1 \n\t" \ "clr r1 \n\t" \
: \ : \
"=&r" (intRes) \ "=&r" (intRes) \
: \ : \
"d" (longIn1), \ "d" (longIn1), \
"d" (longIn2) \ "d" (longIn2) \
: \ : \
"r26" , "r27" \ "r26" , "r27" \
) )
// Some useful constants // Some useful constants
@@ -328,7 +328,7 @@ inline void update_endstops() {
if ((current_block->steps[A_AXIS] != current_block->steps[C_AXIS]) || (TEST(out_bits, A_AXIS) == TEST(out_bits, C_AXIS))) { if ((current_block->steps[A_AXIS] != current_block->steps[C_AXIS]) || (TEST(out_bits, A_AXIS) == TEST(out_bits, C_AXIS))) {
if (TEST(out_bits, X_HEAD)) if (TEST(out_bits, X_HEAD))
#else #else
if (TEST(out_bits, X_AXIS)) // stepping along -X axis (regular Cartesian bot) if (TEST(out_bits, X_AXIS)) // stepping along -X axis (regular Cartesian bot)
#endif #endif
{ // -direction { // -direction
#if ENABLED(DUAL_X_CARRIAGE) #if ENABLED(DUAL_X_CARRIAGE)
@@ -391,11 +391,11 @@ inline void update_endstops() {
#if ENABLED(Z_DUAL_ENDSTOPS) #if ENABLED(Z_DUAL_ENDSTOPS)
SET_ENDSTOP_BIT(Z, MIN); SET_ENDSTOP_BIT(Z, MIN);
#if HAS_Z2_MIN #if HAS_Z2_MIN
SET_ENDSTOP_BIT(Z2, MIN); SET_ENDSTOP_BIT(Z2, MIN);
#else #else
COPY_BIT(current_endstop_bits, Z_MIN, Z2_MIN); COPY_BIT(current_endstop_bits, Z_MIN, Z2_MIN);
#endif #endif
byte z_test = TEST_ENDSTOP(Z_MIN) << 0 + TEST_ENDSTOP(Z2_MIN) << 1; // bit 0 for Z, bit 1 for Z2 byte z_test = TEST_ENDSTOP(Z_MIN) << 0 + TEST_ENDSTOP(Z2_MIN) << 1; // bit 0 for Z, bit 1 for Z2
@@ -408,14 +408,14 @@ inline void update_endstops() {
#else // !Z_DUAL_ENDSTOPS #else // !Z_DUAL_ENDSTOPS
UPDATE_ENDSTOP(Z, MIN); UPDATE_ENDSTOP(Z, MIN);
#endif // !Z_DUAL_ENDSTOPS #endif // !Z_DUAL_ENDSTOPS
#endif // Z_MIN_PIN #endif // Z_MIN_PIN
#if ENABLED(Z_MIN_PROBE_ENDSTOP) #if ENABLED(Z_MIN_PROBE_ENDSTOP)
UPDATE_ENDSTOP(Z, MIN_PROBE); UPDATE_ENDSTOP(Z, MIN_PROBE);
if (TEST_ENDSTOP(Z_MIN_PROBE)) if (TEST_ENDSTOP(Z_MIN_PROBE)) {
{
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
endstop_hit_bits |= BIT(Z_MIN_PROBE); endstop_hit_bits |= BIT(Z_MIN_PROBE);
} }
@@ -427,11 +427,11 @@ inline void update_endstops() {
#if ENABLED(Z_DUAL_ENDSTOPS) #if ENABLED(Z_DUAL_ENDSTOPS)
SET_ENDSTOP_BIT(Z, MAX); SET_ENDSTOP_BIT(Z, MAX);
#if HAS_Z2_MAX #if HAS_Z2_MAX
SET_ENDSTOP_BIT(Z2, MAX); SET_ENDSTOP_BIT(Z2, MAX);
#else #else
COPY_BIT(current_endstop_bits, Z_MAX, Z2_MAX); COPY_BIT(current_endstop_bits, Z_MAX, Z2_MAX);
#endif #endif
byte z_test = TEST_ENDSTOP(Z_MAX) << 0 + TEST_ENDSTOP(Z2_MAX) << 1; // bit 0 for Z, bit 1 for Z2 byte z_test = TEST_ENDSTOP(Z_MAX) << 0 + TEST_ENDSTOP(Z2_MAX) << 1; // bit 0 for Z, bit 1 for Z2
@@ -451,7 +451,7 @@ inline void update_endstops() {
} }
#if ENABLED(COREXZ) #if ENABLED(COREXZ)
} }
#endif #endif
old_endstop_bits = current_endstop_bits; old_endstop_bits = current_endstop_bits;
} }
@@ -495,17 +495,17 @@ FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
if (step_rate < (F_CPU / 500000)) step_rate = (F_CPU / 500000); if (step_rate < (F_CPU / 500000)) step_rate = (F_CPU / 500000);
step_rate -= (F_CPU / 500000); // Correct for minimal speed step_rate -= (F_CPU / 500000); // Correct for minimal speed
if (step_rate >= (8 * 256)) { // higher step rate if (step_rate >= (8 * 256)) { // higher step rate
unsigned short table_address = (unsigned short)&speed_lookuptable_fast[(unsigned char)(step_rate>>8)][0]; unsigned short table_address = (unsigned short)&speed_lookuptable_fast[(unsigned char)(step_rate >> 8)][0];
unsigned char tmp_step_rate = (step_rate & 0x00ff); unsigned char tmp_step_rate = (step_rate & 0x00ff);
unsigned short gain = (unsigned short)pgm_read_word_near(table_address+2); unsigned short gain = (unsigned short)pgm_read_word_near(table_address + 2);
MultiU16X8toH16(timer, tmp_step_rate, gain); MultiU16X8toH16(timer, tmp_step_rate, gain);
timer = (unsigned short)pgm_read_word_near(table_address) - timer; timer = (unsigned short)pgm_read_word_near(table_address) - timer;
} }
else { // lower step rates else { // lower step rates
unsigned short table_address = (unsigned short)&speed_lookuptable_slow[0][0]; unsigned short table_address = (unsigned short)&speed_lookuptable_slow[0][0];
table_address += ((step_rate)>>1) & 0xfffc; table_address += ((step_rate) >> 1) & 0xfffc;
timer = (unsigned short)pgm_read_word_near(table_address); timer = (unsigned short)pgm_read_word_near(table_address);
timer -= (((unsigned short)pgm_read_word_near(table_address+2) * (unsigned char)(step_rate & 0x0007))>>3); timer -= (((unsigned short)pgm_read_word_near(table_address + 2) * (unsigned char)(step_rate & 0x0007)) >> 3);
} }
if (timer < 100) { timer = 100; MYSERIAL.print(MSG_STEPPER_TOO_HIGH); MYSERIAL.println(step_rate); }//(20kHz this should never happen) if (timer < 100) { timer = 100; MYSERIAL.print(MSG_STEPPER_TOO_HIGH); MYSERIAL.println(step_rate); }//(20kHz this should never happen)
return timer; return timer;
@@ -704,16 +704,18 @@ ISR(TIMER1_COMPA_vect) {
timer = calc_timer(acc_step_rate); timer = calc_timer(acc_step_rate);
OCR1A = timer; OCR1A = timer;
acceleration_time += timer; acceleration_time += timer;
#if ENABLED(ADVANCE) #if ENABLED(ADVANCE)
for(int8_t i=0; i < step_loops; i++) {
for (int8_t i = 0; i < step_loops; i++) {
advance += advance_rate; advance += advance_rate;
} }
//if (advance > current_block->advance) advance = current_block->advance; //if (advance > current_block->advance) advance = current_block->advance;
// Do E steps + advance steps // Do E steps + advance steps
e_steps[current_block->active_extruder] += ((advance >>8) - old_advance); e_steps[current_block->active_extruder] += ((advance >> 8) - old_advance);
old_advance = advance >>8; old_advance = advance >> 8;
#endif #endif //ADVANCE
} }
else if (step_events_completed > (unsigned long)current_block->decelerate_after) { else if (step_events_completed > (unsigned long)current_block->decelerate_after) {
MultiU24X32toH16(step_rate, deceleration_time, current_block->acceleration_rate); MultiU24X32toH16(step_rate, deceleration_time, current_block->acceleration_rate);
@@ -734,13 +736,13 @@ ISR(TIMER1_COMPA_vect) {
OCR1A = timer; OCR1A = timer;
deceleration_time += timer; deceleration_time += timer;
#if ENABLED(ADVANCE) #if ENABLED(ADVANCE)
for(int8_t i=0; i < step_loops; i++) { for (int8_t i = 0; i < step_loops; i++) {
advance -= advance_rate; advance -= advance_rate;
} }
if (advance < final_advance) advance = final_advance; if (advance < final_advance) advance = final_advance;
// Do E steps + advance steps // Do E steps + advance steps
e_steps[current_block->active_extruder] += ((advance >>8) - old_advance); e_steps[current_block->active_extruder] += ((advance >> 8) - old_advance);
old_advance = advance >>8; old_advance = advance >> 8;
#endif //ADVANCE #endif //ADVANCE
} }
else { else {
@@ -749,7 +751,7 @@ ISR(TIMER1_COMPA_vect) {
step_loops = step_loops_nominal; step_loops = step_loops_nominal;
} }
OCR1A = (OCR1A < (TCNT1 +16)) ? (TCNT1 + 16) : OCR1A; OCR1A = (OCR1A < (TCNT1 + 16)) ? (TCNT1 + 16) : OCR1A;
// If current block is finished, reset pointer // If current block is finished, reset pointer
if (step_events_completed >= current_block->step_event_count) { if (step_events_completed >= current_block->step_event_count) {
@@ -763,12 +765,11 @@ ISR(TIMER1_COMPA_vect) {
unsigned char old_OCR0A; unsigned char old_OCR0A;
// Timer interrupt for E. e_steps is set in the main routine; // Timer interrupt for E. e_steps is set in the main routine;
// Timer 0 is shared with millies // Timer 0 is shared with millies
ISR(TIMER0_COMPA_vect) ISR(TIMER0_COMPA_vect) {
{
old_OCR0A += 52; // ~10kHz interrupt (250000 / 26 = 9615kHz) old_OCR0A += 52; // ~10kHz interrupt (250000 / 26 = 9615kHz)
OCR0A = old_OCR0A; OCR0A = old_OCR0A;
// Set E direction (Depends on E direction + advance) // Set E direction (Depends on E direction + advance)
for(unsigned char i=0; i<4;i++) { for (unsigned char i = 0; i < 4; i++) {
if (e_steps[0] != 0) { if (e_steps[0] != 0) {
E0_STEP_WRITE(INVERT_E_STEP_PIN); E0_STEP_WRITE(INVERT_E_STEP_PIN);
if (e_steps[0] < 0) { if (e_steps[0] < 0) {
@@ -782,52 +783,51 @@ ISR(TIMER1_COMPA_vect) {
E0_STEP_WRITE(!INVERT_E_STEP_PIN); E0_STEP_WRITE(!INVERT_E_STEP_PIN);
} }
} }
#if EXTRUDERS > 1 #if EXTRUDERS > 1
if (e_steps[1] != 0) { if (e_steps[1] != 0) {
E1_STEP_WRITE(INVERT_E_STEP_PIN); E1_STEP_WRITE(INVERT_E_STEP_PIN);
if (e_steps[1] < 0) { if (e_steps[1] < 0) {
E1_DIR_WRITE(INVERT_E1_DIR); E1_DIR_WRITE(INVERT_E1_DIR);
e_steps[1]++; e_steps[1]++;
E1_STEP_WRITE(!INVERT_E_STEP_PIN); E1_STEP_WRITE(!INVERT_E_STEP_PIN);
}
else if (e_steps[1] > 0) {
E1_DIR_WRITE(!INVERT_E1_DIR);
e_steps[1]--;
E1_STEP_WRITE(!INVERT_E_STEP_PIN);
}
} }
else if (e_steps[1] > 0) { #endif
E1_DIR_WRITE(!INVERT_E1_DIR); #if EXTRUDERS > 2
e_steps[1]--; if (e_steps[2] != 0) {
E1_STEP_WRITE(!INVERT_E_STEP_PIN); E2_STEP_WRITE(INVERT_E_STEP_PIN);
if (e_steps[2] < 0) {
E2_DIR_WRITE(INVERT_E2_DIR);
e_steps[2]++;
E2_STEP_WRITE(!INVERT_E_STEP_PIN);
}
else if (e_steps[2] > 0) {
E2_DIR_WRITE(!INVERT_E2_DIR);
e_steps[2]--;
E2_STEP_WRITE(!INVERT_E_STEP_PIN);
}
} }
} #endif
#endif #if EXTRUDERS > 3
#if EXTRUDERS > 2 if (e_steps[3] != 0) {
if (e_steps[2] != 0) { E3_STEP_WRITE(INVERT_E_STEP_PIN);
E2_STEP_WRITE(INVERT_E_STEP_PIN); if (e_steps[3] < 0) {
if (e_steps[2] < 0) { E3_DIR_WRITE(INVERT_E3_DIR);
E2_DIR_WRITE(INVERT_E2_DIR); e_steps[3]++;
e_steps[2]++; E3_STEP_WRITE(!INVERT_E_STEP_PIN);
E2_STEP_WRITE(!INVERT_E_STEP_PIN); }
else if (e_steps[3] > 0) {
E3_DIR_WRITE(!INVERT_E3_DIR);
e_steps[3]--;
E3_STEP_WRITE(!INVERT_E_STEP_PIN);
}
} }
else if (e_steps[2] > 0) { #endif
E2_DIR_WRITE(!INVERT_E2_DIR);
e_steps[2]--;
E2_STEP_WRITE(!INVERT_E_STEP_PIN);
}
}
#endif
#if EXTRUDERS > 3
if (e_steps[3] != 0) {
E3_STEP_WRITE(INVERT_E_STEP_PIN);
if (e_steps[3] < 0) {
E3_DIR_WRITE(INVERT_E3_DIR);
e_steps[3]++;
E3_STEP_WRITE(!INVERT_E_STEP_PIN);
}
else if (e_steps[3] > 0) {
E3_DIR_WRITE(!INVERT_E3_DIR);
e_steps[3]--;
E3_STEP_WRITE(!INVERT_E_STEP_PIN);
}
}
#endif
} }
} }
#endif // ADVANCE #endif // ADVANCE
@@ -1032,15 +1032,14 @@ void st_init() {
TCCR1A &= ~BIT(WGM10); TCCR1A &= ~BIT(WGM10);
// output mode = 00 (disconnected) // output mode = 00 (disconnected)
TCCR1A &= ~(3<<COM1A0); TCCR1A &= ~(3 << COM1A0);
TCCR1A &= ~(3<<COM1B0); TCCR1A &= ~(3 << COM1B0);
// Set the timer pre-scaler // Set the timer pre-scaler
// Generally we use a divider of 8, resulting in a 2MHz timer // Generally we use a divider of 8, resulting in a 2MHz timer
// frequency on a 16MHz MCU. If you are going to change this, be // frequency on a 16MHz MCU. If you are going to change this, be
// sure to regenerate speed_lookuptable.h with // sure to regenerate speed_lookuptable.h with
// create_speed_lookuptable.py // create_speed_lookuptable.py
TCCR1B = (TCCR1B & ~(0x07<<CS10)) | (2<<CS10); TCCR1B = (TCCR1B & ~(0x07 << CS10)) | (2 << CS10);
OCR1A = 0x4000; OCR1A = 0x4000;
TCNT1 = 0; TCNT1 = 0;
@@ -1067,7 +1066,7 @@ void st_init() {
*/ */
void st_synchronize() { while (blocks_queued()) idle(); } void st_synchronize() { while (blocks_queued()) idle(); }
void st_set_position(const long &x, const long &y, const long &z, const long &e) { void st_set_position(const long& x, const long& y, const long& z, const long& e) {
CRITICAL_SECTION_START; CRITICAL_SECTION_START;
count_position[X_AXIS] = x; count_position[X_AXIS] = x;
count_position[Y_AXIS] = y; count_position[Y_AXIS] = y;
@@ -1076,7 +1075,7 @@ void st_set_position(const long &x, const long &y, const long &z, const long &e)
CRITICAL_SECTION_END; CRITICAL_SECTION_END;
} }
void st_set_e_position(const long &e) { void st_set_e_position(const long& e) {
CRITICAL_SECTION_START; CRITICAL_SECTION_START;
count_position[E_AXIS] = e; count_position[E_AXIS] = e;
CRITICAL_SECTION_END; CRITICAL_SECTION_END;
@@ -1126,7 +1125,7 @@ void quickStop() {
_APPLY_DIR(AXIS, old_pin); \ _APPLY_DIR(AXIS, old_pin); \
} }
switch(axis) { switch (axis) {
case X_AXIS: case X_AXIS:
BABYSTEP_AXIS(x, X, false); BABYSTEP_AXIS(x, X, false);
@@ -1153,16 +1152,16 @@ void quickStop() {
old_y_dir_pin = Y_DIR_READ, old_y_dir_pin = Y_DIR_READ,
old_z_dir_pin = Z_DIR_READ; old_z_dir_pin = Z_DIR_READ;
//setup new step //setup new step
X_DIR_WRITE(INVERT_X_DIR^z_direction); X_DIR_WRITE(INVERT_X_DIR ^ z_direction);
Y_DIR_WRITE(INVERT_Y_DIR^z_direction); Y_DIR_WRITE(INVERT_Y_DIR ^ z_direction);
Z_DIR_WRITE(INVERT_Z_DIR^z_direction); Z_DIR_WRITE(INVERT_Z_DIR ^ z_direction);
//perform step //perform step
X_STEP_WRITE(!INVERT_X_STEP_PIN); X_STEP_WRITE(!INVERT_X_STEP_PIN);
Y_STEP_WRITE(!INVERT_Y_STEP_PIN); Y_STEP_WRITE(!INVERT_Y_STEP_PIN);
Z_STEP_WRITE(!INVERT_Z_STEP_PIN); Z_STEP_WRITE(!INVERT_Z_STEP_PIN);
delayMicroseconds(2); delayMicroseconds(2);
X_STEP_WRITE(INVERT_X_STEP_PIN); X_STEP_WRITE(INVERT_X_STEP_PIN);
Y_STEP_WRITE(INVERT_Y_STEP_PIN); Y_STEP_WRITE(INVERT_Y_STEP_PIN);
Z_STEP_WRITE(INVERT_Z_STEP_PIN); Z_STEP_WRITE(INVERT_Z_STEP_PIN);
//get old pin state back. //get old pin state back.
X_DIR_WRITE(old_x_dir_pin); X_DIR_WRITE(old_x_dir_pin);
@@ -1182,10 +1181,10 @@ void quickStop() {
// From Arduino DigitalPotControl example // From Arduino DigitalPotControl example
void digitalPotWrite(int address, int value) { void digitalPotWrite(int address, int value) {
#if HAS_DIGIPOTSS #if HAS_DIGIPOTSS
digitalWrite(DIGIPOTSS_PIN,LOW); // take the SS pin low to select the chip digitalWrite(DIGIPOTSS_PIN, LOW); // take the SS pin low to select the chip
SPI.transfer(address); // send in the address and value via SPI: SPI.transfer(address); // send in the address and value via SPI:
SPI.transfer(value); SPI.transfer(value);
digitalWrite(DIGIPOTSS_PIN,HIGH); // take the SS pin high to de-select the chip: digitalWrite(DIGIPOTSS_PIN, HIGH); // take the SS pin high to de-select the chip:
//delay(10); //delay(10);
#else #else
UNUSED(address); UNUSED(address);
@@ -1202,7 +1201,7 @@ void digipot_init() {
pinMode(DIGIPOTSS_PIN, OUTPUT); pinMode(DIGIPOTSS_PIN, OUTPUT);
for (int i = 0; i <= 4; i++) { for (int i = 0; i <= 4; i++) {
//digitalPotWrite(digipot_ch[i], digipot_motor_current[i]); //digitalPotWrite(digipot_ch[i], digipot_motor_current[i]);
digipot_current(i,digipot_motor_current[i]); digipot_current(i, digipot_motor_current[i]);
} }
#endif #endif
#ifdef MOTOR_CURRENT_PWM_XY_PIN #ifdef MOTOR_CURRENT_PWM_XY_PIN
@@ -1222,7 +1221,7 @@ void digipot_current(uint8_t driver, int current) {
const uint8_t digipot_ch[] = DIGIPOT_CHANNELS; const uint8_t digipot_ch[] = DIGIPOT_CHANNELS;
digitalPotWrite(digipot_ch[driver], current); digitalPotWrite(digipot_ch[driver], current);
#elif defined(MOTOR_CURRENT_PWM_XY_PIN) #elif defined(MOTOR_CURRENT_PWM_XY_PIN)
switch(driver) { switch (driver) {
case 0: analogWrite(MOTOR_CURRENT_PWM_XY_PIN, 255L * current / MOTOR_CURRENT_PWM_RANGE); break; case 0: analogWrite(MOTOR_CURRENT_PWM_XY_PIN, 255L * current / MOTOR_CURRENT_PWM_RANGE); break;
case 1: analogWrite(MOTOR_CURRENT_PWM_Z_PIN, 255L * current / MOTOR_CURRENT_PWM_RANGE); break; case 1: analogWrite(MOTOR_CURRENT_PWM_Z_PIN, 255L * current / MOTOR_CURRENT_PWM_RANGE); break;
case 2: analogWrite(MOTOR_CURRENT_PWM_E_PIN, 255L * current / MOTOR_CURRENT_PWM_RANGE); break; case 2: analogWrite(MOTOR_CURRENT_PWM_E_PIN, 255L * current / MOTOR_CURRENT_PWM_RANGE); break;
@@ -1235,19 +1234,19 @@ void digipot_current(uint8_t driver, int current) {
void microstep_init() { void microstep_init() {
#if HAS_MICROSTEPS_E1 #if HAS_MICROSTEPS_E1
pinMode(E1_MS1_PIN,OUTPUT); pinMode(E1_MS1_PIN, OUTPUT);
pinMode(E1_MS2_PIN,OUTPUT); pinMode(E1_MS2_PIN, OUTPUT);
#endif #endif
#if HAS_MICROSTEPS #if HAS_MICROSTEPS
pinMode(X_MS1_PIN,OUTPUT); pinMode(X_MS1_PIN, OUTPUT);
pinMode(X_MS2_PIN,OUTPUT); pinMode(X_MS2_PIN, OUTPUT);
pinMode(Y_MS1_PIN,OUTPUT); pinMode(Y_MS1_PIN, OUTPUT);
pinMode(Y_MS2_PIN,OUTPUT); pinMode(Y_MS2_PIN, OUTPUT);
pinMode(Z_MS1_PIN,OUTPUT); pinMode(Z_MS1_PIN, OUTPUT);
pinMode(Z_MS2_PIN,OUTPUT); pinMode(Z_MS2_PIN, OUTPUT);
pinMode(E0_MS1_PIN,OUTPUT); pinMode(E0_MS1_PIN, OUTPUT);
pinMode(E0_MS2_PIN,OUTPUT); pinMode(E0_MS2_PIN, OUTPUT);
const uint8_t microstep_modes[] = MICROSTEP_MODES; const uint8_t microstep_modes[] = MICROSTEP_MODES;
for (uint16_t i = 0; i < COUNT(microstep_modes); i++) for (uint16_t i = 0; i < COUNT(microstep_modes); i++)
microstep_mode(i, microstep_modes[i]); microstep_mode(i, microstep_modes[i]);
@@ -1255,7 +1254,7 @@ void microstep_init() {
} }
void microstep_ms(uint8_t driver, int8_t ms1, int8_t ms2) { void microstep_ms(uint8_t driver, int8_t ms1, int8_t ms2) {
if (ms1 >= 0) switch(driver) { if (ms1 >= 0) switch (driver) {
case 0: digitalWrite(X_MS1_PIN, ms1); break; case 0: digitalWrite(X_MS1_PIN, ms1); break;
case 1: digitalWrite(Y_MS1_PIN, ms1); break; case 1: digitalWrite(Y_MS1_PIN, ms1); break;
case 2: digitalWrite(Z_MS1_PIN, ms1); break; case 2: digitalWrite(Z_MS1_PIN, ms1); break;
@@ -1264,7 +1263,7 @@ void microstep_ms(uint8_t driver, int8_t ms1, int8_t ms2) {
case 4: digitalWrite(E1_MS1_PIN, ms1); break; case 4: digitalWrite(E1_MS1_PIN, ms1); break;
#endif #endif
} }
if (ms2 >= 0) switch(driver) { if (ms2 >= 0) switch (driver) {
case 0: digitalWrite(X_MS2_PIN, ms2); break; case 0: digitalWrite(X_MS2_PIN, ms2); break;
case 1: digitalWrite(Y_MS2_PIN, ms2); break; case 1: digitalWrite(Y_MS2_PIN, ms2); break;
case 2: digitalWrite(Z_MS2_PIN, ms2); break; case 2: digitalWrite(Z_MS2_PIN, ms2); break;
@@ -1276,12 +1275,12 @@ void microstep_ms(uint8_t driver, int8_t ms1, int8_t ms2) {
} }
void microstep_mode(uint8_t driver, uint8_t stepping_mode) { void microstep_mode(uint8_t driver, uint8_t stepping_mode) {
switch(stepping_mode) { switch (stepping_mode) {
case 1: microstep_ms(driver,MICROSTEP1); break; case 1: microstep_ms(driver, MICROSTEP1); break;
case 2: microstep_ms(driver,MICROSTEP2); break; case 2: microstep_ms(driver, MICROSTEP2); break;
case 4: microstep_ms(driver,MICROSTEP4); break; case 4: microstep_ms(driver, MICROSTEP4); break;
case 8: microstep_ms(driver,MICROSTEP8); break; case 8: microstep_ms(driver, MICROSTEP8); break;
case 16: microstep_ms(driver,MICROSTEP16); break; case 16: microstep_ms(driver, MICROSTEP16); break;
} }
} }

View File

@@ -19,7 +19,7 @@
*/ */
#ifndef stepper_h #ifndef stepper_h
#define stepper_h #define stepper_h
#include "planner.h" #include "planner.h"
#include "stepper_indirection.h" #include "stepper_indirection.h"
@@ -42,7 +42,7 @@
#define E_STEP_WRITE(v) { if(extruder_duplication_enabled) { E0_STEP_WRITE(v); E1_STEP_WRITE(v); } else if(current_block->active_extruder == 1) { E1_STEP_WRITE(v); } else { E0_STEP_WRITE(v); }} #define E_STEP_WRITE(v) { if(extruder_duplication_enabled) { E0_STEP_WRITE(v); E1_STEP_WRITE(v); } else if(current_block->active_extruder == 1) { E1_STEP_WRITE(v); } else { E0_STEP_WRITE(v); }}
#define NORM_E_DIR() { if(extruder_duplication_enabled) { E0_DIR_WRITE(!INVERT_E0_DIR); E1_DIR_WRITE(!INVERT_E1_DIR); } else if(current_block->active_extruder == 1) { E1_DIR_WRITE(!INVERT_E1_DIR); } else { E0_DIR_WRITE(!INVERT_E0_DIR); }} #define NORM_E_DIR() { if(extruder_duplication_enabled) { E0_DIR_WRITE(!INVERT_E0_DIR); E1_DIR_WRITE(!INVERT_E1_DIR); } else if(current_block->active_extruder == 1) { E1_DIR_WRITE(!INVERT_E1_DIR); } else { E0_DIR_WRITE(!INVERT_E0_DIR); }}
#define REV_E_DIR() { if(extruder_duplication_enabled) { E0_DIR_WRITE(INVERT_E0_DIR); E1_DIR_WRITE(INVERT_E1_DIR); } else if(current_block->active_extruder == 1) { E1_DIR_WRITE(INVERT_E1_DIR); } else { E0_DIR_WRITE(INVERT_E0_DIR); }} #define REV_E_DIR() { if(extruder_duplication_enabled) { E0_DIR_WRITE(INVERT_E0_DIR); E1_DIR_WRITE(INVERT_E1_DIR); } else if(current_block->active_extruder == 1) { E1_DIR_WRITE(INVERT_E1_DIR); } else { E0_DIR_WRITE(INVERT_E0_DIR); }}
#endif #endif
#else #else
#define E_STEP_WRITE(v) E0_STEP_WRITE(v) #define E_STEP_WRITE(v) E0_STEP_WRITE(v)
#define NORM_E_DIR() E0_DIR_WRITE(!INVERT_E0_DIR) #define NORM_E_DIR() E0_DIR_WRITE(!INVERT_E0_DIR)
@@ -60,8 +60,8 @@ void st_init();
void st_synchronize(); void st_synchronize();
// Set current position in steps // Set current position in steps
void st_set_position(const long &x, const long &y, const long &z, const long &e); void st_set_position(const long& x, const long& y, const long& z, const long& e);
void st_set_e_position(const long &e); void st_set_e_position(const long& e);
// Get current position in steps // Get current position in steps
long st_get_position(uint8_t axis); long st_get_position(uint8_t axis);
@@ -73,7 +73,7 @@ float st_get_position_mm(AxisEnum axis);
// to notify the subsystem that it is time to go to work. // to notify the subsystem that it is time to go to work.
void st_wake_up(); void st_wake_up();
void checkHitEndstops(); //call from somewhere to create an serial error message with the locations the endstops where hit, in case they were triggered void checkHitEndstops(); //call from somewhere to create an serial error message with the locations the endstops where hit, in case they were triggered
void endstops_hit_on_purpose(); //avoid creation of the message, i.e. after homing and before a routine call of checkHitEndstops(); void endstops_hit_on_purpose(); //avoid creation of the message, i.e. after homing and before a routine call of checkHitEndstops();
@@ -83,7 +83,7 @@ void checkStepperErrors(); //Print errors detected by the stepper
void finishAndDisableSteppers(); void finishAndDisableSteppers();
extern block_t *current_block; // A pointer to the block currently being traced extern block_t* current_block; // A pointer to the block currently being traced
void quickStop(); void quickStop();
@@ -102,7 +102,7 @@ void microstep_readings();
#endif #endif
#if ENABLED(BABYSTEPPING) #if ENABLED(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
#endif #endif