Speeding Up LCD Readout Without Slowing Down Everything Else?

I have installed an LCD into my stepper motor CNC project. Updating the display to call out each step (<=300/sec) slows down the actual movement of the motor. This was discussed here:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1290545711

I could do sampling at a set time interval like those guys did but it was suggested that the time interval should be as big as once per second or half second. I quickly ran a test and found that I could see intelligible readings down to a tenth of a second. While this is not necessary, I feel that one tenth has a better look.

A lot of effort has been made to use less pins, i.e. using 4 bit mode instead of 8 etc. but I have a Mega with lots of extra pins, a Rugged Stepper Driver Shield and a Hitachi 16x2 display. It has a shield that comes with 5 useable buttons and another one for reset, none of which I plan to use. Looking at the three boards, I started wondering if I could go bigger instead of smaller.

My question would be, are there any unused recourses available that I could take advantage of to let me use the one tenth of a second setting for display without slowing down my stepper motor? Failing that, is there an inexpensive (and easy to incorporate) board that would make this possible?

(hope that I understand your question right:)

Somewhere in your code you have:

if (Steps==800)
{
  lcd.clear();
  lcd.setCursor(0,0); lcd.print("Steps:");
  lcd.setCursor(6,0); lcd.print(Steps);
  lcd.setCursor(0,1); lcd.print("Revolutions:");
  lcd.setCursor(12,1); lcd.print(Revolutions);
}

what is expensive in this, is the lcd.clear(), for most LCD's this is an expensive call as all char locations are cleared. And the next thing you do is put the same text there again, or at least the fixed strings "Steps:" & "Revolutions:" . You should move those fixed strings out of the inner loop and remove the lcd.clear() altogether.

code should become something like

if (millis() - lasttime > 100)    // 100 millis = 0.1 sec
{
  lcd.setCursor(7,0); lcd.print("     ");  // maybe less spaces are needed 
  lcd.setCursor(6,0); lcd.print(Steps);
  lcd.setCursor(13,1); lcd.print("       ");
  lcd.setCursor(12,1); lcd.print(Revolutions);
  lasttime = millis();
}

Note that I overwrite the old value of steps with spaces except the first digit as that will be overwritten by the new value of Steps for sure. I don't know how much spaces are needed , depends on the maximum length of steps

An even slightly faster but a but more opportunistic approach is this

if (millis() - lasttime > 100)    // 100 millis = 0.1 sec
{
  lcd.setCursor(6,0); lcd.print(Steps);  lcd.print("  "); // 2 spaces maybe 1 is enough
  lcd.setCursor(12,1); lcd.print(Revolutions); lcd.print("  ");
  lasttime = millis();
}

The assumption is that the length of Steps decreases not more than 2 digits per 0.1 sec.

hopes this helps, otherwise please post your code so we can have a better look.

I like that two digit idea. I didn't expect that.

I thought about " " to achieve right justification for the readout number but I didn't know that it was faster for a standard clear. Thanks I know that all this will be faster but I can't test to see how close it will come to perfect until tonight. I can see that it will be quite a bit better and that should be good enough.

I don't know much about this stuff. In addition to this, can I also use some buffer or something like that (code or some unused chip)?

Another (millisec) timesaver, only update the vars on the screen if they have changed. Therefor you need the previous value (prevSteps prevRevolutions).

// additional global vars
float/int prevSteps = -1;             // should be same type as Steps float or int or ...
float/int prevRevolutions = -1;

...

if (millis() - lasttime > 100)    // 100 millis = 0.1 sec
{
  // did it change? then update screen
  if (prevSteps != Steps)  
  {
    lcd.setCursor(6,0); lcd.print(Steps);  lcd.print("  "); // 2 spaces maybe 1 is enough
    prevSteps = Steps;  // store last displayed value
  }

  if (prevRevolutions != Revolutions)
  {
    lcd.setCursor(12,1); lcd.print(Revolutions); lcd.print("  ");
    prevRevolutions != Revolutions;
  }
  lasttime = millis();
}

My question would be, are there any unused recourses available that I could take advantage of to let me use the one tenth of a second setting for display without slowing down my stepper motor?

There are several basic approaches that will speed things up and they were all mentioned in the forum thread that you referenced in your first post.
(1) Don't use the lcd.clear() function if you can avoid it.
(2) Don't redisplay information that never changes.
(3) Use the busy flag to determine when you can write to the LCD display instead of using time delays.
(4) Use interrupts to drive the stepper.

Since driving the stepper is the primary function of your program then (4) is probably the only one that will really give satisfactory results.

Don

I have not tried this but maybe a decent serial LCD can speed things up. You can read about serial LCDs here: