| Author |
Message |
|
|
Posted: Dec 28, 2011 - 03:29 PM |
|

Joined: Dec 28, 2011
Posts: 1
|
|
Hey everybody!
I just started using avr studio and I got a question, I got a problem programming a servo motor in avr studio 5. The meaning of my program is that the servo motor goes to the value in the servo.c file can someone help me? thx
code:main
Code:
#include <avr/io.h>
#include "servo.h"
void main (void)
{
int i;
DDRB = 255;
while(1)
{
PORTB = 255;
for(i=0;i<optel();i++);
PORTB = 0;
for(i=0;i<32000;i++);
}
}
code: servo.c
Code:
#include <avr/io.h>
#include "servo.h"
unsigned char optel (void)
{
optel=300;
}
unsigned char optel (void);
code: servo.h
Code:
[/b] |
|
|
| |
|
|
|
|
|
Posted: Dec 28, 2011 - 07:42 PM |
|

Joined: Mar 05, 2011
Posts: 80
Location: CZ, Zlin
|
|
Hi,
in servo.c
- optel() has no return - add return
- 300 is greater then 255 change char to int
unsigned int optel (void)
{
return 300;
}
in servo.h change declaration to unsigned int optel (void);
- line void main(void) change to int main(void) and add return 0 before last } |
|
|
| |
|
|
|
|
|
Posted: Dec 28, 2011 - 08:15 PM |
|

Joined: Nov 17, 2004
Posts: 13820
Location: Vancouver, BC
|
|
| Wrong forum. This post has absolutely nothing to do with AS5. |
_________________ Regards,
Steve A.
The Board helps those that help themselves.
|
| |
|
|
|
|
|
Posted: Dec 28, 2011 - 08:25 PM |
|

Joined: Mar 05, 2011
Posts: 80
Location: CZ, Zlin
|
|
| OK - for admin (moderator) - move this post to GCC. |
|
|
| |
|
|
|
|
|
Posted: Dec 28, 2011 - 08:43 PM |
|

Joined: Jun 21, 2005
Posts: 882
Location: Chicago area, USA
|
|
|
Koshchi wrote:
Wrong forum. This post has absolutely nothing to do with AS5.
Does not it come with an integrated C compiler? |
|
|
| |
|
|
|
|
|
Posted: Dec 28, 2011 - 09:02 PM |
|

Joined: Mar 05, 2011
Posts: 80
Location: CZ, Zlin
|
|
AS5 forum is about problems with AS5. Installation, compile, debug, help, improve idea,
This post is apparently about beginner and C language |
|
|
| |
|
|
|
|
|
Posted: Dec 28, 2011 - 09:03 PM |
|

Joined: Nov 17, 2004
Posts: 13820
Location: Vancouver, BC
|
|
Irrelevant.
Would you call up the Microsoft help line to answer a question on grammar simply because you were writing in Microsoft Word?
This forum is for questions and problems regarding AS5 itself, not about how to program AVRs. It is certainly not about problems with servos or the C language itself, which is what the problem is here.
Edit: For those of you who might be confused, "this forum" referred to the AS5 forum where this post was originally.
And for whomever moved it, it is still not a good forum since the question is not specific to gcc either. |
_________________ Regards,
Steve A.
The Board helps those that help themselves.
|
| |
|
|
|
|
|
Posted: Dec 28, 2011 - 09:15 PM |
|


Joined: Mar 28, 2001
Posts: 20339
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)
|
|
| hmmm grumble...I should just delete it .... |
_________________ John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
|
| |
|
|
|
|
|
Posted: Dec 28, 2011 - 09:19 PM |
|

Joined: Mar 05, 2011
Posts: 80
Location: CZ, Zlin
|
|
Do not worry - move this post before start its own life with hundreds replies about nothing.
Note: There is not forum for beginners. For anybody is better place post and wait for solution, then learn or find solution in books, in internet, in school.
Your sentence:The Board helps those that help themselves.-- is right. |
|
|
| |
|
|
|
|
|
Posted: Dec 28, 2011 - 09:22 PM |
|

Joined: Nov 17, 2004
Posts: 13820
Location: Vancouver, BC
|
|
|
Quote:
Do not worry - move this post before start its own life with hundreds replies about nothing.
No worries here, the problem was solved with the very first response. |
_________________ Regards,
Steve A.
The Board helps those that help themselves.
|
| |
|
|
|
|
|
Posted: Dec 29, 2011 - 12:16 AM |
|


Joined: Apr 16, 2001
Posts: 3522
Location: Phoenix, Arizona
|
|
| A servo wants to see a specific waveform in order to work properly. You need a pulse between 1 and 2ms, repeated every 20ms of so. Your code produces pulse, but we don't know how wide, since we don't know you clock speed. |
|
|
| |
|
|
|
|
|