| View previous topic :: View next topic |
| Author |
Message |
youthreewire
Joined: 30 Nov 2008 Posts: 39
|
Posted: Wed Dec 17, 2008 11:25 am Post subject: |
|
|
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 |
|
 |
ginge Site Admin
Joined: 14 Jan 2006 Posts: 1027 Location: Manchester, UK
|
Posted: Wed Dec 17, 2008 1:33 pm Post subject: |
|
|
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 |
|
 |
youthreewire
Joined: 30 Nov 2008 Posts: 39
|
Posted: Wed Dec 17, 2008 5:03 pm Post subject: |
|
|
| 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 |
|
 |
mpthompson
Joined: 02 Jan 2006 Posts: 650 Location: San Carlos, CA
|
Posted: Wed Dec 17, 2008 5:20 pm Post subject: |
|
|
| 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 |
|
 |
ginge Site Admin
Joined: 14 Jan 2006 Posts: 1027 Location: Manchester, UK
|
Posted: Wed Dec 17, 2008 11:04 pm Post subject: |
|
|
| 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 |
|
 |
ginge Site Admin
Joined: 14 Jan 2006 Posts: 1027 Location: Manchester, UK
|
Posted: Wed Dec 17, 2008 11:48 pm Post subject: |
|
|
| 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 |
|
 |
youthreewire
Joined: 30 Nov 2008 Posts: 39
|
Posted: Sat Jan 31, 2009 5:20 pm Post subject: |
|
|
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 |
|
 |
ginge Site Admin
Joined: 14 Jan 2006 Posts: 1027 Location: Manchester, UK
|
Posted: Sat Jan 31, 2009 9:24 pm Post subject: |
|
|
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 |
|
 |
youthreewire
Joined: 30 Nov 2008 Posts: 39
|
Posted: Sun Jun 07, 2009 12:54 pm Post subject: |
|
|
| 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 |
|
 |
sikolymester
Joined: 19 Mar 2010 Posts: 1
|
Posted: Fri Mar 19, 2010 11:49 am Post subject: atmega8 board 2.1 |
|
|
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 |
|
 |
|