conflict with IntervalTimer and display library

Status
Not open for further replies.

instrumentek

Well-known member
Hi;

I have an issue where intervalTimer runs until I call my display to print. I'm thinking its a conflict of some kind. I cut down the program to demonstrate the issue. I'm using:
- Teensy LC
- Teesny loader 1.27
- arduino IDE 1.6.3
- nokia 5110 display

Have tried different display commands, only the ".display" causes the timer to stop. I tried adding a priority, makes no difference

Code:
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
Adafruit_PCD8544 MyDisplay = Adafruit_PCD8544(13, 12, 8, 10, 11);

IntervalTimer MyTimer;

void setup()
{
  pinMode(9, OUTPUT);
  MyTimer.begin(MyFunction, 200000);
  MyTimer.priority(1);
}

void loop() {
  MyDisplay.print("test");  // timer working
  delay(5000);              //timer working
  MyDisplay.display();      // timer stops after 5 secconds
}

void MyFunction(void)
{
  digitalWrite(9, 1);
  delayMicroseconds(30000);
  delayMicroseconds(30000);
  delayMicroseconds(30000);
  digitalWrite(9, 0);
}

Thanks for any input
 
You want to spend as little time in your interrupts as possible so change MyFunction to:
Code:
void MyFunction(void)
{
  static uint8_t toggleState = 0;
  digitalWriteFast(9, toggleState);
  toggleState = !toggleState
}

Also try your setup() like so:
Code:
void setup()
{
  pinMode(9, OUTPUT);
  MyTimer.priority(0);
  MyTimer.begin(MyFunction, 200000);
}


EDIT -
Does MyDisplay.display(); work before you put in the timer?
 
Last edited:
Thanks for the ideas;

I tried both of these and have the same issue. There is also something else i am noticing, if i call "tone" (in my un-edited program) the interval timer starts to work again? im trying to get an example going to post it.
 
I think i got it somewhat working. I needed to declare the timer after initialized the display screen(which i forgot to add into the code i posted here). I was trying to make a sketch to demonstrate but it seems the problem must be a combination of things i was doing wrong / wrong order in my original prog
 
I just realized IntervalTimer must also have a conflict with the timers in the different functions. I had more then one issue. I have found if i activate tone() on a pin then off again it slows the interval timer until the teensy resets. is there a way to have both an intervalTimer and a Tone working? Even if there not running at the same time but just so i can use both even if at different times. Below is a sketch that demonstrates my issues:

Code:
IntervalTimer MyTimer;

void setup()
{
  pinMode(21, OUTPUT);
  pinMode(9, OUTPUT);
  MyTimer.priority(0);
  MyTimer.begin(MyFunction, 200000);
}

void loop() {

  delay(5000);              //timer works once only correctly

  tone(21, 1000);
  noTone(21);

  delay(5000);              //timer is now slow untill teensy reset

}

void MyFunction(void)
{
  static uint8_t toggleState = 0;
  digitalWriteFast(9, toggleState);
  toggleState = !toggleState;
}
 
Tone uses interval timer....

I just compiled your code and it acts the same with and without tone() in it.

Teensy 3.2
Arduino 1.6.7
Teensyduino 1.27
96MHZ Optimized


Maybe someone who has used the LC can interject here?
 
Last edited:
In theory, tone() and your code are supposed to use 2 different timers.

Below is a sketch that demonstrates my issues:

Can you please be more specific about the problem.

If I run the program in message #5, what specific wrong behavior do I try to observe. I do not understand what you mean by "it slows the interval timer". Please, tell me **exactly** how you've observing the problem? An oscilloscope, benchtop frequency counter, handheld multimeter, visually watching a LED blink?

Just to be clear, this program in #5 will reproduce the problem without the Nokia 5110 display, right?

I can and will test it here, but please be specific about how I should test to see the same problem you're seeing, so I don't waste time on a wild goose chase.
 
In theory, tone() and your code are supposed to use 2 different timers.



Can you please be more specific about the problem.

If I run the program in message #5, what specific wrong behavior do I try to observe. I do not understand what you mean by "it slows the interval timer". Please, tell me **exactly** how you've observing the problem? An oscilloscope, benchtop frequency counter, handheld multimeter, visually watching a LED blink?

Just to be clear, this program in #5 will reproduce the problem without the Nokia 5110 display, right?

I can and will test it here, but please be specific about how I should test to see the same problem you're seeing, so I don't waste time on a wild goose chase.


In the program in message #5 the LED blinks (digital output 9) off and on 5 times a second for the first delay of 5 seconds. After the tone(21,1000); no tone(21); The blinking still happens but its very slow like once every 10 seconds(i'm not in front of this project ATM so that is an estimate). This acts up without the nokia 5110 or its libraries

In my original program I found a work around, if I re initialize the intervalTimer after noTone(); it seems to works fine.
 
Hi again;
sorry about the delay today is my first day off again. I have done some more testing and wrote a different program so I can give some better and quantitative observations. The below program is exactly what i have in my sketch, nothing is missing or added.
I have a teensy LC with 2 switches hooked up that connect either GND or 3.3V+ to digital pins 1 and 2. I have a 10k pull up hooked between pin 3 and 3.3V+. I am using a fluke 787 with the positive measure lead on pin 3 between the pull up resistor and Teensy. The negative lead of the meter is hooked to GND. Teensy is hooked to USB for power. No other connections are made to the teensy.
Results:
- Reset teensy with both switches in GND position: fluke measures 500 Hz I ran it for several min like this.
- Toggle switch 2 to 3.3 volts Hz goes to 0.00, if I move toggle switch back to GND it stays at 0.00
- Toggle switch 1 to 3.3 volts HZ goes to 500, if I move toggle switch back to GND it stays at 500
- The last two steps can be repeated over and over without resetting the teensy.

Code:
IntervalTimer MyTimer;
unsigned long a = 0;
unsigned long b = 0;

void setup()
{
  pinMode(1, INPUT); // switch 1
  pinMode(2, INPUT); // switch 2
  pinMode(3, OUTPUT); // output for interval timer
  pinMode(4, OUTPUT); // random output for tone / notone
  MyTimer.priority(0);
  MyTimer.begin(MyFunction, 1000);
}

void loop() {

  if (digitalRead(1) == 1)
    MyTimer.begin(MyFunction, 1000);

  if (digitalRead(2) == 1)
  {
    tone(4, 1000);
    noTone(4);
  }
}

void MyFunction(void)
{
  static uint8_t toggleState = 0;
  digitalWriteFast(3, toggleState);
  toggleState = !toggleState;
}
 
Status
Not open for further replies.
Back
Top