Data transfer from external SPI RAM to SPI DAC with 33FJ12GP202

Started by Wimax, Sep 05, 2022, 09:04 AM

Previous topic - Next topic

Wimax

Hello everyboy !

I would need some advice on optimizing data transfer from an external ram to an external dac on SPI bus under the control of a 33FJ12GP202 (without DMA unfortunately, operating with an internal clock of 39.68 MHz) with a fairly quiet (around 30/50 KHz), but constant rate.

top204

I've used DMA in some previous codes and it has actually taken longer than using standard interrupts, and is far too complex to set up and monitor (using interrupts), so I dropped using it and have not looked at DMA since. It is one of those "buzz" words, that works fine on units with lots of RAM, or dedicated, processor based, peripherals, but not on standard microcontrollers. It has too many limitations when operating external peripherals. It is great for moving one block of RAM or flash memory to another block of RAM, but with the 16-bit devices, they are fast enough to do all of that without DMA. Also, talking to external peripherals that do not need CS or EN lines manipulated, or commands sent to them are OK, but if they do? Forget DMA! :-)

If you are using the SPI peripherals for the RAM and DAC, and the time taken to read the RAM and send to the DAC are the same, setup an interrupt operating at the speed of the transfer you want and read then write within it.

If it is taking longer to read the RAM and manipulate the data than what is required for the sending speed, implement a double buffer mechanism using two arrays. So while one array is being filled with the RAM's data, the other array is being sent out to the DAC, then swap the array being used with a bit toggle to state which array is being used for transmission when the buffer is finished being sent. Then you will get a very fast and smooth output from the DAC, because it does not have to wait for its data. The important thing to do for a double buffer, is fill the first array buffer first, then set off the interrupt. A bit like a seesaw. And make sure the RAM buffers are large enough to counter-act the timings required. i.e. Large buffers for slow RAM reading, or slow DAC writing. :-)

Wimax

Thank you very much Les ! I'll try to follow your precious advise! The 33FJ12GP202 does not shine in RAM availability so, sooner or later, I will have to think about upgrading to a more powerful micro (perhaps even just the dsPIC33E version), both in terms of operating frequency and RAM and FLASH memory.