I am working on Ultrasonic sensors, but I can't figure out how my microcontroller will be able to capture and store the signal values in an array even if I provide a sampling rate of 44 KHz.
I didn't get what you want to store ? If you want to detect presence of ultrasound with particular strength use ultrasound sensor than interface it with ATMEGA 128 (use internal ADC).
First buffered, the altrasound signal, sensor's out put, use internal ADC of ATMEGA 128, plot the stored values of samples taken by ADC on paper, as you know the frequency of signal(using C.R.O), hence the sampling rate of the ADC, would be available to you. Using samples, of half/full window width observed, you can do analysis using Forier, Walse , Hartley etc. transforms and find the suitable method to analysis of signal, for accurate measurement.
First look at the question - it has two aspects - 1) sampling a 22kHz signal with atleast 44kHz sampling rate using mega128 and then 2) Storing the sampled values.
I believe, provided a single channel used, ATMega128 @ 16MIPS should be able to achieve the desired rate or even higher.
As far as the storage is considered, the device has 4k SRAM, so depending upon how the software is written, one can use atleast 3.5k of SRAM for storing the sample values. But at 44ksps (or kHz) rate, it will require large amount (>4k) of RAM space.
Instead, uploading the samples over the serial port and then storing the values on PC would be an alternative. But off-course the serial transfer rate would have hindering effect on your sampling rate. It will always be a trade-off between the sampling rate and the upload rate with the later governing or having major limitation on the sampling rate.
as I see from the datasheet of Atmels ATMEGA128 this device can handle up to 8 input channels for A/D-conversion. The maximum conversion time (13µs...260µs) also depends on the desired resolution. Assuming you need only one channel for airborne sound up to 22kHz (Nyquist) the desired conversion speed of 44kHz (8Bits?) fills the internal SRAM of 4K within 93ms. In pulse-echo mode and air as the medium this belongs to a measured distance of appx. 15meters.
But because of program data and registers you can`t take advantage of the whole 4K.
2K or 3K might be the residual buffer for your ultrasonic samples.
If you need more points to save you have to use the external SRAM with the max. capability of 64K (and 8 bits wide).
For further signal processing e.g. on a PC you can transfer these data either with the USART or serial interface (SPI) after collecting in internal or external SRAM.
Does this answer your question?
Best regards,
Marc.
@Prasanna: 16MIPS belongs to the highest speed grade of 16MHz oscillator frequency and one cycle instruction time. The ADC stage uses a prescaler to get a maximum of 200kHz (ADC clock) for 10Bit resolution and 1MHz ADC clock for 8Bit resolution.
What I meant by 16MIPS is that the total timing for the activities that involve ADC sampling and acquisition time, storage in the RAM and then uploading the data stream on the serial port (USART or SPI). This eventually requires the CPU to have faster speed. So in my opinion, 16MIPS was just adequate.
But as you have stated in your answer, a time about 100ms corresponding to a distance about 15meters will certainly put restrictions as what processing we can carry out by ATmega.
For a clean system operation, I would recommend only to acquire the data and send it at a faster rate to the HOST so that the processing can be done there and not @ MEGA.
I do not want to go in detail, however, I still anticipate timing errors or limitations (even at 16MIPS CPU Speed) while handling 44kHz sampling rate by ATMEGA in this project or research work! There will be little or no room for processing the data.
Let's hear from Nidhi as what are her requirements so that I shall be more than happy to discuss it with you further.
of course 16MIPS are not very fast to process data in time. But offline data processing would be o.k. One good solution would be in fact just to sample data and transfer them e.g. over USB connection to a PC. For USB connectivity the ATmega128 doesn`t fit that purpose. E.g. ATMEL AT90USB.../ ATxmega... or Microchip (32MX...) could be the choice.
Further signal processing can be done with different tools (MatLab, LabView...).
I do agree with you. That is why I suggested, in my earlier answers that we should only ACQUIRE the data through ATMEGA and then send it to PC for processing.
And then when the question of faster serial transfer arises, USB would be the best but this invites migrating the platform from ATMEGA to AT90USB devices.
as you can see from page 230 and 235 ( http://www.atmel.com/Images/doc2467.pdf and http://www.atmel.com/Images/doc8161.pdf ) the maximum ADC clock for ATMEGA128/328 is 1MHz at 8 Bit resolution. The ADC stage needs 13 steps (cycles) for conversion, so maximum sampling rate is 1MHz/13 = 76,92kHz. For one channel. Otherwise you might have to distribute the max. ADC frequency to the desired amount of input channels. Must be confirmed reading the appropriate section...
You can not simply interface an ultrasonic sensor (with frequency output) to a microcontroller and get the output. You need an interface circuit in between. An easy approach is to first use a suitable linear Frequency-to-Voltage (F-to-V) converter to convert the frequency signal into a voltage signal. This means that any changes in the frequency of your input signal would be transformed to changes in voltage level. A number of F-to-V ICs are available commercially, you can Google and find which one is is suitable for your desired frequency range.
In the next step, you can feed this voltage signal to the ADC input of the microcontroller. ATMega128 can sample upto 76.9Ksps, so you can safely sample a maximum frequency of 38KHz. You may face storage issues at this rate.
Alternatively, select an ultrasonic sensor that provides a voltage output. Then you don't need an F-to-V interface circuit.
Dear Friend Nasir, when we have a frequency output why do we need additional F-to-V converter to get the analog voltage reading to be measured by an ADC? We can do direct frequency measurements through the timer ports so use of F-to-V is not a viable solution here.
Secondly look exactly what is needed - Sampling a signal with ATLEAST 44ksps rate through an 8-bit micro.
As I have stated earlier, timing issues will dominate or make this device a difficult choice to choose.
There is another issue that needs to be cleared by the author - whether it is 1) a continuous CW signal or 2) a burst or 3) a band of signal in the ultrasonic range, that needs to be CONTINUOUSLY sampled for data processing.
I would suggest to go for a high speed MIXED SIGNAL CONTROLLER such as dsPIC or similar where the ADC itself has a basic sampling rate in excess of 500ksps. And eventually, the device is clocked faster at 20MIPS or higher, with high speed SPI or even USB, it would give more room to breath than suffocating with the 8-bit micro. Then some basic data processing can also be carried out at the device itself and then fine processing can be done at HOST PC side.
Alternately, there is another way to do is to use a USB Oscilloscope type hardware that can also store the data in a file (but look for text or Excel format data format!).
And Nidhi, all this discussion assumes that you have the Ultrasonic transducer that has some signal conditioning such as amplification and filtering before the signal is fed to the ADC or data acquisition.
I think, that the author Nidhi has to clearify the purpose of the ultrasonic transducer.
Otherwise we could - in fact - have a nice discussion about different point of views but not achieving her objects.
Of course, if strong signal processing (e.g. FFT) has to be done either a DSP or a dsPIC can handle that task. Simple echo detection can be done with a simple processor and envelope processing.
So - Prasanna - you are right to turn the attention to the authors aim. Just sampling and storing ultrasonic values with a PC for further signal processing can be done with any data acquisition card. Building a transmitter and receiver stage was not the question of Nidhi.
The sampling at just the Nyquist rate does not always solve the problem. The solution depends on the critical analysis requirement of the acquired waveform. If you need to analyse at the phase level then you need very high sampling rate. One solution could be to acquire with known delay of small amount. This is possible if you have a repetative signal. If you have continuous wave and can not repeat then this may not work. But again the storage problem will still exist if you need higher record length.
If you are working in pulse echo mode this may solve your problem.
Thanks for your most valued suggestions. I did follow this table for sometime. But being a novice, it took me a lot of time to achieve clarity and implement them.
I chose ATmega128 (with built-in ADC), Ultrasonic Sensor HC-SR04. The system worked in pulse mode. I would send a short signal, capture the reflected signal. few such samples were collected and analyzed. It was just a simple prototype, so I didn't push much on memory limits.