Does Timer1 break the Delay() function?

I'm trying to use Timer1 to generate my own internal timer interrupts. I'm also trying to use the delay() function in my Loop(). If I enable my timer interrupts, the delay() function doesn't work. It gets hung up. Does anyone know if this is a known issue? If so, is there another way to have timer interrupts and utilize the delay() function? I could use my own interrupts and a counter, but I'd rather not if I don't have to. All I can think of, is that they require the same clock to operate.

I apologize if this has already been posted. I couldn't find a way to search previous topics.

I appreciate any suggestions.

The delay() function uses millis(), which itself uses Timer 0.

Timer 1 is used by PWM (analogWrite()) functions for those pins connected to Timer 1 (D9 and D10 on a Duemilanove).

-- Check out our new shield: http://www.ruggedcircuits.com/html/gadget_shield.html

It is safe to assume that TimerOne.h uses Timer 1?

If it’s the one you downloaded from the playground, then yes, it uses Timer 1.


Check out our new shield: http://www.ruggedcircuits.com/html/gadget_shield.html

The delay, millis and micros functions work off timer0, independent of timer1.

When you enable interrupts on a timer, you need to make sure there is sufficient time between interrupts to actually process them. If not, your sketch will appear to hang.

Hmm, OK. I'll have to upload my code later and give a better description of what is happening. I don't know if anyone else has seen something like this before.

void loop(){ change values of motors and stuff print statement A delay(100); print statement B }

I'd see print statement A, print statement B, print statement A.... then nothing....

yes, thanks Ben. I considered that. I don't think that's the issue, but it is a possibility. It gets through the delay and other code at first. If I take out the delay, everything else runs fine (just really fast, ha ha). Yeah, I'll have to post my code.... I just didn't know if there was a dependency between these two.

Another bummer is calling delay from within an interrupt handler. That's a dead end.

void loop(){
change values of motors and stuff
print statement A
delay(100);
print statement B
}

I’d see print statement A, print statement B, print statement A… then nothing….

A suggestion different from the question:
Could it be the motors are drawing too much current?

I don't think so, I'm using very small motors and a DC motor controller. The motors are actually being powered from a 9V battery, so the Arduino 5V/digital out pins are not supplying the power; only the logic inputs to the motor driver. Like I said... If I remove the delay(100) call, then the motors and the servo all work wonderfully..... well, the servo moves really fast.

I did write my own hacked delay routine into my interrupt function and it works really nicely. But, I don't think I should have had to do this (it may end up better for me in the end, though). I'll paste my code and see if anyone has seen this same thing (I'll have to get home first). All I can think of, is that there is some kind of hardware contention.

my own hacked delay routine into my interrupt function

:o

What? It’s really not that hard. You just need a global counter or two. You know how often your interrupt will occur, so you can just increment that (those) counter(s) every interrupt, and count them in your delay function. Then, in your delay function, you can do things like read the sensors. ;D

I now see what you have done, but you have a funny way to express it....

Then, in your delay function, you can do things like read the sensors

The problem is that if you call delay from within an interrupt handler, global interrupts will be disabled. When you then check your global variables, they will never increment as long as interrupts are disabled.