Hi all ( aka Kiste and Rob&Rob ?) :)

One possible solution to take 8 adc average values is below (and does not
work):

const sample_nr  = 8  ; buffer size dimension
var word voltage1_a[sample_nr] ; sample array
var word one_ch_ad_read
var word voltage1 = 0 ; the average value we need
const word c256 = 256

var byte i
  for 8 using i loop
   one_ch_ad_read (0, 0b10, 0b00, 1) ; read adc procedure
   ch0_adc_value = c256*ADRESH + ADRESL ; compute result
   voltage1_a [i] = ch0_adc_value ; store sample
   voltage1 = voltage1 + voltage1_a[i] ; do a sum of all samples each i step
  end loop

   voltage1 = voltage1 >> 3  ; divide by 8 and get the adc average

The issue is at the line:
voltage1 = voltage1 + voltage1_a[i] ;
initially voltage1 = 0
for i=0  voltage1 = 0 + voltage1_a[0]
for i=1 voltage1 = voltage1 (i=0) + voltage1_a[1] ...etc
this is not working as presumed...

If I remove this line from for...loop...end loop and write as:
voltage1 = voltage1_a [0] + voltage1_a [1] + voltage1_a [2] + voltage1_a [3]
            + voltage1_a [4] + voltage1_a [5] + voltage1_a [6] + voltage1_a
[7]

then everything is ok.

The question is: why it does not work?
thx

-- 
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jallib/CAM%2Bj4qttXVSgPyqqUetP_HaKEH01xZoSXXmG%2BD73jKOHh2Ub9g%40mail.gmail.com.

Reply via email to