Digest Number 2127
Archiver
Posts: 46,084
Message: 10
Date: Fri, 28 Nov 2003 05:23:58 +0800
From: "Chris Anderson" <fuel@b...>
Subject: Averaging numbers...
Hello Stampers,
Is there an easy way to average large word numbers?.
For example, I wish to
average 62319 and 62323, which averages at 62321. I
cant add them together
obviously.
Is there a way to "and" them together or something ?
I would like to average a list of 10 words this way.
Cheers,
Chris Anderson
Sunny Western Australia
*******************************************************
******************
One way to average is to split your number into high
and low byte and add them into a word
varaible, take those two word variables and divide by
the number of samples back to the byte size.
and assemble the new average.
number_x ' value being read, word size 1-4095 12 bit
L_num var number_x.highbyte
H_num var number_x.lowbyte
L_num_avg var word
H_num_avg var word
L_num_avg = 0
H_num_avg = 0
'********************************
for N = 1 to 16 ' for 16 samples
get ADC value
number_x = ADC_value_read
L_num_avg = L_num_avg + L_num
H_num_avg = H_num_avg + H_num
next
L_num = L_num_avg >> 4 ' shift the sum right to
divide by 16
H_num = H_num_avg >> 4 'shift the sum right to divide
by 16
New_Avg = number_x ' number x is the sum of high
and low bytes
Sincerely,
Ron A.
Date: Fri, 28 Nov 2003 05:23:58 +0800
From: "Chris Anderson" <fuel@b...>
Subject: Averaging numbers...
Hello Stampers,
Is there an easy way to average large word numbers?.
For example, I wish to
average 62319 and 62323, which averages at 62321. I
cant add them together
obviously.
Is there a way to "and" them together or something ?
I would like to average a list of 10 words this way.
Cheers,
Chris Anderson
Sunny Western Australia
*******************************************************
******************
One way to average is to split your number into high
and low byte and add them into a word
varaible, take those two word variables and divide by
the number of samples back to the byte size.
and assemble the new average.
number_x ' value being read, word size 1-4095 12 bit
L_num var number_x.highbyte
H_num var number_x.lowbyte
L_num_avg var word
H_num_avg var word
L_num_avg = 0
H_num_avg = 0
'********************************
for N = 1 to 16 ' for 16 samples
get ADC value
number_x = ADC_value_read
L_num_avg = L_num_avg + L_num
H_num_avg = H_num_avg + H_num
next
L_num = L_num_avg >> 4 ' shift the sum right to
divide by 16
H_num = H_num_avg >> 4 'shift the sum right to divide
by 16
New_Avg = number_x ' number x is the sum of high
and low bytes
Sincerely,
Ron A.