I am using an AVR USB programmer with AVR Studio4 (Windows XP) to program a Baby-Orang B-328 to drive a servo on PD0. This is very simple code (I am just learning) designed to simply sweep the servo from one position to another and then back. There is then a delay for a prescribed period of time (say 5 minutes) before repeating the cycle. The cycle should run continuously with a sweep every 5 mins approx.
When I run this code, the servo completes one arc only. The delay_ms() code does not appear to be working properly and the program does not repeat either…any advice or help is appreciated.
Here is my code:
[code]#define F_CPU 20000000
#include <pololu/orangutan.h>
#include <util/delay.h>
int main()
{
while(1)
{
// set output pin for servo to PD0
const unsigned char demuxPins[] = {IO_D0};
servos_init(demuxPins, sizeof(demuxPins));
//initialize variables
int numWipes = 1; // set number of wipes per cycle
int numDelay = 5; // set number of delay period to repeat before main loop
int x;
int y;
//int sleepTime = 1; // set sleep time between cycle (minutes)
//this is a wipe-cycle that is usually set to 1
for(int y = 0; y != numWipes; ++y)
//sweep code
set_servo_target(0, 2000); // Make the servo go to a FIRST position.
delay_ms(20000);
set_servo_target(0, 750); // Make the servo go to a REST position.
delay_ms(900);
//time delay - numDelay cycles in minutes
for(int x = 0; x != numDelay; ++x)
//sleep for desired sleepTime (minutes)
//set_sleep_mode();
//delay_m(sleepTime);
delay_ms(60000);
}
}
[/code]