Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: SPI latency DMA newbie question on: March 08, 2013, 01:17:51 pm
Can you flesh out your requirements please?
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.

2  Using Arduino / Programming Questions / Re: SPI latency DMA newbie question on: March 08, 2013, 11:39:01 am
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????
3  Using Arduino / Programming Questions / SPI latency DMA newbie question on: March 08, 2013, 09:57:50 am
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, 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:
//  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:
    DDRB = b11111111 ;  // set portB output direction

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

if(out_buffer==dma_buffer) halt_master_flag_underrun();
Pages: [1]