I want to control a stepper while displaying user menus on a freetronics style 16x2 LCD. I'm using liquidcrystal for my menus and in order to get non-blocking control of the stepper I've imported the StepperLab3 library.

The problem is that the two seem to be incompatible. Either will work if I disable the other, but if I try to run them both, the output on the LCD screen is garbled, and I don't think the stepper driver is working (though I haven't tested it fully - the current sketch uses menu functions to control the stepper and since the menus don't work I can't use it).

I believe the problem is that they're both wanting to use the same timer(…?). This belief is based on this warning on the stepperLab page

Keep in mind that the library is using ATMEGAs timer1 and the corresponding interrupt. Some other libraries or arduino functions might work not correct.

Would a workaround be to try another timer? How many does the Uno have available? Would the LCD be using the timer or interrupts to do PWM for the LED that illuminates the screen?

In the SpepperLab source the timer is set-up here:

void StepperLab3::_setupTimer() {
#if defined (__AVR_ATmega168__) || defined (__AVR_ATmega48__) || defined (__AVR_ATmega88__) || defined (__AVR_ATmega328P__) || (__AVR_ATmega1280__)

// set Timer 1 prescaler to 1
TCCR1B &=  ~((1<<CS11) | (1<<CS12));  // Reset Bits
TCCR1B |=  (1<<CS10);    // set Bits

// Fast PWM 10 bit , WGM13=0,WGM12=1 WGM11=1, WGM10=1
// 64uS / 15.625 KHz

TCCR1A |= (1<<WGM11) ;  //  WGM10=1
TCCR1B |= (1<<WGM12) ;  //  WGM10=1
TCCR1A |= (1<<WGM10);  //  WGM11=1
TCCR1B &= ~(1<<WGM13);  //  WGM13=0
//TCCR1B |= (1<<WGM13);  //  WGM13=1


// set pins as pwm output
TCCR1A |= ((1<<COM1A1) | (1<<COM1B1));

// enable Timer1 Interrupt
TIMSK1 |= (1<<OCIE1A);

Am I going to be able to do a find-and-replace for TCCR1* and change it to TCCR3*?

  • 1
    I don't think LiquidCrystal uses (or has any call to use) a timer. I think you're barking up the wrong tree here. – Majenko May 28 '18 at 9:29
  • Ok, thanks. I'll edit the question to include what's going wrong. – stib May 29 '18 at 4:11

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.