Pages: [1] 2   Go Down
Author Topic: SPI latency DMA newbie question  (Read 3438 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am an arduino newbie so know nothing and am hoping begging for some advice will help me get kick started.....

Basically I have not done anything yet as I want to be sure it is possible before starting coding .

I worry I will look stupid as I maybe ask the impossible or should have done some research first, I show below my pseudocode/thoughts/ideas/system description, but will ask my questions first...

1) How can I setup dma on arduino to handle SPI (does arduino even have dma for SPI as slave??) i have seen this http://arduino.cc/forum/index.php?PHPSESSID=3224079b565191d380db0d82da085c82&topic=147858.0, but no mention of dma..

2) How fast can arduino handle dma and interupts and what are speed considerations?, i.e. what is the shortest usleep in the main loop that can guarantee a constant step rate?

3) Is there any example code of similar projects available?

System definition:

Arduino as SPI slave that works as a digital IO interface (basically constant step rate switching gpio pins dependent on SPI data)

1) The arduino must take SPI packets of data (64 bytes I guess) as fast as possible
2) store SPI data in memory
3) constantly step through memory and switching IO pins
4) flag SPI master if it runs out of data
5) (possibly in future add some code for config the arduino via SPI e.g change step rate, number of io pins being switched etc..)

I am guessing what I need to do is

allocate 3 64 byte buffers
setup arduino dma to write SPI data to buffers (double buffering)
create interupt to rotate through the buffer when SPI dma completes
write the data output loop


I am assuming arduino has dma for SPI and it can be setup for 64 byte packets, I have not found any information about SPI dma yet??????

outline pseudo code below :

current_buffer = 0; // pointer indexing where we are for comparison purposes
dma_buffer = 0;  // pointer to where SPI data is buffered by dma
out_buffer = -1;   // pointer to buffer currently being read to output pins

setup_dma();   // function, how do we setup dma to copy 64 bytes from SPI to a memory buffer?????

//     I imagine interupt routine should be similar to below:
interupt_service_routine()
{
//  update circular buffer index
If (current_buffer == 3) current_buffer = 0 ;
else current_buffer = current_buffer + 1 ;

if(current_buffer==out_buffer) halt_spi_master(); // stop if we are going to over write the current output

if(current_buffer==3  & out_buffer==-1 ){ main_loop();  current_buffer=0; } // start the main loop once 3 buffers full
dma_buffer = current_buffer;
}
//       I imagine the output loop should be similar to that below:
out_buffer=0;
main_loop()
{
    DDRB = b11111111 ;  // set portB output direction
 
for(;smiley-wink
{

PORTB= out_buffer[index]
index++;
usleep(step_time);
if(index==64) {
index=0;
If (out_buffer == 3) out_buffer = 0 ;
else out_buffer = out_buffer + 1 ;

if(out_buffer==dma_buffer) halt_master_flag_underrun();
}
}
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 137
Posts: 6792
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Most Arduinos do not have ANY dma.  Due might.
Logged

UK
Offline Offline
Faraday Member
**
Karma: 100
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Not a mention of DMA anywhere in the datasheet.  Another reason I never pick Atmel for my real projects.  Just too under powered and feature scarce for the price.
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Majenko, your anti-AVR tirades/whines are starting to get tedious.
Cut it out, there's a good chap.
Logged

Per Arduino ad Astra

UK
Offline Offline
Faraday Member
**
Karma: 100
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Majenko, your anti-AVR tirades/whines are starting to get tedious.
Cut it out, there's a good chap.
Hey, I'm getting better... I haven't mentioned my preferred alternative smiley-wink
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Majenko, your anti-AVR tirades/whines are starting to get tedious.
Cut it out, there's a good chap.
Hey, I'm getting better... I haven't mentioned my preferred alternative smiley-wink


Okay after being told arduino does not have dma I just spent an hour doing research and find my project is probably impossible because I also have another requirement, chip must be easy hobby solderable DIP package.

What is your prefered alternative???

I checked the MSP430 and the DIP package chips don't have dma either smiley-sad

Could this be done without dma, what is the max possible speed for a SPI transaction on an arduino, how many interupts does it generate etc????
Logged

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

Can you flesh out your requirements please?
Quote
The arduino must take SPI packets of data (64 bytes I guess) as fast as possible
is really a bit woolly.
It may be that DMA is unnecessary, but without solid numbers, it is tough to say.
DMA often implies external devices, wide busses, large memories and high pin counts, so it probably isn't surprising through-hole devices don't feature large in the candidate list.
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.

UK
Offline Offline
Faraday Member
**
Karma: 100
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

At the risk of getting shot down in flames...

Quote from: PIC18F26J11 Datasheet
1024-byte SPI Direct Memory Access (DMA) channel

Available in 28-pin DIP, similar price to the ATMega328P.  I've said enough.  If I mention the fact that it's faster I'll get slapped.
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you flesh out your requirements please?
Quote
The arduino must take SPI packets of data (64 bytes I guess) as fast as possible
is really a bit woolly.
It may be that DMA is unnecessary, but without solid numbers, it is tough to say.
DMA often implies external devices, wide busses, large memories and high pin counts, so it probably isn't surprising through-hole devices don't feature large in the candidate list.

Yes, sorry for the fuzzy requirements, I really just start thinking about it myself this afternoon and not put much thought into it.

Making things a little more solid numbers wise:

I am hoping to get minimum 100kHz switching speeds on the io pins, 16 bits of io or more, for high speed control of stepper motors. I assume that means SPI interupts at 200kHz?

Does that mean we get 100 instructions to handle each byte on a 20Mhz atmega168/328?

The control computer sends out SPI under dma in 64byte packets.

I have been looking around and is seems PIC32MX chips come in SPDIP package and have SPI and DMA available.

I got confused with arduino as I have seen mention of DMA, but now realise its on due and that uses SAM arm chip.

Logged

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

And the Arduino is ported to that processor is it?

Consider yourself shot down in a glorious Hindenburg-like blaze.

Seriously Majenko, why bother?
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.

UK
Offline Offline
Faraday Member
**
Karma: 100
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

*cough*chipkit*cough*
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

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

Quote
*cough*chipkit*cough*
*cough* link to their forum? *cough*
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.

UK
Offline Offline
Faraday Member
**
Karma: 100
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
*cough*chipkit*cough*
*cough* link to their forum? *cough*
But that would be treasonous wouldn't it?
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

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

Quote
But that would be treasonous wouldn't it?
Not if you are helping the OP.
You are helping the OP, aren't you?

Please stop being a prat.
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.

UK
Offline Offline
Faraday Member
**
Karma: 100
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
But that would be treasonous wouldn't it?
Not if you are helping the OP.
You are helping the OP, aren't you?
Why would I ever do anything but?  That is why we're all here, after all.
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Pages: [1] 2   Go Up
Jump to: