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 

Atmega8 version of Open servo
Goto page Previous  1, 2, 3, 4
 
Post new topic   Reply to topic    OpenServo.com Forum Index -> Software
View previous topic :: View next topic  
Author Message
youthreewire



Joined: 30 Nov 2008
Posts: 39

PostPosted: Wed Dec 17, 2008 11:25 am    Post subject: Reply with quote

As I understand the following command changes the position:
registers_write_word(REG_SEEK_HI, REG_SEEK_LO, 0x0100);

0x0100 is the position value.But there are always two registers REG_SEEK_HI and REG_SEEK_LO associated with the position.Why are two registers required?

Also REG_MIN_SEEK_LO,REG_MIN_SEEK_HI and REG_MAX_SEEK_LO ,REG_MAX_SEEK_HI are for providing limitation to the servo to save from mechanical flaw which can result from overturning.
Back to top
View user's profile Send private message
ginge
Site Admin


Joined: 14 Jan 2006
Posts: 1029
Location: Manchester, UK

PostPosted: Wed Dec 17, 2008 1:33 pm    Post subject: Reply with quote

Hi,

Each register is an 8 bit value, and can only hold values between 0 to 255

The HI and LO values are used to allow a value greater than 255 to be stored, by storing as a 16bit variable. THis allows values between the range of 0 - 65535

The OpenServo does some simple bit shifting to combine the HI and LO values of the 2 8 bit registers into 1 16 bit value.

The easiest way to explain is by example:

255 in binary is:
11111111

65535 in binary is:
HI LO
11111111 11111111

SO....

New position to be set: 0x0100 in decimal this is 256, or one too large for a single 8 bit register.

So if we show this in binary form...

HI Bit LO bit
00000001 00000000

so when we write the position to the servo, we send 2x 8 bit bytes. The first (HI) is 0x01 the LO is 0x00

So as you can se it is the same as 0x0100


I would highly recommend learning how bits bytes, and bitwise work. You will need this to learn how to manipulate large variables in a small micro

I googled and found this great looking resource.
http://www.cprogramming.com/tutorial/bitwise_operators.html

Barry
_________________
http://www.headfuzz.co.uk/
http://www.robotfuzz.co.uk/
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
youthreewire



Joined: 30 Nov 2008
Posts: 39

PostPosted: Wed Dec 17, 2008 5:03 pm    Post subject: Reply with quote

Quote:
For example, to set a servo position of 980 (which is the max value I can get from a Stell Servo) you would send this command sequence.

Assuming device address = 0x20

I2C communicates using hex bytes, so position 980 translates to 0x03D4

As with any I2C transaction, this 16 bit value must be split into 2 8 bit bytes. All that is required, is to send the upper and lower nibbles of the byte.

send: 0x20 0x10 0x03 0xD4

I understand the 16 bit byte is split to two 8 bit bytes.But SEEK_HI is 0X10 and SEEK_L0 is 0X11.So by just sending "0x20 0x10 0x03 0xD4 " how will the position be written?
Back to top
View user's profile Send private message
mpthompson



Joined: 02 Jan 2006
Posts: 650
Location: San Carlos, CA

PostPosted: Wed Dec 17, 2008 5:20 pm    Post subject: Reply with quote

youthreewire wrote:
Also looking at eeprom.c ,I understand that TWI master slave communication requires value to be read and sent back which are being stored in the EEPROM as a buffer.I think while making this minimal by sending values through the UART eeprom feature can be disabled.


I'm not thoroughly familiar with the latest code, but the EEPROM is basically used to store configuration parameters during power cycles of the Openservo. It is certainly not being used a communication buffer for the TWI port, although the EEPROM does store the one byte address on the I2C/TWI bus.

You can disable the EEPROM feature of the OpenServo, but you'll either need to store the configuration settings statically in the code or always configure the servo through commands sent to it via the UART.

-Mike
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
ginge
Site Admin


Joined: 14 Jan 2006
Posts: 1029
Location: Manchester, UK

PostPosted: Wed Dec 17, 2008 11:04 pm    Post subject: Reply with quote

youthreewire wrote:
Quote:
For example, to set a servo position of 980 (which is the max value I can get from a Stell Servo) you would send this command sequence.

Assuming device address = 0x20

I2C communicates using hex bytes, so position 980 translates to 0x03D4

As with any I2C transaction, this 16 bit value must be split into 2 8 bit bytes. All that is required, is to send the upper and lower nibbles of the byte.

send: 0x20 0x10 0x03 0xD4

I understand the 16 bit byte is split to two 8 bit bytes.But SEEK_HI is 0X10 and SEEK_L0 is 0X11.So by just sending "0x20 0x10 0x03 0xD4 " how will the position be written?


yeah, I wrote that summary... It refers to an I2C transaction.
so:
0x20 is the servo address
0x10 is the _ADDRESS_ of the position register (which to answer your question is SEEK_HI)
0x03 0xD4 is the position

so what you are seeing when you look at SEEK_HI is the position in the data array where the seek position is held. This is defined as 0x10 and 0x11. So this is a reference to the position in the register where you need to write the seek value (0x03d4)
_________________
http://www.headfuzz.co.uk/
http://www.robotfuzz.co.uk/
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
ginge
Site Admin


Joined: 14 Jan 2006
Posts: 1029
Location: Manchester, UK

PostPosted: Wed Dec 17, 2008 11:48 pm    Post subject: Reply with quote

Quote:
I'm not thoroughly familiar with the latest code, but the EEPROM is basically used to store configuration parameters during power cycles of the Openservo. It is certainly not being used a communication buffer for the TWI port, although the EEPROM does store the one byte address on the I2C/TWI bus.

You can disable the EEPROM feature of the OpenServo, but you'll either need to store the configuration settings statically in the code or always configure the servo through commands sent to it via the UART.

-Mike


mike, you are indeed correct. It wouldn'tmake sense to use the eeprom for that. In fact, there are only very small changes to how the twi code works, and it is, for the most part, your original code
_________________
http://www.headfuzz.co.uk/
http://www.robotfuzz.co.uk/
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
youthreewire



Joined: 30 Nov 2008
Posts: 39

PostPosted: Sat Jan 31, 2009 5:20 pm    Post subject: Reply with quote

Coming back alive after a long time.(Sorry for keeping the thread inactive for some time,was involved in other work).Once again I thank Ginge and Mike for their valuable time.

I think TWI.c and eeprom.h go together.The TWI commands write the register values buy updating the higher 4 bits and the lower 4 bits and are stored in the eeprom.
Back to top
View user's profile Send private message
ginge
Site Admin


Joined: 14 Jan 2006
Posts: 1029
Location: Manchester, UK

PostPosted: Sat Jan 31, 2009 9:24 pm    Post subject: Reply with quote

Welcome back Youth!

"I think TWI.c and eeprom.h go together.The TWI commands write the register values buy updating the higher 4 bits and the lower 4 bits and are stored in the eeprom."

Um, this isn't really how OpenServo communication works.

TWI.c has routines to read the values from the hardware TWI module, and then fills a global data array called registers with the data at the relevant position. The eeprom doesn't come into the communication method at all. The eeprom stores the TWI module's slave address and other configuration variables.
It doesn't make sense to use the eeprom in that way, and would wear out the storage cells pretty quickly.

I can show you how the code paths work within twi.c if you want.

Baz
_________________
http://www.headfuzz.co.uk/
http://www.robotfuzz.co.uk/
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
youthreewire



Joined: 30 Nov 2008
Posts: 39

PostPosted: Sun Jun 07, 2009 12:54 pm    Post subject: Reply with quote

ginge wrote:


I can show you how the code paths work within twi.c if you want.

Baz


Hi barry,

I was able to get a bit of PID working.I am now interested to learn about the TWI protocol.Is it possible to use a I2C as well?Also there happens to be a file with macro definitions.I could make a bit of it!!!How did you write that?
Back to top
View user's profile Send private message
sikolymester



Joined: 19 Mar 2010
Posts: 1

PostPosted: Fri Mar 19, 2010 11:49 am    Post subject: atmega8 board 2.1 Reply with quote

Hi, I made a PCB following the v2.1 schematic.
Now I would like to use an atmega8 on it, because it is less costly than an atmega 168. The problem is, that I can't get any code to work in it.
Can you help me finding the files I have to use in the CVS repository.

I can get the code to compile, but realy nothing happens. Only thing that seems to work is reading out the position with the openservo.

Help would be appreciated. Thanks!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenServo.com Forum Index -> Software All times are GMT
Goto page Previous  1, 2, 3, 4
Page 4 of 4

 
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