OpenServo.com Forum Index OpenServo.com
Discussion of the OpenServo project
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Simple code to test and run the openservo v3 on Atmega16

 
Post new topic   Reply to topic    OpenServo.com Forum Index -> Software
View previous topic :: View next topic  
Author Message
dinozaur



Joined: 01 Jun 2010
Posts: 1

PostPosted: Tue Jun 01, 2010 1:03 pm    Post subject: Simple code to test and run the openservo v3 on Atmega16 Reply with quote

Hello everyone ! Thanks for help Smile
I was trying to find simple code for atmega16 to run openservo v3, but i did not find, maybe I looking too short.
But, I write some code to test openservo v3 via atmega16
This opensrvo v3 is new i buy it from robofuzz.
And I hope the compiled and wrorking hex is on the borad.


Code:
#define F_CPU 8000000UL       //freq 8 MHz
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <avr/delay.h>
#include "UART_routines.h"
#include "TWI.h"

// procedura transmisji sygnału START - transmit signal start
void twistart(void)
{
TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN);
while (!(TWCR & (1<<TWINT)));
}

// procedura transmisji sygnału STOP - transmit signal stop
void twistop(void)
{
TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWSTO);
while ((TWCR & (1<<TWSTO)));
}

// procedura transmisji bajtu danych - procedure to transmit bite of data
void twiwrite(char data)
{
TWDR = data;
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
}

//procedura odczytu bajtu danych - reading bite of data
char twiread(char ack)
{
TWCR = ack
? ((1 << TWINT) | (1 << TWEN) | (1 << TWEA))
: ((1 << TWINT) | (1 << TWEN)) ;
while (!(TWCR & (1<<TWINT)));
return TWDR;
}


#define sbi(port, bit) (port) |= (1 << (bit))
#define cbi(port, bit) (port) &= ~(1 << (bit))

void ustawPORTY(){
   DDRA=0xFF;
   PORTA=0xFF;
   DDRD=0xfe; // D wyjscie, pin 1 wejscie RX
   PORTD=0xfe;// D wysokie
}

void uart0_init(void)
{
 UCSRB = 0x00; //disable while setting baud rate
 UCSRA = 0x00;
 UCSRC = (1 << URSEL) | 0x06;
 UBRRL = 0x19; //set baud rate lo
 UBRRH = 0x00; //set baud rate hi
 UCSRB = 0x18;
}
void uputc(char znak){ // napisz znak, oczekuje na gotowosc - write a sign and wait fore ready
  while (!(UCSRA & (1<<UDRE)));
  UDR = znak;
  while(!(UCSRA & (1<<TXC)));
  sbi(UCSRA,TXC);
}

void uputs(char* wyraz){ // napisz tekst - write text
   int i;
   for(i=0; *wyraz!='\0'; uputc(*wyraz++)); 
}

void sendSign (char licz)
{
   char t;

   t = (char) (((int) licz)/100 + (int) '0');
   uputc(t);
   t = (char) ((((int) licz)/10)%10 + (int) '0');
   uputc(t);
   t = (char) (((int) licz)%10 + (int) '0');
   uputc(t);
}

int main(void)
{
   
  _delay_ms(100);  //delay for VCC stabilization
  ustawPORTY();
  uart0_init();
  TWSR=0;
  TWBR=40; //100kHz
  char data[10];//="twiread";
  //data='a';
char pos_hi;

 // while(1)
    {
   //data = receiveByte();
   //transmitByte(data);
       twistart();
       //twiwrite("0x10");
       //twiwrite("0x08");
         pos_hi=twiread("0x10");
   uputs(pos_hi);
          pos_hi=twiread("0x08");       
   uputs(pos_hi);
       //twiread(pos_hi);
       twistop();
       //transmitByte(data);
       
    }
}


and is it good?
for this code I receive
BD BD


- shall i turn on by some command the openservo ?
- maybe my data frame is wrong ?

this is one cycle / now testing withot while(1)
best regards Krzysztof
Back to top
View user's profile Send private message
robotjay
co-admin


Joined: 01 Aug 2006
Posts: 225
Location: Nebraska, USA

PostPosted: Tue Jun 15, 2010 6:35 pm    Post subject: Reply with quote

Krzysztof,

My apologies that no one has answered you yet. Is it correct to say that you are having problems with the OpenServo you bought from RobotFuzz.co.uk? The OpenServos from RobotFuzz are pre-programmed with the stable version of OpenServo firmware. To make the servos function, you must write appropriate values to the PID registers on the servo.

I don't know what your code is trying to accomplish, and I have no time to go through it line by line. (This is probably the reason no one else has answered.) A shorter summary of your code would be helpful. Talk to you soon.

-Jay
_________________
"Nothing is fool-proof; For we fools are ingenious and will find a way."
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OpenServo.com Forum Index -> Software All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group