changed encoder pos from int to long to fix problems setting x/y/z/e stepps_per_mm using the lcd menu

2.0.x
MaikStohn 13 years ago
parent b657a18449
commit 1efe9ab497

@ -70,7 +70,7 @@
void showAxisMove(); void showAxisMove();
void showSD(); void showSD();
bool force_lcd_update; bool force_lcd_update;
int lastencoderpos; long lastencoderpos;
int8_t lineoffset; int8_t lineoffset;
int8_t lastlineoffset; int8_t lastlineoffset;
@ -79,11 +79,11 @@
bool tune; bool tune;
private: private:
FORCE_INLINE void updateActiveLines(const uint8_t &maxlines,volatile int &encoderpos) FORCE_INLINE void updateActiveLines(const uint8_t &maxlines,volatile long &encoderpos)
{ {
if(linechanging) return; // an item is changint its value, do not switch lines hence if(linechanging) return; // an item is changint its value, do not switch lines hence
lastlineoffset=lineoffset; lastlineoffset=lineoffset;
int curencoderpos=encoderpos; long curencoderpos=encoderpos;
force_lcd_update=false; force_lcd_update=false;
if( (abs(curencoderpos-lastencoderpos)<lcdslow) ) if( (abs(curencoderpos-lastencoderpos)<lcdslow) )
{ {

@ -24,7 +24,7 @@ extern CardReader card;
//=============================public variables============================ //=============================public variables============================
//=========================================================================== //===========================================================================
volatile char buttons=0; //the last checked buttons in a bit array. volatile char buttons=0; //the last checked buttons in a bit array.
int encoderpos=0; long encoderpos=0;
short lastenc=0; short lastenc=0;
@ -884,7 +884,7 @@ void MainMenu::showTune()
if(force_lcd_update) if(force_lcd_update)
{ {
lcd.setCursor(0,line);lcdprintPGM(MSG_FLOW); lcd.setCursor(0,line);lcdprintPGM(MSG_FLOW);
lcd.setCursor(13,line);lcd.print(itostr4(axis_steps_per_unit[3])); lcd.setCursor(13,line);lcd.print(ftostr52(axis_steps_per_unit[E_AXIS]));
} }
if((activeline!=line) ) if((activeline!=line) )
@ -895,14 +895,14 @@ void MainMenu::showTune()
linechanging=!linechanging; linechanging=!linechanging;
if(linechanging) if(linechanging)
{ {
encoderpos=(int)axis_steps_per_unit[3]; encoderpos=(long)(axis_steps_per_unit[E_AXIS]*100.0);
} }
else else
{ {
float factor=float(encoderpos)/float(axis_steps_per_unit[3]); float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[E_AXIS]);
position[E_AXIS]=lround(position[E_AXIS]*factor); position[E_AXIS]=lround(position[E_AXIS]*factor);
//current_position[3]*=factor; //current_position[E_AXIS]*=factor;
axis_steps_per_unit[E_AXIS]= encoderpos; axis_steps_per_unit[E_AXIS]= encoderpos/100.0;
encoderpos=activeline*lcdslow; encoderpos=activeline*lcdslow;
} }
@ -912,8 +912,8 @@ void MainMenu::showTune()
if(linechanging) if(linechanging)
{ {
if(encoderpos<5) encoderpos=5; if(encoderpos<5) encoderpos=5;
if(encoderpos>9999) encoderpos=9999; if(encoderpos>999999) encoderpos=999999;
lcd.setCursor(13,line);lcd.print(itostr4(encoderpos)); lcd.setCursor(13,line);lcd.print(ftostr52(encoderpos/100.0));
} }
}break; }break;
@ -1296,7 +1296,7 @@ void MainMenu::showControlTemp()
linechanging=!linechanging; linechanging=!linechanging;
if(linechanging) if(linechanging)
{ {
encoderpos=(int)Kp; encoderpos=(long)Kp;
} }
else else
{ {
@ -1331,7 +1331,7 @@ void MainMenu::showControlTemp()
linechanging=!linechanging; linechanging=!linechanging;
if(linechanging) if(linechanging)
{ {
encoderpos=(int)(Ki*10/PID_dT); encoderpos=(long)(Ki*10/PID_dT);
} }
else else
{ {
@ -1367,7 +1367,7 @@ void MainMenu::showControlTemp()
linechanging=!linechanging; linechanging=!linechanging;
if(linechanging) if(linechanging)
{ {
encoderpos=(int)(Kd/5./PID_dT); encoderpos=(long)(Kd/5./PID_dT);
} }
else else
{ {
@ -1403,7 +1403,7 @@ void MainMenu::showControlTemp()
linechanging=!linechanging; linechanging=!linechanging;
if(linechanging) if(linechanging)
{ {
encoderpos=(int)Kc; encoderpos=(long)Kc;
} }
else else
{ {
@ -1476,7 +1476,7 @@ void MainMenu::showControlMotion()
linechanging=!linechanging; linechanging=!linechanging;
if(linechanging) if(linechanging)
{ {
encoderpos=(int)acceleration/100; encoderpos=(long)acceleration/100;
} }
else else
{ {
@ -1510,7 +1510,7 @@ void MainMenu::showControlMotion()
linechanging=!linechanging; linechanging=!linechanging;
if(linechanging) if(linechanging)
{ {
encoderpos=(int)max_xy_jerk; encoderpos=(long)max_xy_jerk;
} }
else else
{ {
@ -1553,7 +1553,7 @@ void MainMenu::showControlMotion()
linechanging=!linechanging; linechanging=!linechanging;
if(linechanging) if(linechanging)
{ {
encoderpos=(int)max_feedrate[i-ItemCM_vmaxx]; encoderpos=(long)max_feedrate[i-ItemCM_vmaxx];
} }
else else
{ {
@ -1589,7 +1589,7 @@ void MainMenu::showControlMotion()
linechanging=!linechanging; linechanging=!linechanging;
if(linechanging) if(linechanging)
{ {
encoderpos=(int)(minimumfeedrate); encoderpos=(long)(minimumfeedrate);
} }
else else
{ {
@ -1624,7 +1624,7 @@ void MainMenu::showControlMotion()
linechanging=!linechanging; linechanging=!linechanging;
if(linechanging) if(linechanging)
{ {
encoderpos=(int)mintravelfeedrate; encoderpos=(long)mintravelfeedrate;
} }
else else
{ {
@ -1667,7 +1667,7 @@ void MainMenu::showControlMotion()
linechanging=!linechanging; linechanging=!linechanging;
if(linechanging) if(linechanging)
{ {
encoderpos=(int)max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100; encoderpos=(long)max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100;
} }
else else
{ {
@ -1701,7 +1701,7 @@ void MainMenu::showControlMotion()
linechanging=!linechanging; linechanging=!linechanging;
if(linechanging) if(linechanging)
{ {
encoderpos=(int)retract_acceleration/100; encoderpos=(long)retract_acceleration/100;
} }
else else
{ {
@ -1725,7 +1725,7 @@ void MainMenu::showControlMotion()
if(force_lcd_update) if(force_lcd_update)
{ {
lcd.setCursor(0,line);lcdprintPGM(MSG_XSTEPS); lcd.setCursor(0,line);lcdprintPGM(MSG_XSTEPS);
lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[0])); lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[X_AXIS]));
} }
if((activeline!=line) ) if((activeline!=line) )
@ -1736,13 +1736,13 @@ void MainMenu::showControlMotion()
linechanging=!linechanging; linechanging=!linechanging;
if(linechanging) if(linechanging)
{ {
encoderpos=(int)(axis_steps_per_unit[0]*100.0); encoderpos=(long)(axis_steps_per_unit[X_AXIS]*100.0);
} }
else else
{ {
float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[0]); float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[X_AXIS]);
position[X_AXIS]=lround(position[X_AXIS]*factor); position[X_AXIS]=lround(position[X_AXIS]*factor);
//current_position[3]*=factor; //current_position[X_AXIS]*=factor;
axis_steps_per_unit[X_AXIS]= encoderpos/100.0; axis_steps_per_unit[X_AXIS]= encoderpos/100.0;
encoderpos=activeline*lcdslow; encoderpos=activeline*lcdslow;
} }
@ -1752,7 +1752,7 @@ void MainMenu::showControlMotion()
if(linechanging) if(linechanging)
{ {
if(encoderpos<5) encoderpos=5; if(encoderpos<5) encoderpos=5;
if(encoderpos>32000) encoderpos=32000;//TODO: This is a problem, encoderpos is 16bit, but steps_per_unit for e can be wel over 800 if(encoderpos>999999) encoderpos=99999;
lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0)); lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
} }
@ -1762,7 +1762,7 @@ void MainMenu::showControlMotion()
if(force_lcd_update) if(force_lcd_update)
{ {
lcd.setCursor(0,line);lcdprintPGM(MSG_YSTEPS); lcd.setCursor(0,line);lcdprintPGM(MSG_YSTEPS);
lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[1])); lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[Y_AXIS]));
} }
if((activeline!=line) ) if((activeline!=line) )
@ -1773,13 +1773,13 @@ void MainMenu::showControlMotion()
linechanging=!linechanging; linechanging=!linechanging;
if(linechanging) if(linechanging)
{ {
encoderpos=(int)(axis_steps_per_unit[1]*100.0); encoderpos=(long)(axis_steps_per_unit[Y_AXIS]*100.0);
} }
else else
{ {
float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[1]); float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[Y_AXIS]);
position[Y_AXIS]=lround(position[Y_AXIS]*factor); position[Y_AXIS]=lround(position[Y_AXIS]*factor);
//current_position[3]*=factor; //current_position[Y_AXIS]*=factor;
axis_steps_per_unit[Y_AXIS]= encoderpos/100.0; axis_steps_per_unit[Y_AXIS]= encoderpos/100.0;
encoderpos=activeline*lcdslow; encoderpos=activeline*lcdslow;
@ -1790,7 +1790,7 @@ void MainMenu::showControlMotion()
if(linechanging) if(linechanging)
{ {
if(encoderpos<5) encoderpos=5; if(encoderpos<5) encoderpos=5;
if(encoderpos>9999) encoderpos=9999; if(encoderpos>999999) encoderpos=999999;
lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0)); lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
} }
@ -1800,7 +1800,7 @@ void MainMenu::showControlMotion()
if(force_lcd_update) if(force_lcd_update)
{ {
lcd.setCursor(0,line);lcdprintPGM(MSG_ZSTEPS); lcd.setCursor(0,line);lcdprintPGM(MSG_ZSTEPS);
lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[2])); lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[Z_AXIS]));
} }
if((activeline!=line) ) if((activeline!=line) )
@ -1811,13 +1811,13 @@ void MainMenu::showControlMotion()
linechanging=!linechanging; linechanging=!linechanging;
if(linechanging) if(linechanging)
{ {
encoderpos=(int)(axis_steps_per_unit[2]*100.0); encoderpos=(long)(axis_steps_per_unit[Z_AXIS]*100.0);
} }
else else
{ {
float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[2]); float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[Z_AXIS]);
position[Z_AXIS]=lround(position[Z_AXIS]*factor); position[Z_AXIS]=lround(position[Z_AXIS]*factor);
//current_position[3]*=factor; //current_position[Z_AXIS]*=factor;
axis_steps_per_unit[Z_AXIS]= encoderpos/100.0; axis_steps_per_unit[Z_AXIS]= encoderpos/100.0;
encoderpos=activeline*lcdslow; encoderpos=activeline*lcdslow;
@ -1828,7 +1828,7 @@ void MainMenu::showControlMotion()
if(linechanging) if(linechanging)
{ {
if(encoderpos<5) encoderpos=5; if(encoderpos<5) encoderpos=5;
if(encoderpos>9999) encoderpos=9999; if(encoderpos>999999) encoderpos=999999;
lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0)); lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
} }
@ -1839,7 +1839,7 @@ void MainMenu::showControlMotion()
if(force_lcd_update) if(force_lcd_update)
{ {
lcd.setCursor(0,line);lcdprintPGM(MSG_ESTEPS); lcd.setCursor(0,line);lcdprintPGM(MSG_ESTEPS);
lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[3])); lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[E_AXIS]));
} }
if((activeline!=line) ) if((activeline!=line) )
@ -1850,13 +1850,13 @@ void MainMenu::showControlMotion()
linechanging=!linechanging; linechanging=!linechanging;
if(linechanging) if(linechanging)
{ {
encoderpos=(int)(axis_steps_per_unit[3]*100.0); encoderpos=(long)(axis_steps_per_unit[E_AXIS]*100.0);
} }
else else
{ {
float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[3]); float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[E_AXIS]);
position[E_AXIS]=lround(position[E_AXIS]*factor); position[E_AXIS]=lround(position[E_AXIS]*factor);
//current_position[3]*=factor; //current_position[E_AXIS]*=factor;
axis_steps_per_unit[E_AXIS]= encoderpos/100.0; axis_steps_per_unit[E_AXIS]= encoderpos/100.0;
encoderpos=activeline*lcdslow; encoderpos=activeline*lcdslow;
@ -1867,7 +1867,7 @@ void MainMenu::showControlMotion()
if(linechanging) if(linechanging)
{ {
if(encoderpos<5) encoderpos=5; if(encoderpos<5) encoderpos=5;
if(encoderpos>9999) encoderpos=9999; if(encoderpos>999999) encoderpos=999999;
lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0)); lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
} }

Loading…
Cancel
Save