Random Pauses Messing Up Timing//Interrupt Problem?

Hi,

I have a simple program turning bit 7 of PORTD off and on. However, when I look at the output on an oscilloscope, a 5uS pause is obvious and messing up how the signal should look. I noticed when I disable interrupts, this 5uS pause goes away....however I need to use interrupts for my project.

Anyone have any idea what causes this and how I can mitigate it?

#include <avr/io.h> 
#include <avr/interrupt.h>
#include <avr/wdt.h>
void setup() {   
  wdt_disable();  
  //cli();  //When Uncommented, It Works Like A Charm
  DDRD = 0xFF;   

}
void loop() {
  while(1){
  PORTD |= _BV(7);
  __asm__ ("nop\n\t""nop\n\t""nop\n\t""nop\n\t"); //Pause 4 Cycles
  PORTD &= ~_BV(7);
  __asm__ ("nop\n\t""nop\n\t""nop\n\t""nop\n\t"); //Pause 4 Cycles
  }
}
EMPTY_INTERRUPT(BADISR_vect);

Bit 7 output of PORTD when interrupts disabled:

Bit 7 output of PORTD when interrupts enabled w/ 5us 'pause':

Thanks for any and all help!

You're bound to get glitches (they're not random, BTW) when the timer overflow interrupt occurs.
Why not use the timers to generate your waveform, and reserve the processor for slower stuff?

Disgusting! You said it! I hate it when that happens.

Just out of curiosity, do those "random" glitches happen every 1.024 mS?

They do, don't they?

So it's not random, nor is it disgusting.

AWOL:
You're bound to get glitches (they're not random, BTW) when the timer overflow interrupt occurs.
Why not use the timers to generate your waveform, and reserve the processor for slower stuff?

I would love to do as you've described, however you're implying using interrupts and this 5uS 'pause' exists anytime interrupts are enabled and it messes up my signal.

Can you explain or point me in the direction of what is causing this...I've run out of ideas for tracking it down? You mentioned a timer overflow, I wasn't using a timer in my code, perhaps you're talking about one Arduino uses...do you know where that is in the Arduino C files so I could modify it to get rid of this?

Thanks again.

, however you're implying using interrupts

No, I'm suggesting you live with the interrupts you already have, and use the hardware timers to generate your waveform.

The "glitch" you're seeing is caused by the timer used to generate the Arduino's software "micros" and "millis" clock.

If you have a dig around in the Playground, you should find tutorials and hints on how to user the timers to do what you want.

The Arduino timer code is is
hardware/arduino/cores/arduino/wiring.c

AWOL:

, however you're implying using interrupts

No, I'm suggesting you live with the interrupts you already have, and use the hardware timers to generate your waveform.

The "glitch" you're seeing is caused by the timer used to generate the Arduino's software "micros" and "millis" clock.

If you have a dig around in the Playground, you should find tutorials and hints on how to user the timers to do what you want.

The Arduino timer code is is
hardware/arduino/cores/arduino/wiring.c

Yea thanks. I just got rid of that Timer0 interrupt in wiring.c for Timer0 and everything works perfect.

Thanks.

Not sure that that is what anyone was suggesting - for a time critical application most of us would just set up the hardware timers to do their thing in the background. They are entirely hardware based and not effected by whatever the software is doing elsewhere on the micro controller - until you want to effect them that is.

Look up the hardware timers in the datasheet, its not the easiest reading, but there are various waveform generation modes built in to do exactly what you want without software or interrupts getting in the way.

Duane B

rcarduino.blogspot.com

DuaneB:
Not sure that that is what anyone was suggesting - for a time critical application most of us would just set up the hardware timers to do their thing in the background. They are entirely hardware based and not effected by whatever the software is doing elsewhere on the micro controller - until you want to effect them that is.

Look up the hardware timers in the datasheet, its not the easiest reading, but there are various waveform generation modes built in to do exactly what you want without software or interrupts getting in the way.

Duane B

rcarduino.blogspot.com

Hi,

I didn't look into it completely but the Timer0 that arduino uses to generate the millis() was the problem and since my app is time sensitive I couldn't have it pausing my real program or interrupts (timer0 is a higher priority I guess?) every 1.024mS with a 5uS freeze.

Either way about it, disabling that Timer0's interrupt means the only interrupts that run are my own which is exactly what I happened to need.

Thanks again for the help guys.