Hi,
I have chosen
- Transcend 4GB micro SHDC card.
- PIC32F795F512L, 80MHz processor with 128K RAM. ( I do not know yet that this micro will be suitable for my application)
My PIC will be getting 16 bit of samples at 256 Hz from an ADC from 30 different channels which the microprocessor has to write into the SDHC card. The ADC will continuously sample the data. The same microprocessor will also be transmitting the same data via Bluetooth
2.1 to a PC. I figured that for one ADC channel (256 x 16 x 1 second =
4096 or 4K) 4Kbits of memory is required (So, for 32 channels 32 x 4k = 120K) Is this calculation correct? . I know that SDHC cards have their delays and communication problems etc which make them a little slower.
The problem is that I have to write the continuous coming ADC data into the RAM and from there continuously writing it to the microSD Card until it gets full . So, the problems are as follows
- I write the specified amount of data to the SD Card. SD Card let the microprocessor write the data but takes some delay to do it and then also keeps the microprocessor waits for the acknowledge signal for some times. The delay is unknown or big enough that my RAM gets full with the continuously coming ADC data and micro started losing the real data and overwriting or generates an error message or something. Plus if a user on the PC side also generates some command to the microprocessor to do something else via Bluetooth. I forgot to tell the microprocessor is also sending the same data to the PC via Bluetooth 2.1 too.
So, far I came up with the idea to keep the RAM as big as possible. I know that my C code will also reside there and the data will also reside there. I might have to divide the RAM in three sections, C- code, Bluetooth and SDHC Card. I guess the my questions are as follows
- If bigger RAM is the solution, than how big. How can I calculate the size that I need.
- How can I make the Bluetooth and SDHC card data rate, delays, microprocessor clock and other important parameters( which I do not know yet) be the part of my calculations?
Any idea, suggestion or advice is welcome. ========================================================
resolution*rate*channels is the minimum sustained data rate you must have. For your case this is 16*256*30 ~= 125khz. No matter what code, devices, or transfer methods this is the minimum.
Since there is overhead in transferring the data you must calculate the cycles required to transfer one bit from one channel and then multiply that by the above number. viz., the above number assumes that it takes exactly 1 cycle to transfer the data.
I believe it will take at least 10 cycles(approximately) to transfer a bit which means you'll it will require ~ 1Mhz cpu. I would imagine an 80Mhz processor would be fine and give you a bit of headroom to work with(depending on the adc protocol it might not be enough but it's always easy to parallel to give the throughput you need).
As far as memory goes, you have to store those bits somewhere. In your example it is ~125kbits per second which you calculated correctly.
This is the minimum amount of ram you need. Anything over this may not be helpful depending on your method.
Because it will take around 1M cycles to receive the adc data it will also take about 1M cycles to transmit(really depends on protocols and such but I'm estimating).
The problem is you cannot receive 1 second of data then transmit 1 second because that will introduce a delay of 1s into the receiving end. You must interleave the transmitting and receiving so that there are no samples dropped(and you must decide how bad of an problem that might cause).
Alternatively you could have a dedicated receiving circuit and dedicated transmitting circuit. This may be a problem if the memory cannot be simultaneously read and written. (you can get two port memory for this)
If a delay is ok for the transmission(e.g., it doesn't have to be real time) you can double your memory and have the receiving end write to one memory bank while the transmission is reading from the other. This solves the problem but introduces a delay of how ever long it takes to fill up a memory bank(125kbits would take 1 second but you could subdivide and simply swap bank quicker but up to a limit).
There are many factors involved and one of the biggest is the cost. What you want to do is not a terribly difficult task... it depends on how well you want to do it...
Your pic should easily be able to handle the transmitting and receiving but if there are any stalls or errors in the stream then you might have some big issues. You could, for example, use ERC's to fix this or resend the data but it costs cycles to compute.
What you have to realize is that you must have a fast enough system so that the you can send the bits faster than you can receiving them. If you don't you just end up piling up bits or having to drop them to keep up. If dropping bits or errors in the stream are bad(fatal without recovery) then you have some real work ahead). If it's not a critical application(no one is going to die or lose money on it) then it should be a relatively easy task).