That function is not part of WinAVR; you need to install the Pololu AVR library to access it. WinAVR does have the function _delay_us() in util/delay.h, but it can only delay for around 13 microseconds if your CPU frequency is 20 MHz, so you would need to call it multiple times to achieve longer delays.
You probably no longer need this line since the the Pololu library gives you the same delay functions. Note that delay.h uses almost no RAM, but you can easily determine your heap and flash usage by compiling your program in AVR Studio and seeing how much data memory and program memory it is using.
The result is quite compact and flexible. The macros above are for a 20MHz CPU clock, but they can be constructed for the general case using F_CPU if desired.
Yes I was able to install the package and now compiles successfully.
You mentioned 13ms?
I am really trying to create a delay to move a servo using the BabyO 168.
the code is below and the code was giving to me by Ryan, he said
"Position_delay greater than 1800 or less than 1200, because your servo might run into its stops."
Can you advise further as to a proper delay for this application or is the delay_us
sufficent?
And thank for the advise
void S1_MOVE(int delay_amt)
{
if (delay_amt == 0)
{
// PORTC &= ~(1 << PORTC2); // stop servo
return;
}
// set pin high run servo
PORTC |= 1 << PORTC2;
// delay
delay_us(delay_amt);
// stop servo
// PORTC &= ~(1 << PORTC2);
// delay rest of the time
delay_us(2000 - delay_amt);
}
The delay_us() function in the Pololu AVR library can accept any two-byte unsigned integer as argument. The _delay_us() function from util/delay.h is the one that can only delay for a few microseconds when your MCU is running at 20 MHz.
Probably, though I don’t want to make any strong claims since I don’t know anything about the servo you’re using. You should carefully test it to see what the limits are by writing a program that outputs a fixed-length pulse train. Start with 1500us and then change the value in steps to figure out what your servo can do.