[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/diy/ - Do It Yourself

Search:


View post   

>> No.70215 [View]
File: 227 KB, 1280x1024, Photo-0016.jpg [View same] [iqdb] [saucenao] [google]
70215

Greetings fellow /diy/namites. In order to create something I wanted to make a servo turn to the left and then to the right. Anyway, I found out that AVR-Servo communication was a pretty hot topic around, so I present to you my simple servo-turning program for AVR studio. I used a Tower Hobbies TS-53 servo and an ATMEGA32 micro.

//servo.c
#define F_CPU 1000000UL /* 1 MHz CPU clock */
#include <avr/io.h>
#include <util/delay.h>


int main (void)
{
//PortD output
DDRD = 0xFF;

while(1) {
_delay_ms(1200);
for(int i = 1; i<4000; i = i+100)
{
PORTD = 0xFF;
_delay_ms(1);
PORTD = 0x00;
_delay_ms(19);
}

_delay_ms(1200);
for(int i = 4000; i> 1; i = i-100)

{

PORTD = 0xFF;
_delay_ms(2);
PORTD = 0x00;
_delay_ms(18);
}
}

return (1);
}

Now, this program is actually a dumb approach to PWM adn servo control, but he, if it works it's fine with me. I noted that the servo acted funny (joggedm failed to move etc) until I added an 100microfarad cap to it's power supply. It seems that it would drain the power from the system. Adding a diode to the signal line only made things better.

Pic related. It's the darn thing.

Navigation
View posts[+24][+48][+96]