Pages: [1] 2   Go Down
Author Topic: Transferring an Integer under 100 us  (Read 1317 times)
0 Members and 1 Guest are viewing this topic.
BC, Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 8
To fail or not to fail
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello All,

I'm working on a project that has two Arduinos: one to drive a stepper motor and another to read a sdCard and figure out how many motor steps are required.  Currently, I have the sd Arduino read the card, convert the file and fill an array with those steps.  The sd card then sends the steps over to the motor controller arduino via I2C and the motor controller runs the array.

I want to make it so I don't require an array anymore.  I want the sd Arduino to feed an integer of motor steps to the motor Arduino during the motor's downtime.  I've calculated the downtime to being no less than ~120 microseconds.

Is there an easy way to do this?
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 112
Posts: 5286
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is there an easy way to do this?

Depends on what's easy for you.

With this description http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1241668644 you can increase the speed of the I2C to 400kHz. This way you should be able to transmit an integer in about 50us.

Although, from your description I don't get the reason to do so. Maybe you describe in a bit more detail to let us comprehend the reason.
Logged

BC, Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 8
To fail or not to fail
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks pylon!  I assumed the I2C bus was already confirmed to run in Fast mode.  It lowers the time from ~330 us to ~130 us which still isn't enough.  I also found that the Adafruit Touch screen shield does not like I2C set to Fast Mode.

The reason I need this done is to allow the motor to run without any interruption.  I want to feed the motor controller arduino commands and values without interrupting the motor at its fastest speed.  I also want to drop using an array so I'm no longer limited by the memory size on the controller.
Logged

USA
Offline Offline
God Member
*****
Karma: 14
Posts: 644
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How big are these values?  Could they fit in a byte (0 to 255) instead?
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 112
Posts: 5286
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You didn't mention that a touch shield is involved. How many integers do you need to transfer? 3?
Logged

BC, Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 8
To fail or not to fail
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The integers can go from -800 to +800.
I expect to send an integer every 100 ms.  The integer is how many steps the motor must take for the next 100 ms period.  I could break up the integer into a LSB and MSB and send only a byte per step (reassembling the bytes into an integer on the third step), but I am hoping there is a comm protocol fast enough to do it in one shot.
Logged

USA
Offline Offline
God Member
*****
Karma: 14
Posts: 644
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The integers can go from -800 to +800.
Then that's a no go on my idea...

I expect to send an integer every 100 ms.  The integer is how many steps the motor must take for the next 100 ms period.  I could break up the integer into a LSB and MSB and send only a byte per step (reassembling the bytes into an integer on the third step), but I am hoping there is a comm protocol fast enough to do it in one shot.
Well there is Serial Peripheral Interface, which can achieve faster communication between individual microcontrollers, and some other devices as well, than I2C.  Unless your implementation somehow precludes using SPI, it could be a better communication option between the Arduinos at least.
Logged

Southampton, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

With the steppers there is certainly SPI, but you are reliant on being able to read the SPI (and the data being present) between issuing steps to the stepper motor... which you have told us is 120us, which ain't a lot. Linking the two cards with an 8 bit bus as farseeker was alluding to is probably more reliable.. if the value is -800 to 800 you can do that with an 11 bit bus... i.e. 11 digital lines on one arduino linked to 11 digital lines on the other... but timing will be an issue I think.

This does demonstrate the inherent problem of stepper motors and microcontrollers... you have to keep telling the motor to keep going around, leaving little time for other tasks. Consider using a DC motor and an encoder with a PID controller algorithm... you'll have plenty of time (easily 5000-1000us) between the PID calculations to do all manner of things, like read the SD card thus eliminating an entire arduino.
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 112
Posts: 5286
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The integers can go from -800 to +800.

This kind of integers does perfectly fit into two bytes. With a 400kHz I2C you need about 50us to transmit 2 bytes. How do you get to 130us?
Logged

USA
Offline Offline
God Member
*****
Karma: 14
Posts: 644
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The integers can go from -800 to +800.

This kind of integers does perfectly fit into two bytes. With a 400kHz I2C you need about 50us to transmit 2 bytes. How do you get to 130us?

Recall that this project has to communicate between two Arduinos, then from the second Arduino to the stepper motors.  With two transimissions of ~50 µs, plus the processing time on the second Arduino, I can see how the total time could exceed 130 µs.

Edit: Typo
« Last Edit: August 20, 2012, 09:59:02 am by Far-seeker » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26632
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For numbers of that magnitude, you only need eleven bits, not sixteen.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

BC, Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 8
To fail or not to fail
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The integers can go from -800 to +800.

This kind of integers does perfectly fit into two bytes. With a 400kHz I2C you need about 50us to transmit 2 bytes. How do you get to 130us?

Recall that this project has to communicate between two Arduinos, then from the second Arduino to the stepper motors.  With two transimissions of ~50 µs, plus the processing time on the second Arduino, I can see how the total time could exceed 130 µs.

Edit: Typo


Correct.  I also need to figure out which integer to send and to break the integer up, send the integer bytes, and then reassemble the integer.

Turns out SPI was the answer.  I'm getting around ~52 us from start to finish.  It's a bit more complicated to set up a Salve, but well worth the effort.

Thanks to everyone for the input.
Logged

USA
Offline Offline
God Member
*****
Karma: 14
Posts: 644
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm glad you found a solution that worked for you! smiley
Logged

Breaking Worse
Offline Offline
Edison Member
*
Karma: 19
Posts: 1109
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Gee, I was going to suggest choose eleven pins and bit bang the heck out of them using the direct port manipulation method.  You should be able to get at least that much speed out of it, maybe more like a few us per port (pair) update.
Logged

I have only come here seeking knowledge. Things they would not teach me of in college.

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 52
Posts: 2396
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why do you need 2 unos?. Can't you just read from the SD card and then output the value?

Mark
Logged

Pages: [1] 2   Go Up
Jump to: