View unanswered posts | View active topics It is currently Thu Apr 17, 2014 9:26 pm






Reply to topic  [ 8 posts ] 
Speed of I2C? 
Author Message
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Speed of I2C?
How many bits-per-second is I2C with RobotC? Communicating with, say, the LineLeader?

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Thu Sep 13, 2012 11:36 pm
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3105
Location: Rotterdam, The Netherlands
Post Re: Speed of I2C?
At the standard speed, the clock speed is around 10kHz, at the fast speed, it's about 30kHz. With each clock tick, a bit of data can be transmitted. Please note that not everything that is transmitted is actual data, there are start, stop, nack and acks.

ST = start (1 bit)
SP = stop (1 bit)
A = ack (1 bit)
N = nack (1 bit)
AD = I2C address (7 bit + 1 direction bit)
R = register address (1 byte)
D = data

After every 8 bits of data, an ACK or NACK is sent to the sending side.
At the start of each transmission, the master will send a START, followed by the address of the slave.
At the end of each transmission, the master will send a STOP

To query a register, the master would send: stuff inside <>'s is from the slave to the master.
ST AD <A> R <A> SP
ST AD <D1> N SP
The nack is sent from the master to the slave to basically tell it that it's had enough data. So you see, a simple query to request a single byte from a sensor, is in fact two queries. A request from the master for multiple bytes (4 in this case, could be a long-sized number, for example), would look like this:
ST AD <A> R <A> SP
ST AD <D1> A <D2> A <D3> A <D4> N SP
If, for example, you wanted to send a command to the Lineleader, you'd send something to register 0x41 (the standard command register). It would look something like this:
ST AD <A> R <A> D1 <A> SP
There are no further requests required, since this was a one-way thing.

It's because of this that you'll find in my drivers that I try to do things in as few queries as possible.

Question 1: For a standard transaction that queries a register, requesting a single byte from a sensor, calculate the amount of ms required to transmit the request and receive the response. Do this for both 10kHz and 30kHz. You can ignore the time between the 1st and 2nd request from the master.

Question 2: For a standard transaction that queries a register from a sensor but requests 12 bytes, calculate the max number of transactions you could achieve per second. There is a 1ms wait between each query/response pair. You can ignore the time between each 1st and 2nd query from the master. Do this for both 10kHz and 30kHz.

You have 1 day to come up with a good answer or else no points for you.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Sep 14, 2012 2:16 am
Profile WWW
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: Speed of I2C?
You adults, always trying to find a learning opportunity.

Q1. Approximately 4.1ms at 10kHz, and 1.36ms at 30kHz. A total of 41 bits transferred.
Q2. Approximately 72 times-per-second at 10kHz, and 217 at 30kHz. 138 bits.

It's best I can tell... The brain is slightly confused by all this.

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Sat Sep 15, 2012 3:57 pm
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3105
Location: Rotterdam, The Netherlands
Post Re: Speed of I2C?
Hey there,

I did a bunch of tests a few years ago to test the transfer speeds in ROBOTC and at 10kHz, a query for a single byte takes about 6ms and about 2ms at 30kHz.

A 12 byte request can be done about 58 times per second as it takes about 16ms to complete at 10kHz (+1 ms wait time between each transaction). The same query at 30kHz takes a mere 5 ms, with a 1ms wait between each, that's about 166 transactions per second.

Results with the current version of ROBOTC may be slightly different now, it's been quite a while since I last did these.

Keep in mind that transferring 1 byte takes as long as two, same goes for 3 and 4, 5 and 6, etc, etc. It is not completely linear between each increased number of bytes. This is probably due to some internal delays, etc. If you have a Mindsensors or Dexter Industries sensor (they both play well at 30kHz), I challenge you to run your own tests and publish your results in a little report.

I have attached some programs I found in my projects directory that may of help to you, just see what you can salvage. I've made them compile with 3.50 but I don't know if they work :)

Ah, bloody adults, always with the homework! If you come up with something good, I will make sure it gets published on my blog and the ROBOTC site's blog.

- Xander


Attachments:
I2C_SpeedTest-1.3.c [2.67 KiB]
Downloaded 136 times
I2C_SpeedTest-1.2.c [2.75 KiB]
Downloaded 140 times
I2C_SpeedTest-1.1.c [2.72 KiB]
Downloaded 136 times
I2C_SpeedTest.c [2.48 KiB]
Downloaded 145 times

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]
Sun Sep 16, 2012 12:44 am
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3105
Location: Rotterdam, The Netherlands
Post Re: Speed of I2C?
Here's an old post I did about it: http://botbench.com/blog/2008/10/25/tak ... n-the-nxt/

There might be others too, not sure :)

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sun Sep 16, 2012 12:47 am
Profile WWW
Expert

Joined: Tue Feb 28, 2012 3:10 pm
Posts: 195
Post Re: Speed of I2C?
I continue to be amazed in one way, and frustrated in another by you hardware guys.

As you know I recently picked up the saleae analyser (which does I2C), and it has created more questions than it answered.
From one sensor device, I can read a byte register at a time, and get perfect numbers. I change that to read a block and get the same first byte over and over. I change that to read a byte at a time in a loop (incrementing the read address), and get the same number, over and over. At that point I just go play civ because none of it makes any sense to me.

On another device, depending on the temperature, or the moon phase (or both) one minute the byte reads work, and the block read don't, the next minute vice versa. more civ.

Add to that total confusion with how and when RobotC is evaluating math and casts (try printf'ing a %ud pointing to a byte), and .... more civ.

curse you hardware guys.

_________________
Mike aka Spiked3
http://www.spiked3.com


Sun Sep 16, 2012 2:57 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3105
Location: Rotterdam, The Netherlands
Post Re: Speed of I2C?
...and a curse upon your house!

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sun Sep 16, 2012 3:13 am
Profile WWW
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: Speed of I2C?
:lol: :lol: :lol: Civilization V: The patented unofficial cure for all ailments! :lol: :lol: :lol:

Curse you software and hardware guys. I'm just good at the building part. I'm at a loss with advanced code, or more than simple circuits.

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Sun Sep 16, 2012 10:45 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 8 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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 post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.