Shop OBEX P1 Docs P2 Docs Learn Events
Automatics Parking Gate — Parallax Forums

Automatics Parking Gate

kakatantkakatant Posts: 8
edited 2011-07-11 17:40 in Robotics
Recently i doing my project Automatics Parking Gate which used Attiny2313 microcontroller control parallax standard servo motor.

Attiny2313 external clock 20MHZ used and below is the code. After program below code and the clock non-stop move the motor CW.. I need to have code can control 0 degree and 90 degree.

#include <avr/io.h>
#include <util/delay.h>
//Simple Wait Function
void Wait()
{
uint8_t i;
for(i=0;i<50;i++)
{
_delay_loop_2(0);
_delay_loop_2(0);
_delay_loop_2(0);
}
}
void main()
{
//Port D pins as input
DDRD=0x00;
//Enable internal pull ups
PORTD=0xFF;
//Set PORTB1 pin as output
DDRB=0xFF;
TCCR1A|=(0<<COM1A0)|(1<<COM1A1)|(0<<COM1B0)|(0<<COM1B1)|(0<<FOC1A)|(0<<FOC1B)|(1<<WGM11)|(0<<WGM10);
TCCR1B|=(0<<ICNC1)|(0<<ICES1)|(1<<WGM13)|(1<<WGM12)| (0<<CS12)|(1<<CS11)|(0<<CS10);
ICR1=18429; //fPWM=50Hz (Period = 20ms Standard).
DDRD|=(1<<PD4)|(1<<PD5); //PWM Pins as Out
while(1)
{
OCR1A=650; //0 degree
Wait();
OCR1A=750; //90 degree
Wait();
OCR1A=850; //135 degree
Wait();
OCR1A=650; //180 degree
Wait();
}
}
553 x 352 - 60K

Comments

Sign In or Register to comment.