ATmega16 and Pololu servo Controllers

hi guys ,
I’m building a robotic arm for my senior project . the arm has 5 servos ,so i’m using the Pololu Micro Serial Servo Controller to control them . the problem is i’m bad at programing and the servo’s are not working properly . i’m trying for example to move the shoulder servo up and down the shoulder will move only up and not the right range nor the right time.i’m using the Mini SSC II mode with 9600 baud with . it gets the green light flashing and every thing but the servo just doesn’t move the way i tell them.
this is the code i wrote using codevision (assuming i wanna move the shoulder ,servo 0, up and down) :

#include <mega16.h>
#include <delay.h>
#ifndef RXB8
#define RXB8 1
#endif

#ifndef TXB8
#define TXB8 0
#endif

#ifndef UPE
#define UPE 2
#endif

#ifndef DOR
#define DOR 3
#endif

#ifndef FE
#define FE 4
#endif

#ifndef UDRE
#define UDRE 5
#endif

#ifndef RXC
#define RXC 7
#endif

#define FRAMING_ERROR (1<<FE)
#define PARITY_ERROR (1<<UPE)
#define DATA_OVERRUN (1<<DOR)
#define DATA_REGISTER_EMPTY (1<<UDRE)
#define RX_COMPLETE (1<<RXC)

// USART Transmitter buffer
#define TX_BUFFER_SIZE 8
char tx_buffer[TX_BUFFER_SIZE];

#if TX_BUFFER_SIZE<256
unsigned char tx_wr_index,tx_rd_index,tx_counter;
#else
unsigned int tx_wr_index,tx_rd_index,tx_counter;
#endif

// USART Transmitter interrupt service routine
interrupt [USART_TXC] void usart_tx_isr(void)
{
if (tx_counter)
   {
   --tx_counter;
   UDR=tx_buffer[tx_rd_index];
   if (++tx_rd_index == TX_BUFFER_SIZE) tx_rd_index=0;
   };
}

#ifndef _DEBUG_TERMINAL_IO_
// Write a character to the USART Transmitter buffer
#define _ALTERNATE_PUTCHAR_
#pragma used+
void putchar(char c)
{
while (tx_counter == TX_BUFFER_SIZE);
#asm("cli")
if (tx_counter || ((UCSRA & DATA_REGISTER_EMPTY)==0))
   {
   tx_buffer[tx_wr_index]=c;
   if (++tx_wr_index == TX_BUFFER_SIZE) tx_wr_index=0;
   ++tx_counter;
   }
else
   UDR=c;
#asm("sei")
}
#pragma used-
#endif

// Standard Input/Output functions
#include <stdio.h>

// Declare your global variables here

void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTA=0x00;
DDRA=0x00;

// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTB=0x00;
DDRB=0x00;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTD=0x00;
DDRD=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: Off
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 9600
UCSRA=0x00;
UCSRB=0x48;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x33;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// Global enable interrupts
#asm("sei")

while (1)
      {
      delay_ms(2000);  // two sec delay
      UDR=(0xff,0x00,0xfe); //  move servo 0 to the absulot range
      delay_ms(2000);  // two sec delay
      UDR=(0xff,0x00,0x00); //  move servo 0 to the absulot range
      };
}

the last while loop is were the commands for the servo’s, were UDR is the buffer i send the signal to in the ATmega
any one has an idea please help this project is due in 3 weeks

It looks like you do not really know how to use the serial routines provided with CodeVision. When you write

    UDR=(0xff,0x00,0x00); //  move servo 0 to the absulot range

You are doing something that does not make sense in C. All this does is set UDR equal to 0x00, which sends byte 0x00 on out on the serial port. The first two values are thrown away, and your compiler probably already warned you about the “statement with no effect” or something like that. Did you get warning messages when compiling?

Do you have a reference to using the serial port in CodeVision that you could quote here? Some kind of tutorial you could follow? There are functions defined in your file like putchar() that you are probably supposed to be using.

-Paul

first thanks for answering
yah i’m not really sure what i’m doing
i didnt get any warning or errors when i compile

all of this initialization was generated by codevision and as i know (or thought i knew) that when you communicate in serial you send the data you want to transmit to the buffer (UDR ?)

what is the buffer i have to use in this case?? or to be clear where should i send my data in order for the servo controller to read it properly??

those are two example codes thats on the the ATmega16 manual

the first one is Initialization

#define FOSC 1843200// Clock Speed
#define BAUD 9600
#define MYUBRR FOSC/16/BAUD-1
void main( void )
{
...
USART_Init ( MYUBRR );
...
}
void USART_Init( unsigned int ubrr)
{
/* Set baud rate */
UBRRH = (unsigned char)(ubrr>>8);
UBRRL = (unsigned char)ubrr;
/* Enable receiver and transmitter */
UCSRB = (1<<RXEN)|(1<<TXEN);
/* Set frame format: 8data, 2stop bit */
UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0);
}

and this one for sending the data

void USART_Transmit( unsigned char data )
{
/* Wait for empty transmit buffer */
while ( !( UCSRA & (1<<UDRE)) )
;
/* Put data into buffer, sends the data */
UDR = data;
}

i think my problem is i dont really know how to send the data with the ATmega16

It looked like you were trying to use automatically generated code from CodeVision before - if you still want to do that, you should look at the CodeVision manual or ask them for support. This most recent code you posted looks totally different, but it should also work. If you are still uncertain about how to proceed, you could search Google for “atmega16 serial tutorial” or something and find some code that is already written out explicitly for you.

-Paul

OK i gave up trying to program the micro servo controller
every thing i did is according to the manuals :exclamation:
do you know another way i can control 5 servos with the ATmega16???

Hello.

Using a dedicated servo controller is generally going to be a lot easier than basically making a servo controller yourself. If you can’t send a few bytes out a serial port, what makes you think you can generate the pulses for servo control? It sounds like you don’t really know what you’re doing, so spending even a few days starting with simpler projects might be helpful. Also, if you’re doing this for a school project, you probably have access to some decent test equipment, like at least an oscilloscope, right? You should be able to look at your serial line on the scope to try to figure out what you’re doing wrong.

- Jan