Hi Vasile, Strange that this does not work.
Did you try to isolate the problem to a minimum program without using special - other - procedures so that it can easily be reproduced by anybody that does not have the library you are using? That would make it easier to find the root cause. Thanks. Kind regards, Rob ________________________________ Van: jallib@googlegroups.com <jallib@googlegroups.com> namens vsurducan <vsurdu...@gmail.com> Verzonden: donderdag 11 november 2021 13:47 Aan: jallib@googlegroups.com <jallib@googlegroups.com> Onderwerp: [jallib] adc average 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 jallib+unsubscr...@googlegroups.com<mailto:jallib+unsubscr...@googlegroups.com>. To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/CAM%2Bj4qttXVSgPyqqUetP_HaKEH01xZoSXXmG%2BD73jKOHh2Ub9g%40mail.gmail.com<https://groups.google.com/d/msgid/jallib/CAM%2Bj4qttXVSgPyqqUetP_HaKEH01xZoSXXmG%2BD73jKOHh2Ub9g%40mail.gmail.com?utm_medium=email&utm_source=footer>. -- 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 jallib+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/AM0PR07MB624187B39106F690C4BD3E10E6949%40AM0PR07MB6241.eurprd07.prod.outlook.com.