Forum Discussion
Altera_Forum
Honored Contributor
13 years ago --- Quote Start --- It looks ok to me. Can you do describe what wrong is? do you have a model to check against or do you do that manually. above all is your adc data correctly entering the filters. here is a model for running average
%(n) stage running average, implementation model
%delay input n stages,
%subtract last stage from current input
%accumulate result and discard LSBs
clear all;
v = 2^16; %vector length
n = 256; %filter stages
data = round(2^10*randn(1,v));
data2 = data - ;
data3 = cumsum();
result = floor(data3/n);
%test it using direct computation of mean of every n samples
data = ;
avg = zeros(1,v);
for i = 1:v
avg(i) = floor(mean(data(i:i+n-1)));
end
figure;hold;
plot(result);
plot(avg,'r--');
figure; plot(result(1:end-1) - avg);
--- Quote End --- Sorry, I was making small mistake in wiring the signals. But now I get the correct values with the above approach. Now the issue comes in the variation. Now I get the values eg. 95mA, 100mA, 105mA,... then all of a sudden it jumps to higher value like 140mA and then all of a sudden it comes to 80mA. I am receiving the values quickly now with the approach I wrote earlier, but the variation is a lot. Is there a way I can decrease the variation?