Critical timing

I have a small section of code that needs to do some critical timing and I need to make sure there are no interrupts during that period of time. What is the easiest way to disable all interrups on the Baby O and then turn them back on.

Hi,

cli() will disable interrupts and sei() will re-enable them.

nongnu.org/avr-libc/user-man … rupts.html

Hope this helps,
Mike

Thanks Mike - one more question. I get errors when I try to use cli() or sei()… I looked through the source files and see I need to include interupt.h, but that file does not seem to be in my download… can you point me to where I can find it.
Thanks

Hello. Try adding this line to the top of your file:

#include <avr/interrupt.h>

If that doesn’t work, could you tell us what toolchain you have and what files are in your avr/include folder?

–David

I just have the standard AVR Studio download from Pololu.
But I have searched everything and do NOT have the Interrupt.h file ANYWHERE.
Is there a link where I can just download all of the current library files… or… what do you suggest?

That’s weird that you don’t have interrupt.h. Are you sure you looked in C:\WinAVR-20100110\avr\include\avr ?

Anyway, if you just want to use sei() and cli() you can simply add these lines to the top of your program:

#define sei()  __asm__ __volatile__ ("sei" ::)
#define cli()  __asm__ __volatile__ ("cli" ::)

You can download the current library files from the “Download Instructions” page in the Pololu AVR C/C++ Library User’s Guide but that’s not where interrupt.h is so that won’t help you. The file interrupt.h is part of the AVR GCC compiler. You should have gotten it when you installed WinAVR from the Pololu AVR Development Bundle. You can always try reinstalling WinAVR.

–David