I want to use 24bit ADC (SPI, e.g. AD7730) with Atmel 89S52 for instrumentation purpose. I also want to use 16bit AD7705 ADC with Atmel 89S52. Please suggest best suitable variable routine within 128 bytes of data memory.
What is a "variable routine" and what criteria do you have for "suitable"?
Actually if i use long int to store 24 bit ADC output, AT89s52's data memory overflows. The main reason is ADC AVERAGING routine. So what i can do within AT89S52's RAM limit.
I'm sorry, but you're leaving your readers way too much in the dark about the inner workings of your program.
Storing a 24-bit ADC value in a 4-byte long int consumes 4 bytes of memory, so you must be doing more than just that if your function manages to overflow a 128-byte data memory space.
So re-write it to be more efficient in its memory usage?
As Christoph says, it is impossible to say any more than that without more detail from you!
As i stated earlier, The main reason is averaging. Because too fluctuations for 24bits of resolution. Averaging is Arithmetic mean of 50 samples. I have to store that samples, so it requires memory, Any Idea that i can get stable Low pass Averaging??
Rolling average or not?'
If not, then you don't need to store anything but sum and count.
Rolling is also trivial - 24 bit = 3 byte. Trivial to pick up 3 byte * 2 för each sample received.
Rolling averages over 50 24-bit samples (of random value) requires 50*3 = 150 bytes of RAM.
In short - you can't solve for the general case. You must make assumptions about the variance of the samples (frequency of input signal including noise in relation to sample frequency), i.e. if you can store a delta from previous sample, and how many bits you need for the delta to make sure it never overflows.
With a 16-bit delta, you can manage with 4-byte sum, 2 or 4-byte absolute value and 49*2 bytes of delta. 104 or 106 bytes in total. If your sample frequency is fast enough, you could manage with a 12 or 8-bit delta, but then you must make very sure that you have proper low-pass filtering of the input signal or very bad things will happen with your avaraging code.
there is a way
make it 64 samples to average have one slot "new" two slots "two" two slots "four tho slots "eight" tho slots "sixteen" two slots "thirtytwo" one slot "result" 12 slots make the "two" slots alterantively average two readings in "new", when both are full, make the "four" slots alterantively average two readings in "two", when both are full...
code from the days when SRAM cost money :)
Why on earth do you not get a chip with some decent RAM there are several with 8k and about anythingg inbetween.
Eriik