Back

/*********************************************************************

                 xBoard(TM) v2.0 Sample Programs
               ------------------------------------


Description :  Demonstrate the use of DC motor. Teaches you how to control
            the speed and direction od DC motors.

            The program starts the MOTOR - A in CW direction with
            with Full Speed. Then it changes speed to half.

            After that the direction is reversed and speed is again
            set to MAX. After some time speed is reduced to 50%

            This whole process is repeated again and again.


Author      : Avinash Gupta 2008
Web         : www.eXtremeElectronics.co.in
                   
**********************************************************************/

#include <avr/io.h>
#include <util/delay.h>

#include "motor.h"

//Simple Delay Function
void Wait()
{
   uint8_t i;

   for(i=0;i<250;i++)
      _delay_loop_2(0);

   for(i=0;i<250;i++)
      _delay_loop_2(0);
}

void main()
{
   //Initialize motor subsystem
   MotorInit();

   while(1)
   {
      //Start Motor A in Clock Wise (CW) direction with full speed (255)
      MotorA(MOTOR_CW,255);

      //Wait
      Wait();

      //Set speed to half
      MotorA(MOTOR_CW,127);

      //Wait
      Wait();

      //Now change direction to Counter Clock Wise (CCW)
      MotorA(MOTOR_CCW,255);

      //Wait
      Wait();

      //Now change direction to Counter Clock Wise (CCW)
      MotorA(MOTOR_CCW,127);

      //Wait
      Wait();
   }

}

Top