cancel
Showing results for 
Search instead for 
Did you mean: 

High speed Sampling and saving on SD card

Javad
Associate III
Posted on November 26, 2015 at 09:49

hello

I need help about my new project. I want to sample from 2Mhz signal with 10Mhz sampling rate about a minutes by a 12bit parallel external ADC (AD9035). since the number of samples will be too many, I need to save them on sd card so that after 1 minutes I use them.  now I want to know how can I write my samples on SD with high speed (more that 20 M Byte/s). using DMA, is good idea?

I am pleased if you help me and suggest any algorithms.

I use STM32f407.

26 REPLIES 26
sanaz
Associate II
Posted on December 14, 2015 at 07:17

hi

I have almost the same problem. I need to read my 12 bit external ADC and logging them in sd card. my sampling rate is 1MS/p. I test my SD on PC. its writing speed is more than 5MB/S.

I found some similar code written by Cvile but I don't know how I have to change them. is it possible to help me for writting its code? i bought stm32f407 board recently.

Posted on December 14, 2015 at 15:03

Snaza, which STM32 board are you using? Does it have a socket for an SD card, and have you tested the write bandwidth on that? You'll need >2MBps

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Problem%20with%20ADC%20DMA%20and%20timer&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=4...

I'm not looking to code your project from scratch, so review the assorted examples posted already and mash together a starting point based on your hardware.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
sanaz
Associate II
Posted on December 15, 2015 at 07:37

Cvile: which STM32 board are you using? Does it have a socket for an SD card

?

I use a simple evaluation STM32f407ez board with 25Mhz external crystal that give me 168Mhz CPU clock (I test it with TIM1). This board does not have SD card socket but I design a board that my external ADC and sd socket is on it (of course with some more circuit that is for driving my sensor). My pin out is as follow:

SD CARD: PC8 (SDIO_D0), PC9(SDIO_D1), PC10(SDIO_D2), PC11(SDIO_D3), PC12(SDIO_CK) and PD2(SDIO_CMD)

ADC: PF0, PF1, PF2, ?., PF11 (for 12 bit parallel ADC output)

PA8 (TIM1_CH1) for ADC Clock: ADC start conversation at rising edge of clock and I have to read out put (PF0-PF11) at falling edge and write on SD.

Cvile: have you tested the write bandwidth on that?

I don?t know how can I test the write bandwidth on board. I just test it on PC. In addition I think I can write it faster than PC because I don?t want use FAT format. I think if I write it without any special format it can help my writing speed.

Cvile: I'm not looking to code your project from scratch, so review the assorted examples posted already and mash together a starting point based on your hardware.

I found some code in forums that most of them are written by you Cvile and I try to use them. I have 2Mhz pulse on PA8 now, I connect it ADC clock pin. But I don?t know how I can configure DMA that read PF0-PF11 on falling edge of clock and write it on SD by SDIO. In addition do I have to

use two DMA(one for read from pin and other for SDIO)? Maybe if I buffer data and write a block on SD, was better, but how can I do it?!!

I attach my code and hardware photo to see them.

I AM REALLY SORRY FOR CODE, I NOW THAT?S AMAZING BUT I JUST COLLECT SOME CONFIGURATION. OF COURSE ITS TIMER WORK, I TEST IT MYSELF

;)

0690X00000603LkQAI.jpg

sanaz
Associate II
Posted on December 15, 2015 at 07:43

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6pK&d=%2Fa%2F0X0000000bwI%2Fj5JQFdAcvpLUEUPwB1CgFOXcxzyFHFpnhEMWP93hwG8&asPdf=false
Javad
Associate III
Posted on December 17, 2015 at 06:58

sanaz, unfortunately the ST documents about its STM32f4 is too poor. I want to implant the same algorithm but I couldn't because I did not have any good reference! 

using FGPA has its problems too. in addition the FPGA price is too high!

I am pleased if any body help to implant this algorithms that explain in above posts.

Posted on December 17, 2015 at 16:06

You'd want to time the writing of a large file, against an internal timer, like using a stopwatch. I'd recommend timing the write of 1000x 32KB blocks, and calculate the MBps from that operation. Smaller blocks sizes, and unaligned writes, will be slower.

Generating pulses and DMA actions against memory is a matter of picking timer(s) that use the pins you want, and the appropriate channels, and edge placement. The DMA table in the reference manual breaks down the available trigger sources, and I think I've also posted examples where an external edge can trigger the DMA. Yes you'll want to use DMA for the SDIO operations.

Not sure I'd skip the FatFs, it makes the card a lot easier to manage. Things need to use blocks which are aligned to the media in use, ie sectors, clusters, erase blocks, etc. Most problem occur when you make the system do a lot of unnecessary small/unaligned operations. I suggest you do the 1000x 32KB test at a file system, and block write level, and determine if FatFs really act as an impediment.

Depending on your buffer depth, you could perhaps look at using an STM32F4 with SDRAM support. Consider also the use of the DCMI for high speed parallel clocked data input.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Javad
Associate III
Posted on December 18, 2015 at 09:09

complete user manual of STM32f4xx UC:

http://www.st.com/web/en/resource/technical/document/reference_manual/DM00031020.pdf

Javad
Associate III
Posted on December 20, 2015 at 16:12

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6mw&d=%2Fa%2F0X0000000bvT%2FRl2M3IK5Mnfngd_7Zo.bmcJbm83LFrmglkKeW8.bG8Q&asPdf=false
Posted on December 20, 2015 at 16:54

is there any way I increase the writing speed?

Increase the clock off the Q tap of the PLL.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Javad
Associate III
Posted on December 20, 2015 at 17:34