[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] How to (efficeiently !!!) test abitwithinamulti-byte
From: |
Dave Hylands |
Subject: |
Re: [avr-gcc-list] How to (efficeiently !!!) test abitwithinamulti-byte intege |
Date: |
Fri, 4 Nov 2005 15:54:45 -0800 |
> FWIW, I always had good luck with the delay functions in delay.h for short
> hardcoded (usec) delays. I don't have access to the code now, but I had a
> macro that calculated the minimum number of trips through the four-cycle
> loop that would guarantee the specified delay. Something like
>
> #define usec_count_(x) ((OSC_FREQ*(x))/4000000)
> #define delay_us(x) _delay_loop_2(usec_count_(x))
>
> It looks like the library also provides _delay_us, which might be better,
> though I've never tried it. Requires you to #define F_CPU before #including
> avr/delay.h.
I picked up this one somewhere:
#define LOOPS_PER_MS (F_CPU/1000/4)
#define LOOPS_PER_US (LOOPS_PER_MS/1000)
/* spin for us microseconds */
void us_spin(unsigned short us)
{
if (!us)
return;
/* the inner loop takes 4 cycles per iteration */
__asm__ __volatile__ (
"1: \n"
" ldi r26, %3 \n"
" ldi r27, %2 \n"
"2: sbiw r26, 1 \n"
" brne 2b \n"
" sbiw %0, 1 \n"
" brne 1b \n"
: "=w" (us)
: "w" (us), "i" (LOOPS_PER_US >> 8), "i" (0xff & LOOPS_PER_US)
);
}
/* spin for ms milliseconds */
void ms_spin(unsigned short ms)
{
if (!ms)
return;
/* the inner loop takes 4 cycles per iteration */
__asm__ __volatile__ (
"1: \n"
" ldi r26, %3 \n"
" ldi r27, %2 \n"
"2: sbiw r26, 1 \n"
" brne 2b \n"
" sbiw %0, 1 \n"
" brne 1b \n"
: "=w" (ms)
: "w" (ms), "i" (LOOPS_PER_MS >> 8), "i" (0xff & LOOPS_PER_MS)
);
}
The ones in avr/delay.h use the same core loop.
--
Dave Hylands
Vancouver, BC, Canada
http://www.DaveHylands.com/
- Re: [avr-gcc-list] How to (efficeiently !!!) test a bit within a multi-byte integer ?, (continued)
- Re: [avr-gcc-list] How to (efficeiently !!!) test a bit within a multi-byte integer ?, Vincent Trouilliez, 2005/11/04
- Re: [avr-gcc-list] How to (efficeiently !!!) test a bit within a multi-byte integer ?, Ian Caddy, 2005/11/04
- Re: [avr-gcc-list] How to (efficeiently !!!) test a bit within a multi-byte integer ?, Vincent Trouilliez, 2005/11/04
- Re: [avr-gcc-list] How to (efficeiently !!!) test a bit within amulti-byte integer ?, Jurek Szczesiul, 2005/11/04
- Re: [avr-gcc-list] How to (efficeiently !!!) test a bit within amulti-byte integer ?, Vincent Trouilliez, 2005/11/04
- RE: [avr-gcc-list] How to (efficeiently !!!) test a bit withinamulti-byte integer ?, niklo, 2005/11/04
- RE: [avr-gcc-list] How to (efficeiently !!!) test a bit withinamulti-byte integer ?, Vincent Trouilliez, 2005/11/04
- Re: [avr-gcc-list] How to (efficeiently !!!) test a bit withinamulti-byte intege, Dave Hansen, 2005/11/04
- Re: [avr-gcc-list] How to (efficeiently !!!) test a bitwithinamulti-byte intege, David Brown, 2005/11/04
- Re: [avr-gcc-list] How to (efficeiently !!!) test abitwithinamulti-byte intege, Dave Hansen, 2005/11/04
- Re: [avr-gcc-list] How to (efficeiently !!!) test abitwithinamulti-byte intege,
Dave Hylands <=
- Re: [avr-gcc-list] How to (efficeiently !!!) test abitwithinamulti-byte intege, Vincent Trouilliez, 2005/11/05
- Re: [avr-gcc-list] How to (efficeiently !!!) test abitwithinamulti-byte intege, Joerg Wunsch, 2005/11/05
- Re: [avr-gcc-list] How to (efficeiently !!!) test abitwithinamulti-byte intege, Vincent Trouilliez, 2005/11/05
- Re: [avr-gcc-list] How to (efficeiently !!!) test abitwithinamulti-byte intege, Joerg Wunsch, 2005/11/05
- Re: [avr-gcc-list] How to (efficeiently !!!) test abitwithinamulti-byte intege, Vincent Trouilliez, 2005/11/05
- Re: [avr-gcc-list] How to (efficeiently !!!) testabitwithinamulti-byte intege, Dave Hansen, 2005/11/07
- Re: [avr-gcc-list] How to (efficeiently !!!) test a bitwithinamulti-byte intege, Vincent Trouilliez, 2005/11/05
- Re: [avr-gcc-list] How to (efficeiently !!!) test a bitwithinamulti-byte intege, David Kelly, 2005/11/05
- Re: [avr-gcc-list] How to (efficeiently !!!) test a bitwithinamulti-byte intege, Vincent Trouilliez, 2005/11/05
- Re: [avr-gcc-list] How to (efficeiently !!!) test a bit within amulti-byte integer ?, Derric Tubbs, 2005/11/04