Servo motor is a important part in world technology, but using that is so different with other motor types, every angle of rotation must be controlled by digital signal for example, using microcontroller ( in this section we would use parallax servo motor type standard )
Now, by using CodevisionAVR, please follow instructions :
1. create new project by codevisionavr, set PORTA as output (0) and PORTD as input (T)
2. enter code declaration and go to global variable in codevisionavr :
#include <mega8535.h>
#include <delay.h>
#define servo PORTA.0
// Declare your global variables here
char i,j;
// instruction to moving servo here, void called by command while(1)
void center(char j) // center
{
for(i=0;i<j;++i)
{
servo=1;
delay_us(1500);
servo=0;
delay_ms(20);
}
}
void full_cw(char j) //rotate 180 degree CW
{
for(i=0;i<j;++i)
{
servo=1;
delay_us(2400);
servo=0;
delay_ms(20);
}
}
void full_ccw(char j) //rotate180 degree CCW
{
for(i=0;i<j;++i)
{
servo=1;
delay_us(600);
servo=0;
delay_ms(20);
}
}
// end perintah
/********standard of servo parallax
1000us(0derajat)-2000us(180degree),
so each degree 2000-1000=1000us/180degree=5,56us
example we should rotate to 45 degree
it means the pwm to put is 45*5,56=250,2us+1000us=1250,2us
so if you want to move 45 degree give pwm 1250,2us
more example to 130degree:130*5,56=722,8us+1000us=1722,8us
you should give1722,8us
****/
3. then put this code to while (1)
// Place your code here
if (PIND.0==1)
{
full_cw(40);
}
else if (PIND.1==1)
{
full_ccw(40);
}
else
{
center(40);
}
4. build all and simulated to proteus 7.7 (on this file)
please download the source code here
project atmega8535 codevisionAVR basic servo motor standard1.rar - 42 KB
good luck
» Read More...