servo motor drive c programme code

Status
Not open for further replies.

electronicsbaazar

Newbie level 1
Joined
Feb 27, 2013
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,284
Code:
#include <avr/io.h>
#include <util/delay.h>


void main()
{
 DDRA=0X00;

  unsigned char i,x,temp,y;  
  
   //Configure TIMER1
   TCCR1A|=(1<<COM1A1)|(1<<COM1B1)|(1<<WGM11);          //NON Inverted PWM
   TCCR1B|=(1<<WGM13)|(1<<WGM12)|(0<<CS11)|(1<<CS10);   //PRESCALER=1 MODE 14(FAST PWM)

   ICR1=19999;   //fPWM=50Hz (Period = 20ms Standard).

   DDRD|=(1<<PD4)|(1<<PD5);   //PWM Pins as Out

   while(1)
   {

      
       x=PINA&0b00001111;

if(x==0b00001111)
      
 {
   OCR1A=600;   //45 degree
      _delay_ms(200);
  }

      OCR1A=1050;   //90 degree
      _delay_ms(200);

      OCR1A=1950;   //135 degree
      _delay_ms(200);

      OCR1A=2400;   //180 degree
      _delay_ms(200);
	   OCR1A=600;   //45 degree
      _delay_ms(200);

      OCR1A=1050;   //90 degree
      _delay_ms(200);

      OCR1A=1950;   //135 degree
      _delay_ms(200);

      OCR1A=2400;   //180 degree
      _delay_ms(200);
	    OCR1A=1950;   //135 degree
      _delay_ms(200);

   }
}


work perfectly
 
Last edited by a moderator:

hi electronicsbaazar i want to drive 2 servo motor with an atmega32 with 2 input pins ( 00 pause /01 left servo on only /10 right servo on only /11 both on ) can you help me to adapt this programme please ?
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…