Hi,
I’m a very happy owner of a BH3-R starting a new learning course.
Today I started to program my micro controller, figgering out that servo-pulse thing. Aldue I’m doing quite well, I’m kinda stuck.
I buyed the default HItec HS-475HB servo’s but I can’t get them to rotate 180 degrees.
Some details,
I’m a experienced programmer willing to learn (better) C/C++ and ASM.
I have never before programmed a micro controller so I toulght let’ s start easy with a atmel AVR Mega128 ( ).
I wrote some simple test loop in c:
#define ServoPort_A PORTA
#define ServoPort_B PORTB
#define ServoPort_C PORTC
#define DdrPreset 0xFF
#include <avr/io.h>
// I have a 16MHz XTAL on my dev board.
// So lets make sure F_CPU is set before including delay.h
#ifdef F_CPU
#undef F_CPU
#endif
#define F_CPU 16000000UL // 16 MHz
#include <util/delay.h>
int main()
{
// Set all used DDR bits
DDRA=DdrPreset;
DDRB=DdrPreset;
DDRC=DdrPreset;
int16_t Delay;
Delay=0;
while(1){
ServoPort_A=0xFF;
ServoPort_B=0xFF;
ServoPort_C=0xFF;
_delay_ms(1.5);
ServoPort_A=0x00;
ServoPort_B=0x00;
ServoPort_C=0x00;
_delay_ms(15);
while(Delay<200){
Delay++;
ServoPort_A=0xFF;
ServoPort_B=0xFF;
ServoPort_C=0xFF;
_delay_ms(2);
ServoPort_A=0x00;
ServoPort_B=0x00;
ServoPort_C=0x00;
_delay_ms(15);
}
while(Delay>1){
Delay--;
ServoPort_A=0xFF;
ServoPort_B=0xFF;
ServoPort_C=0xFF;
_delay_ms(1);
ServoPort_A=0x00;
ServoPort_B=0x00;
ServoPort_C=0x00;
_delay_ms(15);
}
}
return 0;
}
Fuses set:
OCDEN
JTAGEN
CKOPT
SUT0
In my rather n00bish opinion I would say this should do the trick,…
The code should move the servo from one side to another,… and it does.
The problem is that this should be 180 degree rotating servo’s, but it is only rotating 90 degrees.
What am I doing wrong and what should I do to get this thing rotating 180 degrees?
Anny help is appreciated.